[ALSA] hda-codec - Add ALC861VD/ALC660VD support
[safe/jmp/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_UNIWILL_DIG,
56         ALC880_UNIWILL,
57         ALC880_UNIWILL_P53,
58         ALC880_CLEVO,
59         ALC880_TCL_S700,
60         ALC880_LG,
61         ALC880_LG_LW,
62 #ifdef CONFIG_SND_DEBUG
63         ALC880_TEST,
64 #endif
65         ALC880_AUTO,
66         ALC880_MODEL_LAST /* last tag */
67 };
68
69 /* ALC260 models */
70 enum {
71         ALC260_BASIC,
72         ALC260_HP,
73         ALC260_HP_3013,
74         ALC260_FUJITSU_S702X,
75         ALC260_ACER,
76 #ifdef CONFIG_SND_DEBUG
77         ALC260_TEST,
78 #endif
79         ALC260_AUTO,
80         ALC260_MODEL_LAST /* last tag */
81 };
82
83 /* ALC262 models */
84 enum {
85         ALC262_BASIC,
86         ALC262_HIPPO,
87         ALC262_HIPPO_1,
88         ALC262_FUJITSU,
89         ALC262_HP_BPC,
90         ALC262_HP_BPC_D7000_WL,
91         ALC262_HP_BPC_D7000_WF,
92         ALC262_BENQ_ED8,
93         ALC262_AUTO,
94         ALC262_MODEL_LAST /* last tag */
95 };
96
97 /* ALC861 models */
98 enum {
99         ALC861_3ST,
100         ALC660_3ST,
101         ALC861_3ST_DIG,
102         ALC861_6ST_DIG,
103         ALC861_UNIWILL_M31,
104         ALC861_TOSHIBA,
105         ALC861_ASUS,
106         ALC861_ASUS_LAPTOP,
107         ALC861_AUTO,
108         ALC861_MODEL_LAST,
109 };
110
111 /* ALC861-VD models */
112 enum {
113         ALC660VD_3ST,
114         ALC861VD_3ST,
115         ALC861VD_3ST_DIG,
116         ALC861VD_6ST_DIG,
117         ALC861VD_AUTO,
118         ALC861VD_MODEL_LAST,
119 };
120
121 /* ALC882 models */
122 enum {
123         ALC882_3ST_DIG,
124         ALC882_6ST_DIG,
125         ALC882_ARIMA,
126         ALC882_AUTO,
127         ALC885_MACPRO,
128         ALC882_MODEL_LAST,
129 };
130
131 /* ALC883 models */
132 enum {
133         ALC883_3ST_2ch_DIG,
134         ALC883_3ST_6ch_DIG,
135         ALC883_3ST_6ch,
136         ALC883_6ST_DIG,
137         ALC883_TARGA_DIG,
138         ALC883_TARGA_2ch_DIG,
139         ALC888_DEMO_BOARD,
140         ALC883_ACER,
141         ALC883_MEDION,
142         ALC883_LAPTOP_EAPD,
143         ALC883_AUTO,
144         ALC883_MODEL_LAST,
145 };
146
147 /* for GPIO Poll */
148 #define GPIO_MASK       0x03
149
150 struct alc_spec {
151         /* codec parameterization */
152         struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
153         unsigned int num_mixers;
154
155         const struct hda_verb *init_verbs[5];   /* initialization verbs
156                                                  * don't forget NULL
157                                                  * termination!
158                                                  */
159         unsigned int num_init_verbs;
160
161         char *stream_name_analog;       /* analog PCM stream */
162         struct hda_pcm_stream *stream_analog_playback;
163         struct hda_pcm_stream *stream_analog_capture;
164
165         char *stream_name_digital;      /* digital PCM stream */ 
166         struct hda_pcm_stream *stream_digital_playback;
167         struct hda_pcm_stream *stream_digital_capture;
168
169         /* playback */
170         struct hda_multi_out multiout;  /* playback set-up
171                                          * max_channels, dacs must be set
172                                          * dig_out_nid and hp_nid are optional
173                                          */
174
175         /* capture */
176         unsigned int num_adc_nids;
177         hda_nid_t *adc_nids;
178         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
179
180         /* capture source */
181         unsigned int num_mux_defs;
182         const struct hda_input_mux *input_mux;
183         unsigned int cur_mux[3];
184
185         /* channel model */
186         const struct hda_channel_mode *channel_mode;
187         int num_channel_mode;
188         int need_dac_fix;
189
190         /* PCM information */
191         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
192
193         /* dynamic controls, init_verbs and input_mux */
194         struct auto_pin_cfg autocfg;
195         unsigned int num_kctl_alloc, num_kctl_used;
196         struct snd_kcontrol_new *kctl_alloc;
197         struct hda_input_mux private_imux;
198         hda_nid_t private_dac_nids[5];
199
200         /* hooks */
201         void (*init_hook)(struct hda_codec *codec);
202         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
203
204         /* for pin sensing */
205         unsigned int sense_updated: 1;
206         unsigned int jack_present: 1;
207 };
208
209 /*
210  * configuration template - to be copied to the spec instance
211  */
212 struct alc_config_preset {
213         struct snd_kcontrol_new *mixers[5]; /* should be identical size
214                                              * with spec
215                                              */
216         const struct hda_verb *init_verbs[5];
217         unsigned int num_dacs;
218         hda_nid_t *dac_nids;
219         hda_nid_t dig_out_nid;          /* optional */
220         hda_nid_t hp_nid;               /* optional */
221         unsigned int num_adc_nids;
222         hda_nid_t *adc_nids;
223         hda_nid_t dig_in_nid;
224         unsigned int num_channel_mode;
225         const struct hda_channel_mode *channel_mode;
226         int need_dac_fix;
227         unsigned int num_mux_defs;
228         const struct hda_input_mux *input_mux;
229         void (*unsol_event)(struct hda_codec *, unsigned int);
230         void (*init_hook)(struct hda_codec *);
231 };
232
233
234 /*
235  * input MUX handling
236  */
237 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
238                              struct snd_ctl_elem_info *uinfo)
239 {
240         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
241         struct alc_spec *spec = codec->spec;
242         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
243         if (mux_idx >= spec->num_mux_defs)
244                 mux_idx = 0;
245         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
246 }
247
248 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
249                             struct snd_ctl_elem_value *ucontrol)
250 {
251         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
252         struct alc_spec *spec = codec->spec;
253         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
254
255         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
256         return 0;
257 }
258
259 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
260                             struct snd_ctl_elem_value *ucontrol)
261 {
262         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
263         struct alc_spec *spec = codec->spec;
264         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
265         unsigned int mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
266         return snd_hda_input_mux_put(codec, &spec->input_mux[mux_idx], ucontrol,
267                                      spec->adc_nids[adc_idx],
268                                      &spec->cur_mux[adc_idx]);
269 }
270
271
272 /*
273  * channel mode setting
274  */
275 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
276                             struct snd_ctl_elem_info *uinfo)
277 {
278         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
279         struct alc_spec *spec = codec->spec;
280         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
281                                     spec->num_channel_mode);
282 }
283
284 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
285                            struct snd_ctl_elem_value *ucontrol)
286 {
287         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
288         struct alc_spec *spec = codec->spec;
289         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
290                                    spec->num_channel_mode,
291                                    spec->multiout.max_channels);
292 }
293
294 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
295                            struct snd_ctl_elem_value *ucontrol)
296 {
297         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
298         struct alc_spec *spec = codec->spec;
299         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
300                                       spec->num_channel_mode,
301                                       &spec->multiout.max_channels);
302         if (err >= 0 && spec->need_dac_fix)
303                 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
304         return err;
305 }
306
307 /*
308  * Control the mode of pin widget settings via the mixer.  "pc" is used
309  * instead of "%" to avoid consequences of accidently treating the % as 
310  * being part of a format specifier.  Maximum allowed length of a value is
311  * 63 characters plus NULL terminator.
312  *
313  * Note: some retasking pin complexes seem to ignore requests for input
314  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
315  * are requested.  Therefore order this list so that this behaviour will not
316  * cause problems when mixer clients move through the enum sequentially.
317  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
318  * March 2006.
319  */
320 static char *alc_pin_mode_names[] = {
321         "Mic 50pc bias", "Mic 80pc bias",
322         "Line in", "Line out", "Headphone out",
323 };
324 static unsigned char alc_pin_mode_values[] = {
325         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
326 };
327 /* The control can present all 5 options, or it can limit the options based
328  * in the pin being assumed to be exclusively an input or an output pin.  In
329  * addition, "input" pins may or may not process the mic bias option
330  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
331  * accept requests for bias as of chip versions up to March 2006) and/or
332  * wiring in the computer.
333  */
334 #define ALC_PIN_DIR_IN              0x00
335 #define ALC_PIN_DIR_OUT             0x01
336 #define ALC_PIN_DIR_INOUT           0x02
337 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
338 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
339
340 /* Info about the pin modes supported by the different pin direction modes. 
341  * For each direction the minimum and maximum values are given.
342  */
343 static signed char alc_pin_mode_dir_info[5][2] = {
344         { 0, 2 },    /* ALC_PIN_DIR_IN */
345         { 3, 4 },    /* ALC_PIN_DIR_OUT */
346         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
347         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
348         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
349 };
350 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
351 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
352 #define alc_pin_mode_n_items(_dir) \
353         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
354
355 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
356                              struct snd_ctl_elem_info *uinfo)
357 {
358         unsigned int item_num = uinfo->value.enumerated.item;
359         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
360
361         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
362         uinfo->count = 1;
363         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
364
365         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
366                 item_num = alc_pin_mode_min(dir);
367         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
368         return 0;
369 }
370
371 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
372                             struct snd_ctl_elem_value *ucontrol)
373 {
374         unsigned int i;
375         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
376         hda_nid_t nid = kcontrol->private_value & 0xffff;
377         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
378         long *valp = ucontrol->value.integer.value;
379         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
380                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
381                                                  0x00);
382
383         /* Find enumerated value for current pinctl setting */
384         i = alc_pin_mode_min(dir);
385         while (alc_pin_mode_values[i] != pinctl && i <= alc_pin_mode_max(dir))
386                 i++;
387         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
388         return 0;
389 }
390
391 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
392                             struct snd_ctl_elem_value *ucontrol)
393 {
394         signed int change;
395         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
396         hda_nid_t nid = kcontrol->private_value & 0xffff;
397         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
398         long val = *ucontrol->value.integer.value;
399         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
400                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
401                                                  0x00);
402
403         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir)) 
404                 val = alc_pin_mode_min(dir);
405
406         change = pinctl != alc_pin_mode_values[val];
407         if (change) {
408                 /* Set pin mode to that requested */
409                 snd_hda_codec_write(codec,nid,0,AC_VERB_SET_PIN_WIDGET_CONTROL,
410                                     alc_pin_mode_values[val]);
411
412                 /* Also enable the retasking pin's input/output as required 
413                  * for the requested pin mode.  Enum values of 2 or less are
414                  * input modes.
415                  *
416                  * Dynamically switching the input/output buffers probably
417                  * reduces noise slightly (particularly on input) so we'll
418                  * do it.  However, having both input and output buffers
419                  * enabled simultaneously doesn't seem to be problematic if
420                  * this turns out to be necessary in the future.
421                  */
422                 if (val <= 2) {
423                         snd_hda_codec_write(codec, nid, 0,
424                                             AC_VERB_SET_AMP_GAIN_MUTE,
425                                             AMP_OUT_MUTE);
426                         snd_hda_codec_write(codec, nid, 0,
427                                             AC_VERB_SET_AMP_GAIN_MUTE,
428                                             AMP_IN_UNMUTE(0));
429                 } else {
430                         snd_hda_codec_write(codec, nid, 0,
431                                             AC_VERB_SET_AMP_GAIN_MUTE,
432                                             AMP_IN_MUTE(0));
433                         snd_hda_codec_write(codec, nid, 0,
434                                             AC_VERB_SET_AMP_GAIN_MUTE,
435                                             AMP_OUT_UNMUTE);
436                 }
437         }
438         return change;
439 }
440
441 #define ALC_PIN_MODE(xname, nid, dir) \
442         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
443           .info = alc_pin_mode_info, \
444           .get = alc_pin_mode_get, \
445           .put = alc_pin_mode_put, \
446           .private_value = nid | (dir<<16) }
447
448 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
449  * together using a mask with more than one bit set.  This control is
450  * currently used only by the ALC260 test model.  At this stage they are not
451  * needed for any "production" models.
452  */
453 #ifdef CONFIG_SND_DEBUG
454 static int alc_gpio_data_info(struct snd_kcontrol *kcontrol,
455                               struct snd_ctl_elem_info *uinfo)
456 {
457         uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
458         uinfo->count = 1;
459         uinfo->value.integer.min = 0;
460         uinfo->value.integer.max = 1;
461         return 0;
462 }                                
463 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
464                              struct snd_ctl_elem_value *ucontrol)
465 {
466         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
467         hda_nid_t nid = kcontrol->private_value & 0xffff;
468         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
469         long *valp = ucontrol->value.integer.value;
470         unsigned int val = snd_hda_codec_read(codec, nid, 0,
471                                               AC_VERB_GET_GPIO_DATA, 0x00);
472
473         *valp = (val & mask) != 0;
474         return 0;
475 }
476 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
477                              struct snd_ctl_elem_value *ucontrol)
478 {
479         signed int change;
480         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
481         hda_nid_t nid = kcontrol->private_value & 0xffff;
482         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
483         long val = *ucontrol->value.integer.value;
484         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
485                                                     AC_VERB_GET_GPIO_DATA,
486                                                     0x00);
487
488         /* Set/unset the masked GPIO bit(s) as needed */
489         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
490         if (val == 0)
491                 gpio_data &= ~mask;
492         else
493                 gpio_data |= mask;
494         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_GPIO_DATA, gpio_data);
495
496         return change;
497 }
498 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
499         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
500           .info = alc_gpio_data_info, \
501           .get = alc_gpio_data_get, \
502           .put = alc_gpio_data_put, \
503           .private_value = nid | (mask<<16) }
504 #endif   /* CONFIG_SND_DEBUG */
505
506 /* A switch control to allow the enabling of the digital IO pins on the
507  * ALC260.  This is incredibly simplistic; the intention of this control is
508  * to provide something in the test model allowing digital outputs to be
509  * identified if present.  If models are found which can utilise these
510  * outputs a more complete mixer control can be devised for those models if
511  * necessary.
512  */
513 #ifdef CONFIG_SND_DEBUG
514 static int alc_spdif_ctrl_info(struct snd_kcontrol *kcontrol,
515                                struct snd_ctl_elem_info *uinfo)
516 {
517         uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
518         uinfo->count = 1;
519         uinfo->value.integer.min = 0;
520         uinfo->value.integer.max = 1;
521         return 0;
522 }                                
523 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
524                               struct snd_ctl_elem_value *ucontrol)
525 {
526         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
527         hda_nid_t nid = kcontrol->private_value & 0xffff;
528         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
529         long *valp = ucontrol->value.integer.value;
530         unsigned int val = snd_hda_codec_read(codec, nid, 0,
531                                               AC_VERB_GET_DIGI_CONVERT, 0x00);
532
533         *valp = (val & mask) != 0;
534         return 0;
535 }
536 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
537                               struct snd_ctl_elem_value *ucontrol)
538 {
539         signed int change;
540         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
541         hda_nid_t nid = kcontrol->private_value & 0xffff;
542         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
543         long val = *ucontrol->value.integer.value;
544         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
545                                                     AC_VERB_GET_DIGI_CONVERT,
546                                                     0x00);
547
548         /* Set/unset the masked control bit(s) as needed */
549         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
550         if (val==0)
551                 ctrl_data &= ~mask;
552         else
553                 ctrl_data |= mask;
554         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
555                             ctrl_data);
556
557         return change;
558 }
559 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
560         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
561           .info = alc_spdif_ctrl_info, \
562           .get = alc_spdif_ctrl_get, \
563           .put = alc_spdif_ctrl_put, \
564           .private_value = nid | (mask<<16) }
565 #endif   /* CONFIG_SND_DEBUG */
566
567 /*
568  * set up from the preset table
569  */
570 static void setup_preset(struct alc_spec *spec,
571                          const struct alc_config_preset *preset)
572 {
573         int i;
574
575         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
576                 spec->mixers[spec->num_mixers++] = preset->mixers[i];
577         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
578              i++)
579                 spec->init_verbs[spec->num_init_verbs++] =
580                         preset->init_verbs[i];
581         
582         spec->channel_mode = preset->channel_mode;
583         spec->num_channel_mode = preset->num_channel_mode;
584         spec->need_dac_fix = preset->need_dac_fix;
585
586         spec->multiout.max_channels = spec->channel_mode[0].channels;
587
588         spec->multiout.num_dacs = preset->num_dacs;
589         spec->multiout.dac_nids = preset->dac_nids;
590         spec->multiout.dig_out_nid = preset->dig_out_nid;
591         spec->multiout.hp_nid = preset->hp_nid;
592         
593         spec->num_mux_defs = preset->num_mux_defs;
594         if (! spec->num_mux_defs)
595                 spec->num_mux_defs = 1;
596         spec->input_mux = preset->input_mux;
597
598         spec->num_adc_nids = preset->num_adc_nids;
599         spec->adc_nids = preset->adc_nids;
600         spec->dig_in_nid = preset->dig_in_nid;
601
602         spec->unsol_event = preset->unsol_event;
603         spec->init_hook = preset->init_hook;
604 }
605
606 /*
607  * ALC880 3-stack model
608  *
609  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
610  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
611  *                 F-Mic = 0x1b, HP = 0x19
612  */
613
614 static hda_nid_t alc880_dac_nids[4] = {
615         /* front, rear, clfe, rear_surr */
616         0x02, 0x05, 0x04, 0x03
617 };
618
619 static hda_nid_t alc880_adc_nids[3] = {
620         /* ADC0-2 */
621         0x07, 0x08, 0x09,
622 };
623
624 /* The datasheet says the node 0x07 is connected from inputs,
625  * but it shows zero connection in the real implementation on some devices.
626  * Note: this is a 915GAV bug, fixed on 915GLV
627  */
628 static hda_nid_t alc880_adc_nids_alt[2] = {
629         /* ADC1-2 */
630         0x08, 0x09,
631 };
632
633 #define ALC880_DIGOUT_NID       0x06
634 #define ALC880_DIGIN_NID        0x0a
635
636 static struct hda_input_mux alc880_capture_source = {
637         .num_items = 4,
638         .items = {
639                 { "Mic", 0x0 },
640                 { "Front Mic", 0x3 },
641                 { "Line", 0x2 },
642                 { "CD", 0x4 },
643         },
644 };
645
646 /* channel source setting (2/6 channel selection for 3-stack) */
647 /* 2ch mode */
648 static struct hda_verb alc880_threestack_ch2_init[] = {
649         /* set line-in to input, mute it */
650         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
651         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
652         /* set mic-in to input vref 80%, mute it */
653         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
654         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
655         { } /* end */
656 };
657
658 /* 6ch mode */
659 static struct hda_verb alc880_threestack_ch6_init[] = {
660         /* set line-in to output, unmute it */
661         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
662         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
663         /* set mic-in to output, unmute it */
664         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
665         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
666         { } /* end */
667 };
668
669 static struct hda_channel_mode alc880_threestack_modes[2] = {
670         { 2, alc880_threestack_ch2_init },
671         { 6, alc880_threestack_ch6_init },
672 };
673
674 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
675         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
676         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
677         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
678         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
679         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
680         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
681         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
682         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
683         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
684         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
685         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
686         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
687         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
688         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
689         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
690         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
691         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
692         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
693         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
694         {
695                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
696                 .name = "Channel Mode",
697                 .info = alc_ch_mode_info,
698                 .get = alc_ch_mode_get,
699                 .put = alc_ch_mode_put,
700         },
701         { } /* end */
702 };
703
704 /* capture mixer elements */
705 static struct snd_kcontrol_new alc880_capture_mixer[] = {
706         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
707         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
708         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
709         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
710         HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
711         HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
712         {
713                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
714                 /* The multiple "Capture Source" controls confuse alsamixer
715                  * So call somewhat different..
716                  * FIXME: the controls appear in the "playback" view!
717                  */
718                 /* .name = "Capture Source", */
719                 .name = "Input Source",
720                 .count = 3,
721                 .info = alc_mux_enum_info,
722                 .get = alc_mux_enum_get,
723                 .put = alc_mux_enum_put,
724         },
725         { } /* end */
726 };
727
728 /* capture mixer elements (in case NID 0x07 not available) */
729 static struct snd_kcontrol_new alc880_capture_alt_mixer[] = {
730         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
731         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
732         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
733         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
734         {
735                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
736                 /* The multiple "Capture Source" controls confuse alsamixer
737                  * So call somewhat different..
738                  * FIXME: the controls appear in the "playback" view!
739                  */
740                 /* .name = "Capture Source", */
741                 .name = "Input Source",
742                 .count = 2,
743                 .info = alc_mux_enum_info,
744                 .get = alc_mux_enum_get,
745                 .put = alc_mux_enum_put,
746         },
747         { } /* end */
748 };
749
750
751
752 /*
753  * ALC880 5-stack model
754  *
755  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
756  *      Side = 0x02 (0xd)
757  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
758  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
759  */
760
761 /* additional mixers to alc880_three_stack_mixer */
762 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
763         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
764         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
765         { } /* end */
766 };
767
768 /* channel source setting (6/8 channel selection for 5-stack) */
769 /* 6ch mode */
770 static struct hda_verb alc880_fivestack_ch6_init[] = {
771         /* set line-in to input, mute it */
772         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
773         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
774         { } /* end */
775 };
776
777 /* 8ch mode */
778 static struct hda_verb alc880_fivestack_ch8_init[] = {
779         /* set line-in to output, unmute it */
780         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
781         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
782         { } /* end */
783 };
784
785 static struct hda_channel_mode alc880_fivestack_modes[2] = {
786         { 6, alc880_fivestack_ch6_init },
787         { 8, alc880_fivestack_ch8_init },
788 };
789
790
791 /*
792  * ALC880 6-stack model
793  *
794  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
795  *      Side = 0x05 (0x0f)
796  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
797  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
798  */
799
800 static hda_nid_t alc880_6st_dac_nids[4] = {
801         /* front, rear, clfe, rear_surr */
802         0x02, 0x03, 0x04, 0x05
803 };      
804
805 static struct hda_input_mux alc880_6stack_capture_source = {
806         .num_items = 4,
807         .items = {
808                 { "Mic", 0x0 },
809                 { "Front Mic", 0x1 },
810                 { "Line", 0x2 },
811                 { "CD", 0x4 },
812         },
813 };
814
815 /* fixed 8-channels */
816 static struct hda_channel_mode alc880_sixstack_modes[1] = {
817         { 8, NULL },
818 };
819
820 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
821         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
822         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
823         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
824         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
825         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
826         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
827         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
828         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
829         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
830         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
831         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
832         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
833         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
834         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
835         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
836         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
837         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
838         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
839         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
840         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
841         {
842                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
843                 .name = "Channel Mode",
844                 .info = alc_ch_mode_info,
845                 .get = alc_ch_mode_get,
846                 .put = alc_ch_mode_put,
847         },
848         { } /* end */
849 };
850
851
852 /*
853  * ALC880 W810 model
854  *
855  * W810 has rear IO for:
856  * Front (DAC 02)
857  * Surround (DAC 03)
858  * Center/LFE (DAC 04)
859  * Digital out (06)
860  *
861  * The system also has a pair of internal speakers, and a headphone jack.
862  * These are both connected to Line2 on the codec, hence to DAC 02.
863  * 
864  * There is a variable resistor to control the speaker or headphone
865  * volume. This is a hardware-only device without a software API.
866  *
867  * Plugging headphones in will disable the internal speakers. This is
868  * implemented in hardware, not via the driver using jack sense. In
869  * a similar fashion, plugging into the rear socket marked "front" will
870  * disable both the speakers and headphones.
871  *
872  * For input, there's a microphone jack, and an "audio in" jack.
873  * These may not do anything useful with this driver yet, because I
874  * haven't setup any initialization verbs for these yet...
875  */
876
877 static hda_nid_t alc880_w810_dac_nids[3] = {
878         /* front, rear/surround, clfe */
879         0x02, 0x03, 0x04
880 };
881
882 /* fixed 6 channels */
883 static struct hda_channel_mode alc880_w810_modes[1] = {
884         { 6, NULL }
885 };
886
887 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
888 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
889         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
890         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
891         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
892         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
893         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
894         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
895         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
896         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
897         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
898         { } /* end */
899 };
900
901
902 /*
903  * Z710V model
904  *
905  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
906  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
907  *                 Line = 0x1a
908  */
909
910 static hda_nid_t alc880_z71v_dac_nids[1] = {
911         0x02
912 };
913 #define ALC880_Z71V_HP_DAC      0x03
914
915 /* fixed 2 channels */
916 static struct hda_channel_mode alc880_2_jack_modes[1] = {
917         { 2, NULL }
918 };
919
920 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
921         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
922         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
923         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
924         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
925         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
926         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
927         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
928         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
929         { } /* end */
930 };
931
932
933 /* FIXME! */
934 /*
935  * ALC880 F1734 model
936  *
937  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
938  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
939  */
940
941 static hda_nid_t alc880_f1734_dac_nids[1] = {
942         0x03
943 };
944 #define ALC880_F1734_HP_DAC     0x02
945
946 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
947         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
948         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
949         HDA_CODEC_VOLUME("Internal Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
950         HDA_BIND_MUTE("Internal Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
951         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
952         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
953         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
954         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
955         { } /* end */
956 };
957
958
959 /* FIXME! */
960 /*
961  * ALC880 ASUS model
962  *
963  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
964  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
965  *  Mic = 0x18, Line = 0x1a
966  */
967
968 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
969 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
970
971 static struct snd_kcontrol_new alc880_asus_mixer[] = {
972         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
973         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
974         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
975         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
976         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
977         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
978         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
979         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
980         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
981         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
982         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
983         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
984         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
985         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
986         {
987                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
988                 .name = "Channel Mode",
989                 .info = alc_ch_mode_info,
990                 .get = alc_ch_mode_get,
991                 .put = alc_ch_mode_put,
992         },
993         { } /* end */
994 };
995
996 /* FIXME! */
997 /*
998  * ALC880 ASUS W1V model
999  *
1000  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1001  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1002  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
1003  */
1004
1005 /* additional mixers to alc880_asus_mixer */
1006 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
1007         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
1008         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
1009         { } /* end */
1010 };
1011
1012 /* additional mixers to alc880_asus_mixer */
1013 static struct snd_kcontrol_new alc880_pcbeep_mixer[] = {
1014         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1015         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1016         { } /* end */
1017 };
1018
1019 /* TCL S700 */
1020 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
1021         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1022         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1023         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1024         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
1025         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
1026         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
1027         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
1028         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1029         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1030         {
1031                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1032                 /* The multiple "Capture Source" controls confuse alsamixer
1033                  * So call somewhat different..
1034                  * FIXME: the controls appear in the "playback" view!
1035                  */
1036                 /* .name = "Capture Source", */
1037                 .name = "Input Source",
1038                 .count = 1,
1039                 .info = alc_mux_enum_info,
1040                 .get = alc_mux_enum_get,
1041                 .put = alc_mux_enum_put,
1042         },
1043         { } /* end */
1044 };
1045
1046 /* Uniwill */
1047 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
1048         HDA_CODEC_VOLUME("HPhone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1049         HDA_BIND_MUTE("HPhone Playback Switch", 0x0c, 2, HDA_INPUT),
1050         HDA_CODEC_VOLUME("iSpeaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1051         HDA_BIND_MUTE("iSpeaker Playback Switch", 0x0d, 2, HDA_INPUT),
1052         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1053         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1054         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1055         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1056         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1057         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1058         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1059         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1060         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1061         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1062         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1063         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1064         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1065         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1066         {
1067                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1068                 .name = "Channel Mode",
1069                 .info = alc_ch_mode_info,
1070                 .get = alc_ch_mode_get,
1071                 .put = alc_ch_mode_put,
1072         },
1073         { } /* end */
1074 };
1075
1076 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
1077         HDA_CODEC_VOLUME("HPhone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1078         HDA_BIND_MUTE("HPhone Playback Switch", 0x0c, 2, HDA_INPUT),
1079         HDA_CODEC_VOLUME("iSpeaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1080         HDA_BIND_MUTE("iSpeaker Playback Switch", 0x0d, 2, HDA_INPUT),
1081         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1082         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1083         { } /* end */
1084 };
1085
1086 /*
1087  * build control elements
1088  */
1089 static int alc_build_controls(struct hda_codec *codec)
1090 {
1091         struct alc_spec *spec = codec->spec;
1092         int err;
1093         int i;
1094
1095         for (i = 0; i < spec->num_mixers; i++) {
1096                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1097                 if (err < 0)
1098                         return err;
1099         }
1100
1101         if (spec->multiout.dig_out_nid) {
1102                 err = snd_hda_create_spdif_out_ctls(codec,
1103                                                     spec->multiout.dig_out_nid);
1104                 if (err < 0)
1105                         return err;
1106         }
1107         if (spec->dig_in_nid) {
1108                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1109                 if (err < 0)
1110                         return err;
1111         }
1112         return 0;
1113 }
1114
1115
1116 /*
1117  * initialize the codec volumes, etc
1118  */
1119
1120 /*
1121  * generic initialization of ADC, input mixers and output mixers
1122  */
1123 static struct hda_verb alc880_volume_init_verbs[] = {
1124         /*
1125          * Unmute ADC0-2 and set the default input to mic-in
1126          */
1127         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
1128         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1129         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
1130         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1131         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
1132         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1133
1134         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1135          * mixer widget
1136          * Note: PASD motherboards uses the Line In 2 as the input for front
1137          * panel mic (mic 2)
1138          */
1139         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
1140         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1141         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1142         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1143         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1144         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1145
1146         /*
1147          * Set up output mixers (0x0c - 0x0f)
1148          */
1149         /* set vol=0 to output mixers */
1150         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1151         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1152         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1153         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1154         /* set up input amps for analog loopback */
1155         /* Amp Indices: DAC = 0, mixer = 1 */
1156         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1157         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1158         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1159         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1160         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1161         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1162         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1163         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1164
1165         { }
1166 };
1167
1168 /*
1169  * 3-stack pin configuration:
1170  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
1171  */
1172 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
1173         /*
1174          * preset connection lists of input pins
1175          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1176          */
1177         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
1178         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1179         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
1180
1181         /*
1182          * Set pin mode and muting
1183          */
1184         /* set front pin widgets 0x14 for output */
1185         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1186         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1187         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1188         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1189         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1190         /* Mic2 (as headphone out) for HP output */
1191         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1192         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1193         /* Line In pin widget for input */
1194         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1195         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1196         /* Line2 (as front mic) pin widget for input and vref at 80% */
1197         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1198         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1199         /* CD pin widget for input */
1200         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1201
1202         { }
1203 };
1204
1205 /*
1206  * 5-stack pin configuration:
1207  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
1208  * line-in/side = 0x1a, f-mic = 0x1b
1209  */
1210 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
1211         /*
1212          * preset connection lists of input pins
1213          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1214          */
1215         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1216         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
1217
1218         /*
1219          * Set pin mode and muting
1220          */
1221         /* set pin widgets 0x14-0x17 for output */
1222         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1223         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1224         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1225         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1226         /* unmute pins for output (no gain on this amp) */
1227         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1228         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1229         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1230         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1231
1232         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1233         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1234         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1235         /* Mic2 (as headphone out) for HP output */
1236         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1237         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1238         /* Line In pin widget for input */
1239         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1240         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1241         /* Line2 (as front mic) pin widget for input and vref at 80% */
1242         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1243         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1244         /* CD pin widget for input */
1245         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1246
1247         { }
1248 };
1249
1250 /*
1251  * W810 pin configuration:
1252  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
1253  */
1254 static struct hda_verb alc880_pin_w810_init_verbs[] = {
1255         /* hphone/speaker input selector: front DAC */
1256         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
1257
1258         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1259         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1260         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1261         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1262         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1263         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1264
1265         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1266         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1267
1268         { }
1269 };
1270
1271 /*
1272  * Z71V pin configuration:
1273  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
1274  */
1275 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
1276         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1277         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1278         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1279         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1280
1281         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1282         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1283         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1284         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1285
1286         { }
1287 };
1288
1289 /*
1290  * 6-stack pin configuration:
1291  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
1292  * f-mic = 0x19, line = 0x1a, HP = 0x1b
1293  */
1294 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
1295         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1296
1297         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1298         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1299         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1300         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1301         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1302         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1303         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1304         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1305
1306         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1307         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1308         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1309         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1310         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1311         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1312         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1313         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1314         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1315         
1316         { }
1317 };
1318
1319 /*
1320  * Uniwill pin configuration:
1321  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
1322  * line = 0x1a
1323  */
1324 static struct hda_verb alc880_uniwill_init_verbs[] = {
1325         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1326
1327         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1328         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1329         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1330         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1331         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1332         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1333         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1334         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1335         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1336         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1337         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1338         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1339         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1340         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1341
1342         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1343         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1344         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1345         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1346         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1347         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1348         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
1349         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
1350         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1351
1352         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
1353         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
1354
1355         { }
1356 };
1357
1358 /*
1359 * Uniwill P53
1360 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19, 
1361  */
1362 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
1363         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1364
1365         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1366         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1367         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1368         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1369         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1370         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1371         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1372         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1373         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1374         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1375         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1376         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1377
1378         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1379         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1380         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1381         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1382         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1383         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1384
1385         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
1386         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
1387
1388         { }
1389 };
1390
1391 /* toggle speaker-output according to the hp-jack state */
1392 static void alc880_uniwill_automute(struct hda_codec *codec)
1393 {
1394         unsigned int present;
1395
1396         present = snd_hda_codec_read(codec, 0x14, 0,
1397                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1398         snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
1399                                  0x80, present ? 0x80 : 0);
1400         snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
1401                                  0x80, present ? 0x80 : 0);
1402         snd_hda_codec_amp_update(codec, 0x16, 0, HDA_OUTPUT, 0,
1403                                  0x80, present ? 0x80 : 0);
1404         snd_hda_codec_amp_update(codec, 0x16, 1, HDA_OUTPUT, 0,
1405                                  0x80, present ? 0x80 : 0);
1406
1407         present = snd_hda_codec_read(codec, 0x18, 0,
1408                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1409         snd_hda_codec_write(codec, 0x0b, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1410                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
1411 }
1412
1413 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
1414                                        unsigned int res)
1415 {
1416         /* Looks like the unsol event is incompatible with the standard
1417          * definition.  4bit tag is placed at 28 bit!
1418          */
1419         if ((res >> 28) == ALC880_HP_EVENT ||
1420             (res >> 28) == ALC880_MIC_EVENT)
1421                 alc880_uniwill_automute(codec);
1422 }
1423
1424 static void alc880_uniwill_p53_hp_automute(struct hda_codec *codec)
1425 {
1426         unsigned int present;
1427
1428         present = snd_hda_codec_read(codec, 0x14, 0,
1429                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1430
1431         snd_hda_codec_amp_update(codec, 0x15, 0, HDA_INPUT, 0,
1432                                  0x80, present ? 0x80 : 0);
1433         snd_hda_codec_amp_update(codec, 0x15, 1, HDA_INPUT, 0,
1434                                  0x80, present ? 0x80 : 0);
1435 }
1436
1437 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
1438 {
1439         unsigned int present;
1440         
1441         present = snd_hda_codec_read(codec, 0x21, 0,
1442                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0) & 0x7f;
1443
1444         snd_hda_codec_amp_update(codec, 0x0c, 0, HDA_OUTPUT, 0,
1445                                  0x7f, present);
1446         snd_hda_codec_amp_update(codec, 0x0c, 1, HDA_OUTPUT, 0,
1447                                  0x7f,  present);
1448
1449         snd_hda_codec_amp_update(codec, 0x0d, 0, HDA_OUTPUT, 0,
1450                                  0x7f,  present);
1451         snd_hda_codec_amp_update(codec, 0x0d, 1, HDA_OUTPUT, 0,
1452                                  0x7f, present);
1453
1454 }
1455 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
1456                                            unsigned int res)
1457 {
1458         /* Looks like the unsol event is incompatible with the standard
1459          * definition.  4bit tag is placed at 28 bit!
1460          */
1461         if ((res >> 28) == ALC880_HP_EVENT)
1462                 alc880_uniwill_p53_hp_automute(codec);
1463         if ((res >> 28) == ALC880_DCVOL_EVENT) 
1464                 alc880_uniwill_p53_dcvol_automute(codec);
1465 }
1466
1467 /* FIXME! */
1468 /*
1469  * F1734 pin configuration:
1470  * HP = 0x14, speaker-out = 0x15, mic = 0x18
1471  */
1472 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
1473         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
1474         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
1475         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
1476         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
1477
1478         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1479         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1480         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1481         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1482
1483         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1484         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1485         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1486         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1487         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1488         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1489         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1490         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1491         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1492
1493         { }
1494 };
1495
1496 /* FIXME! */
1497 /*
1498  * ASUS pin configuration:
1499  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
1500  */
1501 static struct hda_verb alc880_pin_asus_init_verbs[] = {
1502         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
1503         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
1504         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
1505         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
1506
1507         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1508         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1509         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1510         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1511         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1512         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1513         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1514         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1515
1516         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1517         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1518         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1519         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1520         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1521         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1522         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1523         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1524         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1525         
1526         { }
1527 };
1528
1529 /* Enable GPIO mask and set output */
1530 static struct hda_verb alc880_gpio1_init_verbs[] = {
1531         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
1532         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
1533         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
1534
1535         { }
1536 };
1537
1538 /* Enable GPIO mask and set output */
1539 static struct hda_verb alc880_gpio2_init_verbs[] = {
1540         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
1541         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
1542         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
1543
1544         { }
1545 };
1546
1547 /* Clevo m520g init */
1548 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
1549         /* headphone output */
1550         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
1551         /* line-out */
1552         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1553         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1554         /* Line-in */
1555         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1556         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1557         /* CD */
1558         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1559         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1560         /* Mic1 (rear panel) */
1561         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1562         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1563         /* Mic2 (front panel) */
1564         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1565         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1566         /* headphone */
1567         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1568         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1569         /* change to EAPD mode */
1570         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
1571         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
1572
1573         { }
1574 };
1575
1576 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
1577         /* change to EAPD mode */
1578         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
1579         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
1580
1581         /* Headphone output */
1582         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1583         /* Front output*/
1584         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1585         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1586
1587         /* Line In pin widget for input */
1588         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1589         /* CD pin widget for input */
1590         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1591         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1592         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1593
1594         /* change to EAPD mode */
1595         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
1596         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
1597
1598         { }
1599 };
1600
1601 /*
1602  * LG m1 express dual
1603  *
1604  * Pin assignment:
1605  *   Rear Line-In/Out (blue): 0x14
1606  *   Build-in Mic-In: 0x15
1607  *   Speaker-out: 0x17
1608  *   HP-Out (green): 0x1b
1609  *   Mic-In/Out (red): 0x19
1610  *   SPDIF-Out: 0x1e
1611  */
1612
1613 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
1614 static hda_nid_t alc880_lg_dac_nids[3] = {
1615         0x05, 0x02, 0x03
1616 };
1617
1618 /* seems analog CD is not working */
1619 static struct hda_input_mux alc880_lg_capture_source = {
1620         .num_items = 3,
1621         .items = {
1622                 { "Mic", 0x1 },
1623                 { "Line", 0x5 },
1624                 { "Internal Mic", 0x6 },
1625         },
1626 };
1627
1628 /* 2,4,6 channel modes */
1629 static struct hda_verb alc880_lg_ch2_init[] = {
1630         /* set line-in and mic-in to input */
1631         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1632         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1633         { }
1634 };
1635
1636 static struct hda_verb alc880_lg_ch4_init[] = {
1637         /* set line-in to out and mic-in to input */
1638         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1639         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1640         { }
1641 };
1642
1643 static struct hda_verb alc880_lg_ch6_init[] = {
1644         /* set line-in and mic-in to output */
1645         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1646         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1647         { }
1648 };
1649
1650 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
1651         { 2, alc880_lg_ch2_init },
1652         { 4, alc880_lg_ch4_init },
1653         { 6, alc880_lg_ch6_init },
1654 };
1655
1656 static struct snd_kcontrol_new alc880_lg_mixer[] = {
1657         /* FIXME: it's not really "master" but front channels */
1658         HDA_CODEC_VOLUME("Master Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1659         HDA_BIND_MUTE("Master Playback Switch", 0x0f, 2, HDA_INPUT),
1660         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1661         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
1662         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
1663         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
1664         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
1665         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
1666         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1667         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1668         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
1669         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
1670         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
1671         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
1672         {
1673                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1674                 .name = "Channel Mode",
1675                 .info = alc_ch_mode_info,
1676                 .get = alc_ch_mode_get,
1677                 .put = alc_ch_mode_put,
1678         },
1679         { } /* end */
1680 };
1681
1682 static struct hda_verb alc880_lg_init_verbs[] = {
1683         /* set capture source to mic-in */
1684         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1685         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1686         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1687         /* mute all amp mixer inputs */
1688         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
1689         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(6)},
1690         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(7)},
1691         /* line-in to input */
1692         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1693         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1694         /* built-in mic */
1695         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1696         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1697         /* speaker-out */
1698         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1699         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1700         /* mic-in to input */
1701         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
1702         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1703         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1704         /* HP-out */
1705         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
1706         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1707         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1708         /* jack sense */
1709         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
1710         { }
1711 };
1712
1713 /* toggle speaker-output according to the hp-jack state */
1714 static void alc880_lg_automute(struct hda_codec *codec)
1715 {
1716         unsigned int present;
1717
1718         present = snd_hda_codec_read(codec, 0x1b, 0,
1719                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1720         snd_hda_codec_amp_update(codec, 0x17, 0, HDA_OUTPUT, 0,
1721                                  0x80, present ? 0x80 : 0);
1722         snd_hda_codec_amp_update(codec, 0x17, 1, HDA_OUTPUT, 0,
1723                                  0x80, present ? 0x80 : 0);
1724 }
1725
1726 static void alc880_lg_unsol_event(struct hda_codec *codec, unsigned int res)
1727 {
1728         /* Looks like the unsol event is incompatible with the standard
1729          * definition.  4bit tag is placed at 28 bit!
1730          */
1731         if ((res >> 28) == 0x01)
1732                 alc880_lg_automute(codec);
1733 }
1734
1735 /*
1736  * LG LW20
1737  *
1738  * Pin assignment:
1739  *   Speaker-out: 0x14
1740  *   Mic-In: 0x18
1741  *   Built-in Mic-In: 0x19 (?)
1742  *   HP-Out: 0x1b
1743  *   SPDIF-Out: 0x1e
1744  */
1745
1746 /* seems analog CD is not working */
1747 static struct hda_input_mux alc880_lg_lw_capture_source = {
1748         .num_items = 2,
1749         .items = {
1750                 { "Mic", 0x0 },
1751                 { "Internal Mic", 0x1 },
1752         },
1753 };
1754
1755 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
1756         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1757         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
1758         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1759         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1760         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
1761         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
1762         { } /* end */
1763 };
1764
1765 static struct hda_verb alc880_lg_lw_init_verbs[] = {
1766         /* set capture source to mic-in */
1767         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1768         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1769         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1770         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(7)},
1771         /* speaker-out */
1772         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1773         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1774         /* HP-out */
1775         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
1776         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1777         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1778         /* mic-in to input */
1779         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1780         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1781         /* built-in mic */
1782         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1783         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1784         /* jack sense */
1785         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
1786         { }
1787 };
1788
1789 /* toggle speaker-output according to the hp-jack state */
1790 static void alc880_lg_lw_automute(struct hda_codec *codec)
1791 {
1792         unsigned int present;
1793
1794         present = snd_hda_codec_read(codec, 0x1b, 0,
1795                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1796         snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
1797                                  0x80, present ? 0x80 : 0);
1798         snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
1799                                  0x80, present ? 0x80 : 0);
1800 }
1801
1802 static void alc880_lg_lw_unsol_event(struct hda_codec *codec, unsigned int res)
1803 {
1804         /* Looks like the unsol event is incompatible with the standard
1805          * definition.  4bit tag is placed at 28 bit!
1806          */
1807         if ((res >> 28) == 0x01)
1808                 alc880_lg_lw_automute(codec);
1809 }
1810
1811 /*
1812  * Common callbacks
1813  */
1814
1815 static int alc_init(struct hda_codec *codec)
1816 {
1817         struct alc_spec *spec = codec->spec;
1818         unsigned int i;
1819
1820         for (i = 0; i < spec->num_init_verbs; i++)
1821                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
1822
1823         if (spec->init_hook)
1824                 spec->init_hook(codec);
1825
1826         return 0;
1827 }
1828
1829 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
1830 {
1831         struct alc_spec *spec = codec->spec;
1832
1833         if (spec->unsol_event)
1834                 spec->unsol_event(codec, res);
1835 }
1836
1837 #ifdef CONFIG_PM
1838 /*
1839  * resume
1840  */
1841 static int alc_resume(struct hda_codec *codec)
1842 {
1843         struct alc_spec *spec = codec->spec;
1844         int i;
1845
1846         alc_init(codec);
1847         for (i = 0; i < spec->num_mixers; i++)
1848                 snd_hda_resume_ctls(codec, spec->mixers[i]);
1849         if (spec->multiout.dig_out_nid)
1850                 snd_hda_resume_spdif_out(codec);
1851         if (spec->dig_in_nid)
1852                 snd_hda_resume_spdif_in(codec);
1853
1854         return 0;
1855 }
1856 #endif
1857
1858 /*
1859  * Analog playback callbacks
1860  */
1861 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
1862                                     struct hda_codec *codec,
1863                                     struct snd_pcm_substream *substream)
1864 {
1865         struct alc_spec *spec = codec->spec;
1866         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
1867 }
1868
1869 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1870                                        struct hda_codec *codec,
1871                                        unsigned int stream_tag,
1872                                        unsigned int format,
1873                                        struct snd_pcm_substream *substream)
1874 {
1875         struct alc_spec *spec = codec->spec;
1876         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
1877                                                 stream_tag, format, substream);
1878 }
1879
1880 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1881                                        struct hda_codec *codec,
1882                                        struct snd_pcm_substream *substream)
1883 {
1884         struct alc_spec *spec = codec->spec;
1885         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1886 }
1887
1888 /*
1889  * Digital out
1890  */
1891 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1892                                         struct hda_codec *codec,
1893                                         struct snd_pcm_substream *substream)
1894 {
1895         struct alc_spec *spec = codec->spec;
1896         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1897 }
1898
1899 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1900                                          struct hda_codec *codec,
1901                                          struct snd_pcm_substream *substream)
1902 {
1903         struct alc_spec *spec = codec->spec;
1904         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1905 }
1906
1907 /*
1908  * Analog capture
1909  */
1910 static int alc880_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1911                                       struct hda_codec *codec,
1912                                       unsigned int stream_tag,
1913                                       unsigned int format,
1914                                       struct snd_pcm_substream *substream)
1915 {
1916         struct alc_spec *spec = codec->spec;
1917
1918         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1919                                    stream_tag, 0, format);
1920         return 0;
1921 }
1922
1923 static int alc880_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1924                                       struct hda_codec *codec,
1925                                       struct snd_pcm_substream *substream)
1926 {
1927         struct alc_spec *spec = codec->spec;
1928
1929         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1930                                    0, 0, 0);
1931         return 0;
1932 }
1933
1934
1935 /*
1936  */
1937 static struct hda_pcm_stream alc880_pcm_analog_playback = {
1938         .substreams = 1,
1939         .channels_min = 2,
1940         .channels_max = 8,
1941         /* NID is set in alc_build_pcms */
1942         .ops = {
1943                 .open = alc880_playback_pcm_open,
1944                 .prepare = alc880_playback_pcm_prepare,
1945                 .cleanup = alc880_playback_pcm_cleanup
1946         },
1947 };
1948
1949 static struct hda_pcm_stream alc880_pcm_analog_capture = {
1950         .substreams = 2,
1951         .channels_min = 2,
1952         .channels_max = 2,
1953         /* NID is set in alc_build_pcms */
1954         .ops = {
1955                 .prepare = alc880_capture_pcm_prepare,
1956                 .cleanup = alc880_capture_pcm_cleanup
1957         },
1958 };
1959
1960 static struct hda_pcm_stream alc880_pcm_digital_playback = {
1961         .substreams = 1,
1962         .channels_min = 2,
1963         .channels_max = 2,
1964         /* NID is set in alc_build_pcms */
1965         .ops = {
1966                 .open = alc880_dig_playback_pcm_open,
1967                 .close = alc880_dig_playback_pcm_close
1968         },
1969 };
1970
1971 static struct hda_pcm_stream alc880_pcm_digital_capture = {
1972         .substreams = 1,
1973         .channels_min = 2,
1974         .channels_max = 2,
1975         /* NID is set in alc_build_pcms */
1976 };
1977
1978 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
1979 static struct hda_pcm_stream alc_pcm_null_playback = {
1980         .substreams = 0,
1981         .channels_min = 0,
1982         .channels_max = 0,
1983 };
1984
1985 static int alc_build_pcms(struct hda_codec *codec)
1986 {
1987         struct alc_spec *spec = codec->spec;
1988         struct hda_pcm *info = spec->pcm_rec;
1989         int i;
1990
1991         codec->num_pcms = 1;
1992         codec->pcm_info = info;
1993
1994         info->name = spec->stream_name_analog;
1995         if (spec->stream_analog_playback) {
1996                 snd_assert(spec->multiout.dac_nids, return -EINVAL);
1997                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
1998                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
1999         }
2000         if (spec->stream_analog_capture) {
2001                 snd_assert(spec->adc_nids, return -EINVAL);
2002                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
2003                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2004         }
2005
2006         if (spec->channel_mode) {
2007                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2008                 for (i = 0; i < spec->num_channel_mode; i++) {
2009                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2010                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2011                         }
2012                 }
2013         }
2014
2015         /* SPDIF for stream index #1 */
2016         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2017                 codec->num_pcms = 2;
2018                 info = spec->pcm_rec + 1;
2019                 info->name = spec->stream_name_digital;
2020                 if (spec->multiout.dig_out_nid &&
2021                     spec->stream_digital_playback) {
2022                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
2023                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2024                 }
2025                 if (spec->dig_in_nid &&
2026                     spec->stream_digital_capture) {
2027                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
2028                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2029                 }
2030         }
2031
2032         /* If the use of more than one ADC is requested for the current
2033          * model, configure a second analog capture-only PCM.
2034          */
2035         /* Additional Analaog capture for index #2 */
2036         if (spec->num_adc_nids > 1 && spec->stream_analog_capture &&
2037             spec->adc_nids) {
2038                 codec->num_pcms = 3;
2039                 info = spec->pcm_rec + 2;
2040                 info->name = spec->stream_name_analog;
2041                 /* No playback stream for second PCM */
2042                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = alc_pcm_null_playback;
2043                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2044                 if (spec->stream_analog_capture) {
2045                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
2046                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[1];
2047                 }
2048         }
2049
2050         return 0;
2051 }
2052
2053 static void alc_free(struct hda_codec *codec)
2054 {
2055         struct alc_spec *spec = codec->spec;
2056         unsigned int i;
2057
2058         if (! spec)
2059                 return;
2060
2061         if (spec->kctl_alloc) {
2062                 for (i = 0; i < spec->num_kctl_used; i++)
2063                         kfree(spec->kctl_alloc[i].name);
2064                 kfree(spec->kctl_alloc);
2065         }
2066         kfree(spec);
2067 }
2068
2069 /*
2070  */
2071 static struct hda_codec_ops alc_patch_ops = {
2072         .build_controls = alc_build_controls,
2073         .build_pcms = alc_build_pcms,
2074         .init = alc_init,
2075         .free = alc_free,
2076         .unsol_event = alc_unsol_event,
2077 #ifdef CONFIG_PM
2078         .resume = alc_resume,
2079 #endif
2080 };
2081
2082
2083 /*
2084  * Test configuration for debugging
2085  *
2086  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
2087  * enum controls.
2088  */
2089 #ifdef CONFIG_SND_DEBUG
2090 static hda_nid_t alc880_test_dac_nids[4] = {
2091         0x02, 0x03, 0x04, 0x05
2092 };
2093
2094 static struct hda_input_mux alc880_test_capture_source = {
2095         .num_items = 7,
2096         .items = {
2097                 { "In-1", 0x0 },
2098                 { "In-2", 0x1 },
2099                 { "In-3", 0x2 },
2100                 { "In-4", 0x3 },
2101                 { "CD", 0x4 },
2102                 { "Front", 0x5 },
2103                 { "Surround", 0x6 },
2104         },
2105 };
2106
2107 static struct hda_channel_mode alc880_test_modes[4] = {
2108         { 2, NULL },
2109         { 4, NULL },
2110         { 6, NULL },
2111         { 8, NULL },
2112 };
2113
2114 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
2115                                  struct snd_ctl_elem_info *uinfo)
2116 {
2117         static char *texts[] = {
2118                 "N/A", "Line Out", "HP Out",
2119                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
2120         };
2121         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2122         uinfo->count = 1;
2123         uinfo->value.enumerated.items = 8;
2124         if (uinfo->value.enumerated.item >= 8)
2125                 uinfo->value.enumerated.item = 7;
2126         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2127         return 0;
2128 }
2129
2130 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
2131                                 struct snd_ctl_elem_value *ucontrol)
2132 {
2133         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2134         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2135         unsigned int pin_ctl, item = 0;
2136
2137         pin_ctl = snd_hda_codec_read(codec, nid, 0,
2138                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2139         if (pin_ctl & AC_PINCTL_OUT_EN) {
2140                 if (pin_ctl & AC_PINCTL_HP_EN)
2141                         item = 2;
2142                 else
2143                         item = 1;
2144         } else if (pin_ctl & AC_PINCTL_IN_EN) {
2145                 switch (pin_ctl & AC_PINCTL_VREFEN) {
2146                 case AC_PINCTL_VREF_HIZ: item = 3; break;
2147                 case AC_PINCTL_VREF_50:  item = 4; break;
2148                 case AC_PINCTL_VREF_GRD: item = 5; break;
2149                 case AC_PINCTL_VREF_80:  item = 6; break;
2150                 case AC_PINCTL_VREF_100: item = 7; break;
2151                 }
2152         }
2153         ucontrol->value.enumerated.item[0] = item;
2154         return 0;
2155 }
2156
2157 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
2158                                 struct snd_ctl_elem_value *ucontrol)
2159 {
2160         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2161         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2162         static unsigned int ctls[] = {
2163                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
2164                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
2165                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
2166                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
2167                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
2168                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
2169         };
2170         unsigned int old_ctl, new_ctl;
2171
2172         old_ctl = snd_hda_codec_read(codec, nid, 0,
2173                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2174         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
2175         if (old_ctl != new_ctl) {
2176                 snd_hda_codec_write(codec, nid, 0,
2177                                     AC_VERB_SET_PIN_WIDGET_CONTROL, new_ctl);
2178                 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2179                                     (ucontrol->value.enumerated.item[0] >= 3 ?
2180                                      0xb080 : 0xb000));
2181                 return 1;
2182         }
2183         return 0;
2184 }
2185
2186 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
2187                                  struct snd_ctl_elem_info *uinfo)
2188 {
2189         static char *texts[] = {
2190                 "Front", "Surround", "CLFE", "Side"
2191         };
2192         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2193         uinfo->count = 1;
2194         uinfo->value.enumerated.items = 4;
2195         if (uinfo->value.enumerated.item >= 4)
2196                 uinfo->value.enumerated.item = 3;
2197         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2198         return 0;
2199 }
2200
2201 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
2202                                 struct snd_ctl_elem_value *ucontrol)
2203 {
2204         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2205         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2206         unsigned int sel;
2207
2208         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
2209         ucontrol->value.enumerated.item[0] = sel & 3;
2210         return 0;
2211 }
2212
2213 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
2214                                 struct snd_ctl_elem_value *ucontrol)
2215 {
2216         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2217         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2218         unsigned int sel;
2219
2220         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
2221         if (ucontrol->value.enumerated.item[0] != sel) {
2222                 sel = ucontrol->value.enumerated.item[0] & 3;
2223                 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, sel);
2224                 return 1;
2225         }
2226         return 0;
2227 }
2228
2229 #define PIN_CTL_TEST(xname,nid) {                       \
2230                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
2231                         .name = xname,                 \
2232                         .info = alc_test_pin_ctl_info, \
2233                         .get = alc_test_pin_ctl_get,   \
2234                         .put = alc_test_pin_ctl_put,   \
2235                         .private_value = nid           \
2236                         }
2237
2238 #define PIN_SRC_TEST(xname,nid) {                       \
2239                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
2240                         .name = xname,                 \
2241                         .info = alc_test_pin_src_info, \
2242                         .get = alc_test_pin_src_get,   \
2243                         .put = alc_test_pin_src_put,   \
2244                         .private_value = nid           \
2245                         }
2246
2247 static struct snd_kcontrol_new alc880_test_mixer[] = {
2248         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2249         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2250         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
2251         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2252         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2253         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2254         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
2255         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2256         PIN_CTL_TEST("Front Pin Mode", 0x14),
2257         PIN_CTL_TEST("Surround Pin Mode", 0x15),
2258         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
2259         PIN_CTL_TEST("Side Pin Mode", 0x17),
2260         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
2261         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
2262         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
2263         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
2264         PIN_SRC_TEST("In-1 Pin Source", 0x18),
2265         PIN_SRC_TEST("In-2 Pin Source", 0x19),
2266         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
2267         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
2268         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
2269         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
2270         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
2271         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
2272         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
2273         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
2274         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
2275         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
2276         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
2277         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
2278         {
2279                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2280                 .name = "Channel Mode",
2281                 .info = alc_ch_mode_info,
2282                 .get = alc_ch_mode_get,
2283                 .put = alc_ch_mode_put,
2284         },
2285         { } /* end */
2286 };
2287
2288 static struct hda_verb alc880_test_init_verbs[] = {
2289         /* Unmute inputs of 0x0c - 0x0f */
2290         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2291         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2292         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2293         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2294         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2295         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2296         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2297         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2298         /* Vol output for 0x0c-0x0f */
2299         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2300         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2301         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2302         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2303         /* Set output pins 0x14-0x17 */
2304         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2305         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2306         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2307         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2308         /* Unmute output pins 0x14-0x17 */
2309         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2310         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2311         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2312         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2313         /* Set input pins 0x18-0x1c */
2314         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2315         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2316         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2317         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2318         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2319         /* Mute input pins 0x18-0x1b */
2320         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2321         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2322         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2323         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2324         /* ADC set up */
2325         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2326         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2327         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2328         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2329         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2330         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2331         /* Analog input/passthru */
2332         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2333         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2334         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2335         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2336         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2337         { }
2338 };
2339 #endif
2340
2341 /*
2342  */
2343
2344 static const char *alc880_models[ALC880_MODEL_LAST] = {
2345         [ALC880_3ST]            = "3stack",
2346         [ALC880_TCL_S700]       = "tcl",
2347         [ALC880_3ST_DIG]        = "3stack-digout",
2348         [ALC880_CLEVO]          = "clevo",
2349         [ALC880_5ST]            = "5stack",
2350         [ALC880_5ST_DIG]        = "5stack-digout",
2351         [ALC880_W810]           = "w810",
2352         [ALC880_Z71V]           = "z71v",
2353         [ALC880_6ST]            = "6stack",
2354         [ALC880_6ST_DIG]        = "6stack-digout",
2355         [ALC880_ASUS]           = "asus",
2356         [ALC880_ASUS_W1V]       = "asus-w1v",
2357         [ALC880_ASUS_DIG]       = "asus-dig",
2358         [ALC880_ASUS_DIG2]      = "asus-dig2",
2359         [ALC880_UNIWILL_DIG]    = "uniwill",
2360         [ALC880_F1734]          = "F1734",
2361         [ALC880_LG]             = "lg",
2362         [ALC880_LG_LW]          = "lg-lw",
2363 #ifdef CONFIG_SND_DEBUG
2364         [ALC880_TEST]           = "test",
2365 #endif
2366         [ALC880_AUTO]           = "auto",
2367 };
2368
2369 static struct snd_pci_quirk alc880_cfg_tbl[] = {
2370         /* Broken BIOS configuration */
2371         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG),
2372         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
2373
2374         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
2375         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
2376         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
2377         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
2378         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
2379         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
2380         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
2381         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
2382         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
2383
2384         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
2385         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
2386
2387         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
2388         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
2389         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
2390         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
2391         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
2392         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
2393         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
2394         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
2395         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
2396         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
2397         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS", ALC880_ASUS),
2398         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
2399         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
2400         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
2401         SND_PCI_QUIRK(0x1043, 0, "ASUS", ALC880_ASUS),
2402
2403         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
2404         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
2405         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
2406         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
2407         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
2408         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
2409         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
2410         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
2411         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
2412         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
2413         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
2414         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
2415         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
2416         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
2417         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
2418         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
2419         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
2420         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
2421
2422         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
2423         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
2424         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
2425         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
2426
2427         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
2428         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
2429         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
2430
2431         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
2432         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
2433         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
2434         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
2435
2436         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
2437         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
2438         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
2439         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
2440         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
2441         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
2442         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
2443         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
2444         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
2445         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
2446         SND_PCI_QUIRK(0x8086, 0, "Intel mobo", ALC880_3ST),
2447
2448         {}
2449 };
2450
2451 /*
2452  * ALC880 codec presets
2453  */
2454 static struct alc_config_preset alc880_presets[] = {
2455         [ALC880_3ST] = {
2456                 .mixers = { alc880_three_stack_mixer },
2457                 .init_verbs = { alc880_volume_init_verbs, alc880_pin_3stack_init_verbs },
2458                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2459                 .dac_nids = alc880_dac_nids,
2460                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
2461                 .channel_mode = alc880_threestack_modes,
2462                 .need_dac_fix = 1,
2463                 .input_mux = &alc880_capture_source,
2464         },
2465         [ALC880_3ST_DIG] = {
2466                 .mixers = { alc880_three_stack_mixer },
2467                 .init_verbs = { alc880_volume_init_verbs, alc880_pin_3stack_init_verbs },
2468                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2469                 .dac_nids = alc880_dac_nids,
2470                 .dig_out_nid = ALC880_DIGOUT_NID,
2471                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
2472                 .channel_mode = alc880_threestack_modes,
2473                 .need_dac_fix = 1,
2474                 .input_mux = &alc880_capture_source,
2475         },
2476         [ALC880_TCL_S700] = {
2477                 .mixers = { alc880_tcl_s700_mixer },
2478                 .init_verbs = { alc880_volume_init_verbs,
2479                                 alc880_pin_tcl_S700_init_verbs,
2480                                 alc880_gpio2_init_verbs },
2481                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2482                 .dac_nids = alc880_dac_nids,
2483                 .hp_nid = 0x03,
2484                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
2485                 .channel_mode = alc880_2_jack_modes,
2486                 .input_mux = &alc880_capture_source,
2487         },
2488         [ALC880_5ST] = {
2489                 .mixers = { alc880_three_stack_mixer, alc880_five_stack_mixer},
2490                 .init_verbs = { alc880_volume_init_verbs, alc880_pin_5stack_init_verbs },
2491                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2492                 .dac_nids = alc880_dac_nids,
2493                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
2494                 .channel_mode = alc880_fivestack_modes,
2495                 .input_mux = &alc880_capture_source,
2496         },
2497         [ALC880_5ST_DIG] = {
2498                 .mixers = { alc880_three_stack_mixer, alc880_five_stack_mixer },
2499                 .init_verbs = { alc880_volume_init_verbs, alc880_pin_5stack_init_verbs },
2500                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2501                 .dac_nids = alc880_dac_nids,
2502                 .dig_out_nid = ALC880_DIGOUT_NID,
2503                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
2504                 .channel_mode = alc880_fivestack_modes,
2505                 .input_mux = &alc880_capture_source,
2506         },
2507         [ALC880_6ST] = {
2508                 .mixers = { alc880_six_stack_mixer },
2509                 .init_verbs = { alc880_volume_init_verbs, alc880_pin_6stack_init_verbs },
2510                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
2511                 .dac_nids = alc880_6st_dac_nids,
2512                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
2513                 .channel_mode = alc880_sixstack_modes,
2514                 .input_mux = &alc880_6stack_capture_source,
2515         },
2516         [ALC880_6ST_DIG] = {
2517                 .mixers = { alc880_six_stack_mixer },
2518                 .init_verbs = { alc880_volume_init_verbs, alc880_pin_6stack_init_verbs },
2519                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
2520                 .dac_nids = alc880_6st_dac_nids,
2521                 .dig_out_nid = ALC880_DIGOUT_NID,
2522                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
2523                 .channel_mode = alc880_sixstack_modes,
2524                 .input_mux = &alc880_6stack_capture_source,
2525         },
2526         [ALC880_W810] = {
2527                 .mixers = { alc880_w810_base_mixer },
2528                 .init_verbs = { alc880_volume_init_verbs, alc880_pin_w810_init_verbs,
2529                                 alc880_gpio2_init_verbs },
2530                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
2531                 .dac_nids = alc880_w810_dac_nids,
2532                 .dig_out_nid = ALC880_DIGOUT_NID,
2533                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
2534                 .channel_mode = alc880_w810_modes,
2535                 .input_mux = &alc880_capture_source,
2536         },
2537         [ALC880_Z71V] = {
2538                 .mixers = { alc880_z71v_mixer },
2539                 .init_verbs = { alc880_volume_init_verbs, alc880_pin_z71v_init_verbs },
2540                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
2541                 .dac_nids = alc880_z71v_dac_nids,
2542                 .dig_out_nid = ALC880_DIGOUT_NID,
2543                 .hp_nid = 0x03,
2544                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
2545                 .channel_mode = alc880_2_jack_modes,
2546                 .input_mux = &alc880_capture_source,
2547         },
2548         [ALC880_F1734] = {
2549                 .mixers = { alc880_f1734_mixer },
2550                 .init_verbs = { alc880_volume_init_verbs, alc880_pin_f1734_init_verbs },
2551                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
2552                 .dac_nids = alc880_f1734_dac_nids,
2553                 .hp_nid = 0x02,
2554                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
2555                 .channel_mode = alc880_2_jack_modes,
2556                 .input_mux = &alc880_capture_source,
2557         },
2558         [ALC880_ASUS] = {
2559                 .mixers = { alc880_asus_mixer },
2560                 .init_verbs = { alc880_volume_init_verbs, alc880_pin_asus_init_verbs,
2561                                 alc880_gpio1_init_verbs },
2562                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2563                 .dac_nids = alc880_asus_dac_nids,
2564                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
2565                 .channel_mode = alc880_asus_modes,
2566                 .need_dac_fix = 1,
2567                 .input_mux = &alc880_capture_source,
2568         },
2569         [ALC880_ASUS_DIG] = {
2570                 .mixers = { alc880_asus_mixer },
2571                 .init_verbs = { alc880_volume_init_verbs, alc880_pin_asus_init_verbs,
2572                                 alc880_gpio1_init_verbs },
2573                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2574                 .dac_nids = alc880_asus_dac_nids,
2575                 .dig_out_nid = ALC880_DIGOUT_NID,
2576                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
2577                 .channel_mode = alc880_asus_modes,
2578                 .need_dac_fix = 1,
2579                 .input_mux = &alc880_capture_source,
2580         },
2581         [ALC880_ASUS_DIG2] = {
2582                 .mixers = { alc880_asus_mixer },
2583                 .init_verbs = { alc880_volume_init_verbs, alc880_pin_asus_init_verbs,
2584                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
2585                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2586                 .dac_nids = alc880_asus_dac_nids,
2587                 .dig_out_nid = ALC880_DIGOUT_NID,
2588                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
2589                 .channel_mode = alc880_asus_modes,
2590                 .need_dac_fix = 1,
2591                 .input_mux = &alc880_capture_source,
2592         },
2593         [ALC880_ASUS_W1V] = {
2594                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
2595                 .init_verbs = { alc880_volume_init_verbs, alc880_pin_asus_init_verbs,
2596                                 alc880_gpio1_init_verbs },
2597                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2598                 .dac_nids = alc880_asus_dac_nids,
2599                 .dig_out_nid = ALC880_DIGOUT_NID,
2600                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
2601                 .channel_mode = alc880_asus_modes,
2602                 .need_dac_fix = 1,
2603                 .input_mux = &alc880_capture_source,
2604         },
2605         [ALC880_UNIWILL_DIG] = {
2606                 .mixers = { alc880_asus_mixer, alc880_pcbeep_mixer },
2607                 .init_verbs = { alc880_volume_init_verbs,
2608                                 alc880_pin_asus_init_verbs },
2609                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2610                 .dac_nids = alc880_asus_dac_nids,
2611                 .dig_out_nid = ALC880_DIGOUT_NID,
2612                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
2613                 .channel_mode = alc880_asus_modes,
2614                 .need_dac_fix = 1,
2615                 .input_mux = &alc880_capture_source,
2616         },
2617         [ALC880_UNIWILL] = {
2618                 .mixers = { alc880_uniwill_mixer },
2619                 .init_verbs = { alc880_volume_init_verbs,
2620                                 alc880_uniwill_init_verbs },
2621                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2622                 .dac_nids = alc880_asus_dac_nids,
2623                 .dig_out_nid = ALC880_DIGOUT_NID,
2624                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
2625                 .channel_mode = alc880_threestack_modes,
2626                 .need_dac_fix = 1,
2627                 .input_mux = &alc880_capture_source,
2628                 .unsol_event = alc880_uniwill_unsol_event,
2629                 .init_hook = alc880_uniwill_automute,
2630         },
2631         [ALC880_UNIWILL_P53] = {
2632                 .mixers = { alc880_uniwill_p53_mixer },
2633                 .init_verbs = { alc880_volume_init_verbs,
2634                                 alc880_uniwill_p53_init_verbs },
2635                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2636                 .dac_nids = alc880_asus_dac_nids,
2637                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
2638                 .channel_mode = alc880_w810_modes,
2639                 .input_mux = &alc880_capture_source,
2640                 .unsol_event = alc880_uniwill_p53_unsol_event,
2641                 .init_hook = alc880_uniwill_p53_hp_automute,
2642         },
2643         [ALC880_CLEVO] = {
2644                 .mixers = { alc880_three_stack_mixer },
2645                 .init_verbs = { alc880_volume_init_verbs,
2646                                 alc880_pin_clevo_init_verbs },
2647                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2648                 .dac_nids = alc880_dac_nids,
2649                 .hp_nid = 0x03,
2650                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
2651                 .channel_mode = alc880_threestack_modes,
2652                 .need_dac_fix = 1,
2653                 .input_mux = &alc880_capture_source,
2654         },
2655         [ALC880_LG] = {
2656                 .mixers = { alc880_lg_mixer },
2657                 .init_verbs = { alc880_volume_init_verbs,
2658                                 alc880_lg_init_verbs },
2659                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
2660                 .dac_nids = alc880_lg_dac_nids,
2661                 .dig_out_nid = ALC880_DIGOUT_NID,
2662                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
2663                 .channel_mode = alc880_lg_ch_modes,
2664                 .need_dac_fix = 1,
2665                 .input_mux = &alc880_lg_capture_source,
2666                 .unsol_event = alc880_lg_unsol_event,
2667                 .init_hook = alc880_lg_automute,
2668         },
2669         [ALC880_LG_LW] = {
2670                 .mixers = { alc880_lg_lw_mixer },
2671                 .init_verbs = { alc880_volume_init_verbs,
2672                                 alc880_lg_lw_init_verbs },
2673                 .num_dacs = 1, 
2674                 .dac_nids = alc880_dac_nids,
2675                 .dig_out_nid = ALC880_DIGOUT_NID,
2676                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
2677                 .channel_mode = alc880_2_jack_modes,
2678                 .input_mux = &alc880_lg_lw_capture_source,
2679                 .unsol_event = alc880_lg_lw_unsol_event,
2680                 .init_hook = alc880_lg_lw_automute,
2681         },
2682 #ifdef CONFIG_SND_DEBUG
2683         [ALC880_TEST] = {
2684                 .mixers = { alc880_test_mixer },
2685                 .init_verbs = { alc880_test_init_verbs },
2686                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
2687                 .dac_nids = alc880_test_dac_nids,
2688                 .dig_out_nid = ALC880_DIGOUT_NID,
2689                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
2690                 .channel_mode = alc880_test_modes,
2691                 .input_mux = &alc880_test_capture_source,
2692         },
2693 #endif
2694 };
2695
2696 /*
2697  * Automatic parse of I/O pins from the BIOS configuration
2698  */
2699
2700 #define NUM_CONTROL_ALLOC       32
2701 #define NUM_VERB_ALLOC          32
2702
2703 enum {
2704         ALC_CTL_WIDGET_VOL,
2705         ALC_CTL_WIDGET_MUTE,
2706         ALC_CTL_BIND_MUTE,
2707 };
2708 static struct snd_kcontrol_new alc880_control_templates[] = {
2709         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2710         HDA_CODEC_MUTE(NULL, 0, 0, 0),
2711         HDA_BIND_MUTE(NULL, 0, 0, 0),
2712 };
2713
2714 /* add dynamic controls */
2715 static int add_control(struct alc_spec *spec, int type, const char *name, unsigned long val)
2716 {
2717         struct snd_kcontrol_new *knew;
2718
2719         if (spec->num_kctl_used >= spec->num_kctl_alloc) {
2720                 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
2721
2722                 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
2723                 if (! knew)
2724                         return -ENOMEM;
2725                 if (spec->kctl_alloc) {
2726                         memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
2727                         kfree(spec->kctl_alloc);
2728                 }
2729                 spec->kctl_alloc = knew;
2730                 spec->num_kctl_alloc = num;
2731         }
2732
2733         knew = &spec->kctl_alloc[spec->num_kctl_used];
2734         *knew = alc880_control_templates[type];
2735         knew->name = kstrdup(name, GFP_KERNEL);
2736         if (! knew->name)
2737                 return -ENOMEM;
2738         knew->private_value = val;
2739         spec->num_kctl_used++;
2740         return 0;
2741 }
2742
2743 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
2744 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
2745 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
2746 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
2747 #define alc880_is_input_pin(nid)        ((nid) >= 0x18)
2748 #define alc880_input_pin_idx(nid)       ((nid) - 0x18)
2749 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
2750 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
2751 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
2752 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
2753 #define ALC880_PIN_CD_NID               0x1c
2754
2755 /* fill in the dac_nids table from the parsed pin configuration */
2756 static int alc880_auto_fill_dac_nids(struct alc_spec *spec, const struct auto_pin_cfg *cfg)
2757 {
2758         hda_nid_t nid;
2759         int assigned[4];
2760         int i, j;
2761
2762         memset(assigned, 0, sizeof(assigned));
2763         spec->multiout.dac_nids = spec->private_dac_nids;
2764
2765         /* check the pins hardwired to audio widget */
2766         for (i = 0; i < cfg->line_outs; i++) {
2767                 nid = cfg->line_out_pins[i];
2768                 if (alc880_is_fixed_pin(nid)) {
2769                         int idx = alc880_fixed_pin_idx(nid);
2770                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
2771                         assigned[idx] = 1;
2772                 }
2773         }
2774         /* left pins can be connect to any audio widget */
2775         for (i = 0; i < cfg->line_outs; i++) {
2776                 nid = cfg->line_out_pins[i];
2777                 if (alc880_is_fixed_pin(nid))
2778                         continue;
2779                 /* search for an empty channel */
2780                 for (j = 0; j < cfg->line_outs; j++) {
2781                         if (! assigned[j]) {
2782                                 spec->multiout.dac_nids[i] = alc880_idx_to_dac(j);
2783                                 assigned[j] = 1;
2784                                 break;
2785                         }
2786                 }
2787         }
2788         spec->multiout.num_dacs = cfg->line_outs;
2789         return 0;
2790 }
2791
2792 /* add playback controls from the parsed DAC table */
2793 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
2794                                              const struct auto_pin_cfg *cfg)
2795 {
2796         char name[32];
2797         static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
2798         hda_nid_t nid;
2799         int i, err;
2800
2801         for (i = 0; i < cfg->line_outs; i++) {
2802                 if (! spec->multiout.dac_nids[i])
2803                         continue;
2804                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
2805                 if (i == 2) {
2806                         /* Center/LFE */
2807                         if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, "Center Playback Volume",
2808                                                HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
2809                                 return err;
2810                         if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, "LFE Playback Volume",
2811                                                HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
2812                                 return err;
2813                         if ((err = add_control(spec, ALC_CTL_BIND_MUTE, "Center Playback Switch",
2814                                                HDA_COMPOSE_AMP_VAL(nid, 1, 2, HDA_INPUT))) < 0)
2815                                 return err;
2816                         if ((err = add_control(spec, ALC_CTL_BIND_MUTE, "LFE Playback Switch",
2817                                                HDA_COMPOSE_AMP_VAL(nid, 2, 2, HDA_INPUT))) < 0)
2818                                 return err;
2819                 } else {
2820                         sprintf(name, "%s Playback Volume", chname[i]);
2821                         if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
2822                                                HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
2823                                 return err;
2824                         sprintf(name, "%s Playback Switch", chname[i]);
2825                         if ((err = add_control(spec, ALC_CTL_BIND_MUTE, name,
2826                                                HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
2827                                 return err;
2828                 }
2829         }
2830         return 0;
2831 }
2832
2833 /* add playback controls for speaker and HP outputs */
2834 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
2835                                         const char *pfx)
2836 {
2837         hda_nid_t nid;
2838         int err;
2839         char name[32];
2840
2841         if (! pin)
2842                 return 0;
2843
2844         if (alc880_is_fixed_pin(pin)) {
2845                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
2846                 /* specify the DAC as the extra output */
2847                 if (! spec->multiout.hp_nid)
2848                         spec->multiout.hp_nid = nid;
2849                 else
2850                         spec->multiout.extra_out_nid[0] = nid;
2851                 /* control HP volume/switch on the output mixer amp */
2852                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
2853                 sprintf(name, "%s Playback Volume", pfx);
2854                 if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
2855                                        HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
2856                         return err;
2857                 sprintf(name, "%s Playback Switch", pfx);
2858                 if ((err = add_control(spec, ALC_CTL_BIND_MUTE, name,
2859                                        HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
2860                         return err;
2861         } else if (alc880_is_multi_pin(pin)) {
2862                 /* set manual connection */
2863                 /* we have only a switch on HP-out PIN */
2864                 sprintf(name, "%s Playback Switch", pfx);
2865                 if ((err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
2866                                        HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT))) < 0)
2867                         return err;
2868         }
2869         return 0;
2870 }
2871
2872 /* create input playback/capture controls for the given pin */
2873 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin, const char *ctlname,
2874                             int idx, hda_nid_t mix_nid)
2875 {
2876         char name[32];
2877         int err;
2878
2879         sprintf(name, "%s Playback Volume", ctlname);
2880         if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
2881                                HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT))) < 0)
2882                 return err;
2883         sprintf(name, "%s Playback Switch", ctlname);
2884         if ((err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
2885                                HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT))) < 0)
2886                 return err;
2887         return 0;
2888 }
2889
2890 /* create playback/capture controls for input pins */
2891 static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
2892                                                 const struct auto_pin_cfg *cfg)
2893 {
2894         struct hda_input_mux *imux = &spec->private_imux;
2895         int i, err, idx;
2896
2897         for (i = 0; i < AUTO_PIN_LAST; i++) {
2898                 if (alc880_is_input_pin(cfg->input_pins[i])) {
2899                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
2900                         err = new_analog_input(spec, cfg->input_pins[i],
2901                                                auto_pin_cfg_labels[i],
2902                                                idx, 0x0b);
2903                         if (err < 0)
2904                                 return err;
2905                         imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
2906                         imux->items[imux->num_items].index = alc880_input_pin_idx(cfg->input_pins[i]);
2907                         imux->num_items++;
2908                 }
2909         }
2910         return 0;
2911 }
2912
2913 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
2914                                               hda_nid_t nid, int pin_type,
2915                                               int dac_idx)
2916 {
2917         /* set as output */
2918         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2919         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
2920         /* need the manual connection? */
2921         if (alc880_is_multi_pin(nid)) {
2922                 struct alc_spec *spec = codec->spec;
2923                 int idx = alc880_multi_pin_idx(nid);
2924                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
2925                                     AC_VERB_SET_CONNECT_SEL,
2926                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
2927         }
2928 }
2929
2930 static void alc880_auto_init_multi_out(struct hda_codec *codec)
2931 {
2932         struct alc_spec *spec = codec->spec;
2933         int i;
2934
2935         for (i = 0; i < spec->autocfg.line_outs; i++) {
2936                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
2937                 alc880_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
2938         }
2939 }
2940
2941 static void alc880_auto_init_extra_out(struct hda_codec *codec)
2942 {
2943         struct alc_spec *spec = codec->spec;
2944         hda_nid_t pin;
2945
2946         pin = spec->autocfg.speaker_pins[0];
2947         if (pin) /* connect to front */
2948                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
2949         pin = spec->autocfg.hp_pins[0];
2950         if (pin) /* connect to front */
2951                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
2952 }
2953
2954 static void alc880_auto_init_analog_input(struct hda_codec *codec)
2955 {
2956         struct alc_spec *spec = codec->spec;
2957         int i;
2958
2959         for (i = 0; i < AUTO_PIN_LAST; i++) {
2960                 hda_nid_t nid = spec->autocfg.input_pins[i];
2961                 if (alc880_is_input_pin(nid)) {
2962                         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2963                                             i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
2964                         if (nid != ALC880_PIN_CD_NID)
2965                                 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2966                                                     AMP_OUT_MUTE);
2967                 }
2968         }
2969 }
2970
2971 /* parse the BIOS configuration and set up the alc_spec */
2972 /* return 1 if successful, 0 if the proper config is not found, or a negative error code */
2973 static int alc880_parse_auto_config(struct hda_codec *codec)
2974 {
2975         struct alc_spec *spec = codec->spec;
2976         int err;
2977         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
2978
2979         if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
2980                                                 alc880_ignore)) < 0)
2981                 return err;
2982         if (! spec->autocfg.line_outs)
2983                 return 0; /* can't find valid BIOS pin config */
2984
2985         if ((err = alc880_auto_fill_dac_nids(spec, &spec->autocfg)) < 0 ||
2986             (err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
2987             (err = alc880_auto_create_extra_out(spec,
2988                                                 spec->autocfg.speaker_pins[0],
2989                                                 "Speaker")) < 0 ||
2990             (err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
2991                                                 "Headphone")) < 0 ||
2992             (err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
2993                 return err;
2994
2995         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2996
2997         if (spec->autocfg.dig_out_pin)
2998                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
2999         if (spec->autocfg.dig_in_pin)
3000                 spec->dig_in_nid = ALC880_DIGIN_NID;
3001
3002         if (spec->kctl_alloc)
3003                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
3004
3005         spec->init_verbs[spec->num_init_verbs++] = alc880_volume_init_verbs;
3006
3007         spec->num_mux_defs = 1;
3008         spec->input_mux = &spec->private_imux;
3009
3010         return 1;
3011 }
3012
3013 /* additional initialization for auto-configuration model */
3014 static void alc880_auto_init(struct hda_codec *codec)
3015 {
3016         alc880_auto_init_multi_out(codec);
3017         alc880_auto_init_extra_out(codec);
3018         alc880_auto_init_analog_input(codec);
3019 }
3020
3021 /*
3022  * OK, here we have finally the patch for ALC880
3023  */
3024
3025 static int patch_alc880(struct hda_codec *codec)
3026 {
3027         struct alc_spec *spec;
3028         int board_config;
3029         int err;
3030
3031         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3032         if (spec == NULL)
3033                 return -ENOMEM;
3034
3035         codec->spec = spec;
3036
3037         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
3038                                                   alc880_models,
3039                                                   alc880_cfg_tbl);
3040         if (board_config < 0) {
3041                 printk(KERN_INFO "hda_codec: Unknown model for ALC880, "
3042                        "trying auto-probe from BIOS...\n");
3043                 board_config = ALC880_AUTO;
3044         }
3045
3046         if (board_config == ALC880_AUTO) {
3047                 /* automatic parse from the BIOS config */
3048                 err = alc880_parse_auto_config(codec);
3049                 if (err < 0) {
3050                         alc_free(codec);
3051                         return err;
3052                 } else if (! err) {
3053                         printk(KERN_INFO
3054                                "hda_codec: Cannot set up configuration "
3055                                "from BIOS.  Using 3-stack mode...\n");
3056                         board_config = ALC880_3ST;
3057                 }
3058         }
3059
3060         if (board_config != ALC880_AUTO)
3061                 setup_preset(spec, &alc880_presets[board_config]);
3062
3063         spec->stream_name_analog = "ALC880 Analog";
3064         spec->stream_analog_playback = &alc880_pcm_analog_playback;
3065         spec->stream_analog_capture = &alc880_pcm_analog_capture;
3066
3067         spec->stream_name_digital = "ALC880 Digital";
3068         spec->stream_digital_playback = &alc880_pcm_digital_playback;
3069         spec->stream_digital_capture = &alc880_pcm_digital_capture;
3070
3071         if (! spec->adc_nids && spec->input_mux) {
3072                 /* check whether NID 0x07 is valid */
3073                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
3074                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */
3075                 if (wcap != AC_WID_AUD_IN) {
3076                         spec->adc_nids = alc880_adc_nids_alt;
3077                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
3078                         spec->mixers[spec->num_mixers] = alc880_capture_alt_mixer;
3079                         spec->num_mixers++;
3080                 } else {
3081                         spec->adc_nids = alc880_adc_nids;
3082                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
3083                         spec->mixers[spec->num_mixers] = alc880_capture_mixer;
3084                         spec->num_mixers++;
3085                 }
3086         }
3087
3088         codec->patch_ops = alc_patch_ops;
3089         if (board_config == ALC880_AUTO)
3090                 spec->init_hook = alc880_auto_init;
3091
3092         return 0;
3093 }
3094
3095
3096 /*
3097  * ALC260 support
3098  */
3099
3100 static hda_nid_t alc260_dac_nids[1] = {
3101         /* front */
3102         0x02,
3103 };
3104
3105 static hda_nid_t alc260_adc_nids[1] = {
3106         /* ADC0 */
3107         0x04,
3108 };
3109
3110 static hda_nid_t alc260_adc_nids_alt[1] = {
3111         /* ADC1 */
3112         0x05,
3113 };
3114
3115 static hda_nid_t alc260_hp_adc_nids[2] = {
3116         /* ADC1, 0 */
3117         0x05, 0x04
3118 };
3119
3120 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
3121  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
3122  */
3123 static hda_nid_t alc260_dual_adc_nids[2] = {
3124         /* ADC0, ADC1 */
3125         0x04, 0x05
3126 };
3127
3128 #define ALC260_DIGOUT_NID       0x03
3129 #define ALC260_DIGIN_NID        0x06
3130
3131 static struct hda_input_mux alc260_capture_source = {
3132         .num_items = 4,
3133         .items = {
3134                 { "Mic", 0x0 },
3135                 { "Front Mic", 0x1 },
3136                 { "Line", 0x2 },
3137                 { "CD", 0x4 },
3138         },
3139 };
3140
3141 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
3142  * headphone jack and the internal CD lines since these are the only pins at
3143  * which audio can appear.  For flexibility, also allow the option of
3144  * recording the mixer output on the second ADC (ADC0 doesn't have a
3145  * connection to the mixer output).
3146  */
3147 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
3148         {
3149                 .num_items = 3,
3150                 .items = {
3151                         { "Mic/Line", 0x0 },
3152                         { "CD", 0x4 },
3153                         { "Headphone", 0x2 },
3154                 },
3155         },
3156         {
3157                 .num_items = 4,
3158                 .items = {
3159                         { "Mic/Line", 0x0 },
3160                         { "CD", 0x4 },
3161                         { "Headphone", 0x2 },
3162                         { "Mixer", 0x5 },
3163                 },
3164         },
3165
3166 };
3167
3168 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
3169  * the Fujitsu S702x, but jacks are marked differently.
3170  */
3171 static struct hda_input_mux alc260_acer_capture_sources[2] = {
3172         {
3173                 .num_items = 4,
3174                 .items = {
3175                         { "Mic", 0x0 },
3176                         { "Line", 0x2 },
3177                         { "CD", 0x4 },
3178                         { "Headphone", 0x5 },
3179                 },
3180         },
3181         {
3182                 .num_items = 5,
3183                 .items = {
3184                         { "Mic", 0x0 },
3185                         { "Line", 0x2 },
3186                         { "CD", 0x4 },
3187                         { "Headphone", 0x6 },
3188                         { "Mixer", 0x5 },
3189                 },
3190         },
3191 };
3192 /*
3193  * This is just place-holder, so there's something for alc_build_pcms to look
3194  * at when it calculates the maximum number of channels. ALC260 has no mixer
3195  * element which allows changing the channel mode, so the verb list is
3196  * never used.
3197  */
3198 static struct hda_channel_mode alc260_modes[1] = {
3199         { 2, NULL },
3200 };
3201
3202
3203 /* Mixer combinations
3204  *
3205  * basic: base_output + input + pc_beep + capture
3206  * HP: base_output + input + capture_alt
3207  * HP_3013: hp_3013 + input + capture
3208  * fujitsu: fujitsu + capture
3209  * acer: acer + capture
3210  */
3211
3212 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
3213         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3214         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
3215         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
3216         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
3217         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
3218         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
3219         { } /* end */
3220 };      
3221
3222 static struct snd_kcontrol_new alc260_input_mixer[] = {
3223         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3224         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3225         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
3226         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
3227         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
3228         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
3229         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
3230         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
3231         { } /* end */
3232 };
3233
3234 static struct snd_kcontrol_new alc260_pc_beep_mixer[] = {
3235         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT),
3236         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT),
3237         { } /* end */
3238 };
3239
3240 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
3241         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
3242         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
3243         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
3244         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
3245         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3246         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
3247         HDA_CODEC_VOLUME_MONO("iSpeaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
3248         HDA_CODEC_MUTE_MONO("iSpeaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
3249         { } /* end */
3250 };
3251
3252 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12, 
3253  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
3254  */
3255 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
3256         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3257         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
3258         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
3259         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3260         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3261         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
3262         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
3263         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
3264         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
3265         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
3266         HDA_CODEC_VOLUME("Internal Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
3267         HDA_BIND_MUTE("Internal Speaker Playback Switch", 0x09, 2, HDA_INPUT),
3268         { } /* end */
3269 };
3270
3271 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
3272  * versions of the ALC260 don't act on requests to enable mic bias from NID
3273  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
3274  * datasheet doesn't mention this restriction.  At this stage it's not clear
3275  * whether this behaviour is intentional or is a hardware bug in chip
3276  * revisions available in early 2006.  Therefore for now allow the
3277  * "Headphone Jack Mode" control to span all choices, but if it turns out
3278  * that the lack of mic bias for this NID is intentional we could change the
3279  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
3280  *
3281  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
3282  * don't appear to make the mic bias available from the "line" jack, even
3283  * though the NID used for this jack (0x14) can supply it.  The theory is
3284  * that perhaps Acer have included blocking capacitors between the ALC260
3285  * and the output jack.  If this turns out to be the case for all such
3286  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
3287  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
3288  *
3289  * The C20x Tablet series have a mono internal speaker which is controlled
3290  * via the chip's Mono sum widget and pin complex, so include the necessary
3291  * controls for such models.  On models without a "mono speaker" the control
3292  * won't do anything.
3293  */
3294 static struct snd_kcontrol_new alc260_acer_mixer[] = {
3295         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3296         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
3297         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
3298         HDA_CODEC_VOLUME_MONO("Mono Speaker Playback Volume", 0x0a, 1, 0x0,
3299                               HDA_OUTPUT),
3300         HDA_BIND_MUTE_MONO("Mono Speaker Playback Switch", 0x0a, 1, 2,
3301                            HDA_INPUT),
3302         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3303         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3304         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
3305         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
3306         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
3307         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
3308         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
3309         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
3310         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
3311         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
3312         { } /* end */
3313 };
3314
3315 /* capture mixer elements */
3316 static struct snd_kcontrol_new alc260_capture_mixer[] = {
3317         HDA_CODEC_VOLUME("Capture Volume", 0x04, 0x0, HDA_INPUT),
3318         HDA_CODEC_MUTE("Capture Switch", 0x04, 0x0, HDA_INPUT),
3319         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x05, 0x0, HDA_INPUT),
3320         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x05, 0x0, HDA_INPUT),
3321         {
3322                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3323                 /* The multiple "Capture Source" controls confuse alsamixer
3324                  * So call somewhat different..
3325                  * FIXME: the controls appear in the "playback" view!
3326                  */
3327                 /* .name = "Capture Source", */
3328                 .name = "Input Source",
3329                 .count = 2,
3330                 .info = alc_mux_enum_info,
3331                 .get = alc_mux_enum_get,
3332                 .put = alc_mux_enum_put,
3333         },
3334         { } /* end */
3335 };
3336
3337 static struct snd_kcontrol_new alc260_capture_alt_mixer[] = {
3338         HDA_CODEC_VOLUME("Capture Volume", 0x05, 0x0, HDA_INPUT),
3339         HDA_CODEC_MUTE("Capture Switch", 0x05, 0x0, HDA_INPUT),
3340         {
3341                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3342                 /* The multiple "Capture Source" controls confuse alsamixer
3343                  * So call somewhat different..
3344                  * FIXME: the controls appear in the "playback" view!
3345                  */
3346                 /* .name = "Capture Source", */
3347                 .name = "Input Source",
3348                 .count = 1,
3349                 .info = alc_mux_enum_info,
3350                 .get = alc_mux_enum_get,
3351                 .put = alc_mux_enum_put,
3352         },
3353         { } /* end */
3354 };
3355
3356 /*
3357  * initialization verbs
3358  */
3359 static struct hda_verb alc260_init_verbs[] = {
3360         /* Line In pin widget for input */
3361         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3362         /* CD pin widget for input */
3363         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3364         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3365         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3366         /* Mic2 (front panel) pin widget for input and vref at 80% */
3367         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3368         /* LINE-2 is used for line-out in rear */
3369         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3370         /* select line-out */
3371         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
3372         /* LINE-OUT pin */
3373         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3374         /* enable HP */
3375         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3376         /* enable Mono */
3377         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3378         /* mute capture amp left and right */
3379         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3380         /* set connection select to line in (default select for this ADC) */
3381         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
3382         /* mute capture amp left and right */
3383         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3384         /* set connection select to line in (default select for this ADC) */
3385         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
3386         /* set vol=0 Line-Out mixer amp left and right */
3387         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3388         /* unmute pin widget amp left and right (no gain on this amp) */
3389         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3390         /* set vol=0 HP mixer amp left and right */
3391         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3392         /* unmute pin widget amp left and right (no gain on this amp) */
3393         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3394         /* set vol=0 Mono mixer amp left and right */
3395         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3396         /* unmute pin widget amp left and right (no gain on this amp) */
3397         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3398         /* unmute LINE-2 out pin */
3399         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3400         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 & Line In 2 = 0x03 */
3401         /* mute CD */
3402         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3403         /* mute Line In */
3404         {0x07,  AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3405         /* mute Mic */
3406         {0x07,  AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3407         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
3408         /* mute Front out path */
3409         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3410         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3411         /* mute Headphone out path */
3412         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3413         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3414         /* mute Mono out path */
3415         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3416         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3417         { }
3418 };
3419
3420 #if 0 /* should be identical with alc260_init_verbs? */
3421 static struct hda_verb alc260_hp_init_verbs[] = {
3422         /* Headphone and output */
3423         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
3424         /* mono output */
3425         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3426         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3427         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
3428         /* Mic2 (front panel) pin widget for input and vref at 80% */
3429         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
3430         /* Line In pin widget for input */
3431         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3432         /* Line-2 pin widget for output */
3433         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3434         /* CD pin widget for input */
3435         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3436         /* unmute amp left and right */
3437         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
3438         /* set connection select to line in (default select for this ADC) */
3439         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
3440         /* unmute Line-Out mixer amp left and right (volume = 0) */
3441         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
3442         /* mute pin widget amp left and right (no gain on this amp) */
3443         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
3444         /* unmute HP mixer amp left and right (volume = 0) */
3445         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
3446         /* mute pin widget amp left and right (no gain on this amp) */
3447         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
3448         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 & Line In 2 = 0x03 */
3449         /* unmute CD */
3450         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
3451         /* unmute Line In */
3452         {0x07,  AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
3453         /* unmute Mic */
3454         {0x07,  AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3455         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
3456         /* Unmute Front out path */
3457         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3458         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3459         /* Unmute Headphone out path */
3460         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3461         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3462         /* Unmute Mono out path */
3463         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3464         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3465         { }
3466 };
3467 #endif
3468
3469 static struct hda_verb alc260_hp_3013_init_verbs[] = {
3470         /* Line out and output */
3471         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3472         /* mono output */
3473         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3474         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3475         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
3476         /* Mic2 (front panel) pin widget for input and vref at 80% */
3477         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
3478         /* Line In pin widget for input */
3479         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3480         /* Headphone pin widget for output */
3481         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
3482         /* CD pin widget for input */
3483         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3484         /* unmute amp left and right */
3485         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
3486         /* set connection select to line in (default select for this ADC) */
3487         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
3488         /* unmute Line-Out mixer amp left and right (volume = 0) */
3489         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
3490         /* mute pin widget amp left and right (no gain on this amp) */
3491         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
3492         /* unmute HP mixer amp left and right (volume = 0) */
3493         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
3494         /* mute pin widget amp left and right (no gain on this amp) */
3495         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
3496         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 & Line In 2 = 0x03 */
3497         /* unmute CD */
3498         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
3499         /* unmute Line In */
3500         {0x07,  AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
3501         /* unmute Mic */
3502         {0x07,  AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3503         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
3504         /* Unmute Front out path */
3505         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3506         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3507         /* Unmute Headphone out path */
3508         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3509         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3510         /* Unmute Mono out path */
3511         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3512         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3513         { }
3514 };
3515
3516 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
3517  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
3518  * audio = 0x16, internal speaker = 0x10.
3519  */
3520 static struct hda_verb alc260_fujitsu_init_verbs[] = {
3521         /* Disable all GPIOs */
3522         {0x01, AC_VERB_SET_GPIO_MASK, 0},
3523         /* Internal speaker is connected to headphone pin */
3524         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3525         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
3526         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3527         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
3528         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3529         /* Ensure all other unused pins are disabled and muted. */
3530         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3531         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3532         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3533         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3534         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3535         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3536         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3537         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3538
3539         /* Disable digital (SPDIF) pins */
3540         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
3541         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
3542
3543         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus 
3544          * when acting as an output.
3545          */
3546         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
3547
3548         /* Start with output sum widgets muted and their output gains at min */
3549         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3550         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3551         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3552         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3553         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3554         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3555         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3556         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3557         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3558
3559         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
3560         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3561         /* Unmute Line1 pin widget output buffer since it starts as an output.
3562          * If the pin mode is changed by the user the pin mode control will
3563          * take care of enabling the pin's input/output buffers as needed.
3564          * Therefore there's no need to enable the input buffer at this
3565          * stage.
3566          */
3567         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3568         /* Unmute input buffer of pin widget used for Line-in (no equiv 
3569          * mixer ctrl)
3570          */
3571         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3572
3573         /* Mute capture amp left and right */
3574         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3575         /* Set ADC connection select to match default mixer setting - line 
3576          * in (on mic1 pin)
3577          */
3578         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
3579
3580         /* Do the same for the second ADC: mute capture input amp and
3581          * set ADC connection to line in (on mic1 pin)
3582          */
3583         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3584         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
3585
3586         /* Mute all inputs to mixer widget (even unconnected ones) */
3587         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
3588         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
3589         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
3590         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
3591         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
3592         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
3593         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
3594         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
3595
3596         { }
3597 };
3598
3599 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
3600  * similar laptops (adapted from Fujitsu init verbs).
3601  */
3602 static struct hda_verb alc260_acer_init_verbs[] = {
3603         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
3604          * the headphone jack.  Turn this on and rely on the standard mute
3605          * methods whenever the user wants to turn these outputs off.
3606          */
3607         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
3608         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
3609         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
3610         /* Internal speaker/Headphone jack is connected to Line-out pin */
3611         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3612         /* Internal microphone/Mic jack is connected to Mic1 pin */
3613         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
3614         /* Line In jack is connected to Line1 pin */
3615         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3616         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
3617         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3618         /* Ensure all other unused pins are disabled and muted. */
3619         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3620         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3621         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3622         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3623         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3624         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3625         /* Disable digital (SPDIF) pins */
3626         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
3627         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
3628
3629         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum 
3630          * bus when acting as outputs.
3631          */
3632         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
3633         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
3634
3635         /* Start with output sum widgets muted and their output gains at min */
3636         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3637         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3638         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3639         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3640         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3641         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3642         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3643         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3644         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3645
3646         /* Unmute Line-out pin widget amp left and right (no equiv mixer ctrl) */
3647         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3648         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
3649         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3650         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
3651          * inputs. If the pin mode is changed by the user the pin mode control
3652          * will take care of enabling the pin's input/output buffers as needed.
3653          * Therefore there's no need to enable the input buffer at this
3654          * stage.
3655          */
3656         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3657         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3658
3659         /* Mute capture amp left and right */
3660         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3661         /* Set ADC connection select to match default mixer setting - mic
3662          * (on mic1 pin)
3663          */
3664         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
3665
3666         /* Do similar with the second ADC: mute capture input amp and
3667          * set ADC connection to mic to match ALSA's default state.
3668          */
3669         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3670         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
3671
3672         /* Mute all inputs to mixer widget (even unconnected ones) */
3673         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
3674         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
3675         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
3676         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
3677         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
3678         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
3679         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
3680         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
3681
3682         { }
3683 };
3684
3685 /* Test configuration for debugging, modelled after the ALC880 test
3686  * configuration.
3687  */
3688 #ifdef CONFIG_SND_DEBUG
3689 static hda_nid_t alc260_test_dac_nids[1] = {
3690         0x02,
3691 };
3692 static hda_nid_t alc260_test_adc_nids[2] = {
3693         0x04, 0x05,
3694 };
3695 /* For testing the ALC260, each input MUX needs its own definition since
3696  * the signal assignments are different.  This assumes that the first ADC 
3697  * is NID 0x04.
3698  */
3699 static struct hda_input_mux alc260_test_capture_sources[2] = {
3700         {
3701                 .num_items = 7,
3702                 .items = {
3703                         { "MIC1 pin", 0x0 },
3704                         { "MIC2 pin", 0x1 },
3705                         { "LINE1 pin", 0x2 },
3706                         { "LINE2 pin", 0x3 },
3707                         { "CD pin", 0x4 },
3708                         { "LINE-OUT pin", 0x5 },
3709                         { "HP-OUT pin", 0x6 },
3710                 },
3711         },
3712         {
3713                 .num_items = 8,
3714                 .items = {
3715                         { "MIC1 pin", 0x0 },
3716                         { "MIC2 pin", 0x1 },
3717                         { "LINE1 pin", 0x2 },
3718                         { "LINE2 pin", 0x3 },
3719                         { "CD pin", 0x4 },
3720                         { "Mixer", 0x5 },
3721                         { "LINE-OUT pin", 0x6 },
3722                         { "HP-OUT pin", 0x7 },
3723                 },
3724         },
3725 };
3726 static struct snd_kcontrol_new alc260_test_mixer[] = {
3727         /* Output driver widgets */
3728         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
3729         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
3730         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
3731         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
3732         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3733         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
3734
3735         /* Modes for retasking pin widgets
3736          * Note: the ALC260 doesn't seem to act on requests to enable mic
3737          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
3738          * mention this restriction.  At this stage it's not clear whether
3739          * this behaviour is intentional or is a hardware bug in chip
3740          * revisions available at least up until early 2006.  Therefore for
3741          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
3742          * choices, but if it turns out that the lack of mic bias for these
3743          * NIDs is intentional we could change their modes from
3744          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
3745          */
3746         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
3747         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
3748         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
3749         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
3750         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
3751         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
3752
3753         /* Loopback mixer controls */
3754         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
3755         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
3756         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
3757         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
3758         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
3759         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
3760         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
3761         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
3762         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3763         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3764         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
3765         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
3766         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
3767         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
3768         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
3769         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
3770
3771         /* Controls for GPIO pins, assuming they are configured as outputs */
3772         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
3773         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
3774         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
3775         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
3776
3777         /* Switches to allow the digital IO pins to be enabled.  The datasheet
3778          * is ambigious as to which NID is which; testing on laptops which
3779          * make this output available should provide clarification. 
3780          */
3781         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
3782         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
3783
3784         { } /* end */
3785 };
3786 static struct hda_verb alc260_test_init_verbs[] = {
3787         /* Enable all GPIOs as outputs with an initial value of 0 */
3788         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
3789         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
3790         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
3791
3792         /* Enable retasking pins as output, initially without power amp */
3793         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3794         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3795         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3796         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3797         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3798         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3799
3800         /* Disable digital (SPDIF) pins initially, but users can enable
3801          * them via a mixer switch.  In the case of SPDIF-out, this initverb
3802          * payload also sets the generation to 0, output to be in "consumer"
3803          * PCM format, copyright asserted, no pre-emphasis and no validity
3804          * control.
3805          */
3806         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
3807         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
3808
3809         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the 
3810          * OUT1 sum bus when acting as an output.
3811          */
3812         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
3813         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
3814         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
3815         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
3816
3817         /* Start with output sum widgets muted and their output gains at min */
3818         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3819         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3820         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3821         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3822         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3823         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3824         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3825         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3826         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3827
3828         /* Unmute retasking pin widget output buffers since the default
3829          * state appears to be output.  As the pin mode is changed by the
3830          * user the pin mode control will take care of enabling the pin's
3831          * input/output buffers as needed.
3832          */
3833         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3834         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3835         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3836         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3837         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3838         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3839         /* Also unmute the mono-out pin widget */
3840         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3841
3842         /* Mute capture amp left and right */
3843         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3844         /* Set ADC connection select to match default mixer setting (mic1
3845          * pin)
3846          */
3847         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
3848
3849         /* Do the same for the second ADC: mute capture input amp and
3850          * set ADC connection to mic1 pin
3851          */
3852         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3853         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
3854
3855         /* Mute all inputs to mixer widget (even unconnected ones) */
3856         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
3857         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
3858         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
3859         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
3860         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
3861         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
3862         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
3863         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
3864
3865         { }
3866 };
3867 #endif
3868
3869 static struct hda_pcm_stream alc260_pcm_analog_playback = {
3870         .substreams = 1,
3871         .channels_min = 2,
3872         .channels_max = 2,
3873 };
3874
3875 static struct hda_pcm_stream alc260_pcm_analog_capture = {
3876         .substreams = 1,
3877         .channels_min = 2,
3878         .channels_max = 2,
3879 };
3880
3881 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
3882 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
3883
3884 /*
3885  * for BIOS auto-configuration
3886  */
3887
3888 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
3889                                         const char *pfx)
3890 {
3891         hda_nid_t nid_vol;
3892         unsigned long vol_val, sw_val;
3893         char name[32];
3894         int err;
3895
3896         if (nid >= 0x0f && nid < 0x11) {
3897                 nid_vol = nid - 0x7;
3898                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
3899                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3900         } else if (nid == 0x11) {
3901                 nid_vol = nid - 0x7;
3902                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
3903                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
3904         } else if (nid >= 0x12 && nid <= 0x15) {
3905                 nid_vol = 0x08;
3906                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
3907                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3908         } else
3909                 return 0; /* N/A */
3910         
3911         snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3912         if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val)) < 0)
3913                 return err;
3914         snprintf(name, sizeof(name), "%s Playback Switch", pfx);
3915         if ((err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val)) < 0)
3916                 return err;
3917         return 1;
3918 }
3919
3920 /* add playback controls from the parsed DAC table */
3921 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
3922                                              const struct auto_pin_cfg *cfg)
3923 {
3924         hda_nid_t nid;
3925         int err;
3926
3927         spec->multiout.num_dacs = 1;
3928         spec->multiout.dac_nids = spec->private_dac_nids;
3929         spec->multiout.dac_nids[0] = 0x02;
3930
3931         nid = cfg->line_out_pins[0];
3932         if (nid) {
3933                 err = alc260_add_playback_controls(spec, nid, "Front");
3934                 if (err < 0)
3935                         return err;
3936         }
3937
3938         nid = cfg->speaker_pins[0];
3939         if (nid) {
3940                 err = alc260_add_playback_controls(spec, nid, "Speaker");
3941                 if (err < 0)
3942                         return err;
3943         }
3944
3945         nid = cfg->hp_pins[0];
3946         if (nid) {
3947                 err = alc260_add_playback_controls(spec, nid, "Headphone");
3948                 if (err < 0)
3949                         return err;
3950         }
3951         return 0;       
3952 }
3953
3954 /* create playback/capture controls for input pins */
3955 static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec,
3956                                                 const struct auto_pin_cfg *cfg)
3957 {
3958         struct hda_input_mux *imux = &spec->private_imux;
3959         int i, err, idx;
3960
3961         for (i = 0; i < AUTO_PIN_LAST; i++) {
3962                 if (cfg->input_pins[i] >= 0x12) {
3963                         idx = cfg->input_pins[i] - 0x12;
3964                         err = new_analog_input(spec, cfg->input_pins[i],
3965                                                auto_pin_cfg_labels[i], idx, 0x07);
3966                         if (err < 0)
3967                                 return err;
3968                         imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
3969                         imux->items[imux->num_items].index = idx;
3970                         imux->num_items++;
3971                 }
3972                 if ((cfg->input_pins[i] >= 0x0f) && (cfg->input_pins[i] <= 0x10)){
3973                         idx = cfg->input_pins[i] - 0x09;
3974                         err = new_analog_input(spec, cfg->input_pins[i],
3975                                                auto_pin_cfg_labels[i], idx, 0x07);
3976                         if (err < 0)
3977                                 return err;
3978                         imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
3979                         imux->items[imux->num_items].index = idx;
3980                         imux->num_items++;
3981                 }
3982         }
3983         return 0;
3984 }
3985
3986 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
3987                                               hda_nid_t nid, int pin_type,
3988                                               int sel_idx)
3989 {
3990         /* set as output */
3991         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
3992         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
3993         /* need the manual connection? */
3994         if (nid >= 0x12) {
3995                 int idx = nid - 0x12;
3996                 snd_hda_codec_write(codec, idx + 0x0b, 0,
3997                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
3998                                     
3999         }
4000 }
4001
4002 static void alc260_auto_init_multi_out(struct hda_codec *codec)
4003 {
4004         struct alc_spec *spec = codec->spec;
4005         hda_nid_t nid;
4006
4007         nid = spec->autocfg.line_out_pins[0];   
4008         if (nid)
4009                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
4010         
4011         nid = spec->autocfg.speaker_pins[0];
4012         if (nid)
4013                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
4014
4015         nid = spec->autocfg.hp_pins[0];
4016         if (nid)
4017                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
4018 }       
4019
4020 #define ALC260_PIN_CD_NID               0x16
4021 static void alc260_auto_init_analog_input(struct hda_codec *codec)
4022 {
4023         struct alc_spec *spec = codec->spec;
4024         int i;
4025
4026         for (i = 0; i < AUTO_PIN_LAST; i++) {
4027                 hda_nid_t nid = spec->autocfg.input_pins[i];
4028                 if (nid >= 0x12) {
4029                         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4030                                             i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
4031                         if (nid != ALC260_PIN_CD_NID)
4032                                 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4033                                                     AMP_OUT_MUTE);
4034                 }
4035         }
4036 }
4037
4038 /*
4039  * generic initialization of ADC, input mixers and output mixers
4040  */
4041 static struct hda_verb alc260_volume_init_verbs[] = {
4042         /*
4043          * Unmute ADC0-1 and set the default input to mic-in
4044          */
4045         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4046         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4047         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4048         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4049         
4050         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4051          * mixer widget
4052          * Note: PASD motherboards uses the Line In 2 as the input for front panel
4053          * mic (mic 2)
4054          */
4055         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
4056         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4057         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4058         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
4059         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
4060         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
4061
4062         /*
4063          * Set up output mixers (0x08 - 0x0a)
4064          */
4065         /* set vol=0 to output mixers */
4066         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4067         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4068         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4069         /* set up input amps for analog loopback */
4070         /* Amp Indices: DAC = 0, mixer = 1 */
4071         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4072         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4073         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4074         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4075         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4076         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4077         
4078         { }
4079 };
4080
4081 static int alc260_parse_auto_config(struct hda_codec *codec)
4082 {
4083         struct alc_spec *spec = codec->spec;
4084         unsigned int wcap;
4085         int err;
4086         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
4087
4088         if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
4089                                                 alc260_ignore)) < 0)
4090                 return err;
4091         if ((err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0)
4092                 return err;
4093         if (! spec->kctl_alloc)
4094                 return 0; /* can't find valid BIOS pin config */
4095         if ((err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
4096                 return err;
4097
4098         spec->multiout.max_channels = 2;
4099
4100         if (spec->autocfg.dig_out_pin)
4101                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
4102         if (spec->kctl_alloc)
4103                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
4104
4105         spec->init_verbs[spec->num_init_verbs++] = alc260_volume_init_verbs;
4106
4107         spec->num_mux_defs = 1;
4108         spec->input_mux = &spec->private_imux;
4109
4110         /* check whether NID 0x04 is valid */
4111         wcap = get_wcaps(codec, 0x04);
4112         wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */
4113         if (wcap != AC_WID_AUD_IN) {
4114                 spec->adc_nids = alc260_adc_nids_alt;
4115                 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
4116                 spec->mixers[spec->num_mixers] = alc260_capture_alt_mixer;
4117         } else {
4118                 spec->adc_nids = alc260_adc_nids;
4119                 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
4120                 spec->mixers[spec->num_mixers] = alc260_capture_mixer;
4121         }
4122         spec->num_mixers++;
4123
4124         return 1;
4125 }
4126
4127 /* additional initialization for auto-configuration model */
4128 static void alc260_auto_init(struct hda_codec *codec)
4129 {
4130         alc260_auto_init_multi_out(codec);
4131         alc260_auto_init_analog_input(codec);
4132 }
4133
4134 /*
4135  * ALC260 configurations
4136  */
4137 static const char *alc260_models[ALC260_MODEL_LAST] = {
4138         [ALC260_BASIC]          = "basic",
4139         [ALC260_HP]             = "hp",
4140         [ALC260_HP_3013]        = "hp-3013",
4141         [ALC260_FUJITSU_S702X]  = "fujitsu",
4142         [ALC260_ACER]           = "acer",
4143 #ifdef CONFIG_SND_DEBUG
4144         [ALC260_TEST]           = "test",
4145 #endif
4146         [ALC260_AUTO]           = "auto",
4147 };
4148
4149 static struct snd_pci_quirk alc260_cfg_tbl[] = {
4150         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
4151         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
4152         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
4153         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP),
4154         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_3013),
4155         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
4156         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
4157         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
4158         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
4159         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
4160         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
4161         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
4162         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
4163         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
4164         {}
4165 };
4166
4167 static struct alc_config_preset alc260_presets[] = {
4168         [ALC260_BASIC] = {
4169                 .mixers = { alc260_base_output_mixer,
4170                             alc260_input_mixer,
4171                             alc260_pc_beep_mixer,
4172                             alc260_capture_mixer },
4173                 .init_verbs = { alc260_init_verbs },
4174                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4175                 .dac_nids = alc260_dac_nids,
4176                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
4177                 .adc_nids = alc260_adc_nids,
4178                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4179                 .channel_mode = alc260_modes,
4180                 .input_mux = &alc260_capture_source,
4181         },
4182         [ALC260_HP] = {
4183                 .mixers = { alc260_base_output_mixer,
4184                             alc260_input_mixer,
4185                             alc260_capture_alt_mixer },
4186                 .init_verbs = { alc260_init_verbs },
4187                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4188                 .dac_nids = alc260_dac_nids,
4189                 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
4190                 .adc_nids = alc260_hp_adc_nids,
4191                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4192                 .channel_mode = alc260_modes,
4193                 .input_mux = &alc260_capture_source,
4194         },
4195         [ALC260_HP_3013] = {
4196                 .mixers = { alc260_hp_3013_mixer,
4197                             alc260_input_mixer,
4198                             alc260_capture_alt_mixer },
4199                 .init_verbs = { alc260_hp_3013_init_verbs },
4200                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4201                 .dac_nids = alc260_dac_nids,
4202                 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
4203                 .adc_nids = alc260_hp_adc_nids,
4204                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4205                 .channel_mode = alc260_modes,
4206                 .input_mux = &alc260_capture_source,
4207         },
4208         [ALC260_FUJITSU_S702X] = {
4209                 .mixers = { alc260_fujitsu_mixer,
4210                             alc260_capture_mixer },
4211                 .init_verbs = { alc260_fujitsu_init_verbs },
4212                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4213                 .dac_nids = alc260_dac_nids,
4214                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
4215                 .adc_nids = alc260_dual_adc_nids,
4216                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4217                 .channel_mode = alc260_modes,
4218                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
4219                 .input_mux = alc260_fujitsu_capture_sources,
4220         },
4221         [ALC260_ACER] = {
4222                 .mixers = { alc260_acer_mixer,
4223                             alc260_capture_mixer },
4224                 .init_verbs = { alc260_acer_init_verbs },
4225                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4226                 .dac_nids = alc260_dac_nids,
4227                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
4228                 .adc_nids = alc260_dual_adc_nids,
4229                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4230                 .channel_mode = alc260_modes,
4231                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
4232                 .input_mux = alc260_acer_capture_sources,
4233         },
4234 #ifdef CONFIG_SND_DEBUG
4235         [ALC260_TEST] = {
4236                 .mixers = { alc260_test_mixer,
4237                             alc260_capture_mixer },
4238                 .init_verbs = { alc260_test_init_verbs },
4239                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
4240                 .dac_nids = alc260_test_dac_nids,
4241                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
4242                 .adc_nids = alc260_test_adc_nids,
4243                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4244                 .channel_mode = alc260_modes,
4245                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
4246                 .input_mux = alc260_test_capture_sources,
4247         },
4248 #endif
4249 };
4250
4251 static int patch_alc260(struct hda_codec *codec)
4252 {
4253         struct alc_spec *spec;
4254         int err, board_config;
4255
4256         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4257         if (spec == NULL)
4258                 return -ENOMEM;
4259
4260         codec->spec = spec;
4261
4262         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
4263                                                   alc260_models,
4264                                                   alc260_cfg_tbl);
4265         if (board_config < 0) {
4266                 snd_printd(KERN_INFO "hda_codec: Unknown model for ALC260, "
4267                            "trying auto-probe from BIOS...\n");
4268                 board_config = ALC260_AUTO;
4269         }
4270
4271         if (board_config == ALC260_AUTO) {
4272                 /* automatic parse from the BIOS config */
4273                 err = alc260_parse_auto_config(codec);
4274                 if (err < 0) {
4275                         alc_free(codec);
4276                         return err;
4277                 } else if (! err) {
4278                         printk(KERN_INFO
4279                                "hda_codec: Cannot set up configuration "
4280                                "from BIOS.  Using base mode...\n");
4281                         board_config = ALC260_BASIC;
4282                 }
4283         }
4284
4285         if (board_config != ALC260_AUTO)
4286                 setup_preset(spec, &alc260_presets[board_config]);
4287
4288         spec->stream_name_analog = "ALC260 Analog";
4289         spec->stream_analog_playback = &alc260_pcm_analog_playback;
4290         spec->stream_analog_capture = &alc260_pcm_analog_capture;
4291
4292         spec->stream_name_digital = "ALC260 Digital";
4293         spec->stream_digital_playback = &alc260_pcm_digital_playback;
4294         spec->stream_digital_capture = &alc260_pcm_digital_capture;
4295
4296         codec->patch_ops = alc_patch_ops;
4297         if (board_config == ALC260_AUTO)
4298                 spec->init_hook = alc260_auto_init;
4299
4300         return 0;
4301 }
4302
4303
4304 /*
4305  * ALC882 support
4306  *
4307  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4308  * configuration.  Each pin widget can choose any input DACs and a mixer.
4309  * Each ADC is connected from a mixer of all inputs.  This makes possible
4310  * 6-channel independent captures.
4311  *
4312  * In addition, an independent DAC for the multi-playback (not used in this
4313  * driver yet).
4314  */
4315 #define ALC882_DIGOUT_NID       0x06
4316 #define ALC882_DIGIN_NID        0x0a
4317
4318 static struct hda_channel_mode alc882_ch_modes[1] = {
4319         { 8, NULL }
4320 };
4321
4322 static hda_nid_t alc882_dac_nids[4] = {
4323         /* front, rear, clfe, rear_surr */
4324         0x02, 0x03, 0x04, 0x05
4325 };
4326
4327 /* identical with ALC880 */
4328 #define alc882_adc_nids         alc880_adc_nids
4329 #define alc882_adc_nids_alt     alc880_adc_nids_alt
4330
4331 /* input MUX */
4332 /* FIXME: should be a matrix-type input source selection */
4333
4334 static struct hda_input_mux alc882_capture_source = {
4335         .num_items = 4,
4336         .items = {
4337                 { "Mic", 0x0 },
4338                 { "Front Mic", 0x1 },
4339                 { "Line", 0x2 },
4340                 { "CD", 0x4 },
4341         },
4342 };
4343 #define alc882_mux_enum_info alc_mux_enum_info
4344 #define alc882_mux_enum_get alc_mux_enum_get
4345
4346 static int alc882_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
4347 {
4348         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4349         struct alc_spec *spec = codec->spec;
4350         const struct hda_input_mux *imux = spec->input_mux;
4351         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
4352         static hda_nid_t capture_mixers[3] = { 0x24, 0x23, 0x22 };
4353         hda_nid_t nid = capture_mixers[adc_idx];
4354         unsigned int *cur_val = &spec->cur_mux[adc_idx];
4355         unsigned int i, idx;
4356
4357         idx = ucontrol->value.enumerated.item[0];
4358         if (idx >= imux->num_items)
4359                 idx = imux->num_items - 1;
4360         if (*cur_val == idx && ! codec->in_resume)
4361                 return 0;
4362         for (i = 0; i < imux->num_items; i++) {
4363                 unsigned int v = (i == idx) ? 0x7000 : 0x7080;
4364                 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4365                                     v | (imux->items[i].index << 8));
4366         }
4367         *cur_val = idx;
4368         return 1;
4369 }
4370
4371 /*
4372  * 6ch mode
4373  */
4374 static struct hda_verb alc882_sixstack_ch6_init[] = {
4375         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
4376         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4377         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4378         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4379         { } /* end */
4380 };
4381
4382 /*
4383  * 8ch mode
4384  */
4385 static struct hda_verb alc882_sixstack_ch8_init[] = {
4386         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4387         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4388         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4389         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4390         { } /* end */
4391 };
4392
4393 static struct hda_channel_mode alc882_sixstack_modes[2] = {
4394         { 6, alc882_sixstack_ch6_init },
4395         { 8, alc882_sixstack_ch8_init },
4396 };
4397
4398 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
4399  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
4400  */
4401 static struct snd_kcontrol_new alc882_base_mixer[] = {
4402         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
4403         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
4404         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
4405         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
4406         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
4407         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
4408         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
4409         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
4410         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
4411         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
4412         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
4413         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
4414         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
4415         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
4416         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
4417         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
4418         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
4419         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
4420         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
4421         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
4422         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
4423         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
4424         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
4425         { } /* end */
4426 };
4427
4428 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
4429         {
4430                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4431                 .name = "Channel Mode",
4432                 .info = alc_ch_mode_info,
4433                 .get = alc_ch_mode_get,
4434                 .put = alc_ch_mode_put,
4435         },
4436         { } /* end */
4437 };
4438
4439 static struct hda_verb alc882_init_verbs[] = {
4440         /* Front mixer: unmute input/output amp left and right (volume = 0) */
4441         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4442         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4443         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4444         /* Rear mixer */
4445         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4446         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4447         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4448         /* CLFE mixer */
4449         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4450         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4451         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4452         /* Side mixer */
4453         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4454         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4455         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4456
4457         /* Front Pin: output 0 (0x0c) */
4458         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4459         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4460         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
4461         /* Rear Pin: output 1 (0x0d) */
4462         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4463         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4464         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
4465         /* CLFE Pin: output 2 (0x0e) */
4466         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4467         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4468         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
4469         /* Side Pin: output 3 (0x0f) */
4470         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4471         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4472         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
4473         /* Mic (rear) pin: input vref at 80% */
4474         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4475         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4476         /* Front Mic pin: input vref at 80% */
4477         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4478         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4479         /* Line In pin: input */
4480         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4481         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4482         /* Line-2 In: Headphone output (output 0 - 0x0c) */
4483         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4484         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4485         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
4486         /* CD pin widget for input */
4487         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4488
4489         /* FIXME: use matrix-type input source selection */
4490         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
4491         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
4492         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4493         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4494         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4495         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4496         /* Input mixer2 */
4497         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4498         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4499         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4500         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4501         /* Input mixer3 */
4502         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4503         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4504         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4505         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4506         /* ADC1: mute amp left and right */
4507         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4508         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
4509         /* ADC2: mute amp left and right */
4510         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4511         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
4512         /* ADC3: mute amp left and right */
4513         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4514         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
4515
4516         { }
4517 };
4518
4519 static struct hda_verb alc882_eapd_verbs[] = {
4520         /* change to EAPD mode */
4521         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
4522         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
4523         { } 
4524 };
4525
4526 /* Mac Pro test */
4527 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
4528         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
4529         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
4530         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
4531         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
4532         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
4533         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT),
4534         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT),
4535         { } /* end */
4536 };
4537
4538 static struct hda_verb alc882_macpro_init_verbs[] = {
4539         /* Front mixer: unmute input/output amp left and right (volume = 0) */
4540         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4541         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4542         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4543         /* Front Pin: output 0 (0x0c) */
4544         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4545         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4546         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
4547         /* Front Mic pin: input vref at 80% */
4548         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4549         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4550         /* Speaker:  output */
4551         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4552         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4553         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
4554         /* Headphone output (output 0 - 0x0c) */
4555         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4556         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4557         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
4558
4559         /* FIXME: use matrix-type input source selection */
4560         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
4561         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
4562         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4563         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4564         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4565         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4566         /* Input mixer2 */
4567         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4568         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4569         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4570         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4571         /* Input mixer3 */
4572         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4573         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4574         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4575         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4576         /* ADC1: mute amp left and right */
4577         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4578         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
4579         /* ADC2: mute amp left and right */
4580         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4581         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
4582         /* ADC3: mute amp left and right */
4583         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4584         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
4585
4586         { }
4587 };
4588 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
4589 {
4590         unsigned int gpiostate, gpiomask, gpiodir;
4591
4592         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4593                                        AC_VERB_GET_GPIO_DATA, 0);
4594
4595         if (!muted)
4596                 gpiostate |= (1 << pin);
4597         else
4598                 gpiostate &= ~(1 << pin);
4599
4600         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4601                                       AC_VERB_GET_GPIO_MASK, 0);
4602         gpiomask |= (1 << pin);
4603
4604         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4605                                      AC_VERB_GET_GPIO_DIRECTION, 0);
4606         gpiodir |= (1 << pin);
4607
4608
4609         snd_hda_codec_write(codec, codec->afg, 0,
4610                             AC_VERB_SET_GPIO_MASK, gpiomask);
4611         snd_hda_codec_write(codec, codec->afg, 0,
4612                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
4613
4614         msleep(1);
4615
4616         snd_hda_codec_write(codec, codec->afg, 0,
4617                             AC_VERB_SET_GPIO_DATA, gpiostate);
4618 }
4619
4620 /*
4621  * generic initialization of ADC, input mixers and output mixers
4622  */
4623 static struct hda_verb alc882_auto_init_verbs[] = {
4624         /*
4625          * Unmute ADC0-2 and set the default input to mic-in
4626          */
4627         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
4628         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4629         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
4630         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4631         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
4632         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4633
4634         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4635          * mixer widget
4636          * Note: PASD motherboards uses the Line In 2 as the input for front panel
4637          * mic (mic 2)
4638          */
4639         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
4640         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4641         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4642         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
4643         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
4644         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
4645
4646         /*
4647          * Set up output mixers (0x0c - 0x0f)
4648          */
4649         /* set vol=0 to output mixers */
4650         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4651         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4652         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4653         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4654         /* set up input amps for analog loopback */
4655         /* Amp Indices: DAC = 0, mixer = 1 */
4656         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4657         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4658         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4659         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4660         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4661         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4662         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4663         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4664         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4665         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4666
4667         /* FIXME: use matrix-type input source selection */
4668         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
4669         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
4670         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4671         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
4672         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
4673         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
4674         /* Input mixer2 */
4675         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4676         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
4677         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
4678         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
4679         /* Input mixer3 */
4680         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4681         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
4682         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
4683         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
4684
4685         { }
4686 };
4687
4688 /* capture mixer elements */
4689 static struct snd_kcontrol_new alc882_capture_alt_mixer[] = {
4690         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
4691         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
4692         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
4693         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
4694         {
4695                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4696                 /* The multiple "Capture Source" controls confuse alsamixer
4697                  * So call somewhat different..
4698                  * FIXME: the controls appear in the "playback" view!
4699                  */
4700                 /* .name = "Capture Source", */
4701                 .name = "Input Source",
4702                 .count = 2,
4703                 .info = alc882_mux_enum_info,
4704                 .get = alc882_mux_enum_get,
4705                 .put = alc882_mux_enum_put,
4706         },
4707         { } /* end */
4708 };
4709
4710 static struct snd_kcontrol_new alc882_capture_mixer[] = {
4711         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
4712         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
4713         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
4714         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
4715         HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
4716         HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
4717         {
4718                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4719                 /* The multiple "Capture Source" controls confuse alsamixer
4720                  * So call somewhat different..
4721                  * FIXME: the controls appear in the "playback" view!
4722                  */
4723                 /* .name = "Capture Source", */
4724                 .name = "Input Source",
4725                 .count = 3,
4726                 .info = alc882_mux_enum_info,
4727                 .get = alc882_mux_enum_get,
4728                 .put = alc882_mux_enum_put,
4729         },
4730         { } /* end */
4731 };
4732
4733 /* pcm configuration: identiacal with ALC880 */
4734 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
4735 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
4736 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
4737 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
4738
4739 /*
4740  * configuration and preset
4741  */
4742 static const char *alc882_models[ALC882_MODEL_LAST] = {
4743         [ALC882_3ST_DIG]        = "3stack-dig",
4744         [ALC882_6ST_DIG]        = "6stack-dig",
4745         [ALC882_ARIMA]          = "arima",
4746         [ALC885_MACPRO]         = "macpro",
4747         [ALC882_AUTO]           = "auto",
4748 };
4749
4750 static struct snd_pci_quirk alc882_cfg_tbl[] = {
4751         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
4752         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
4753         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
4754         SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA),
4755         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
4756         {}
4757 };
4758
4759 static struct alc_config_preset alc882_presets[] = {
4760         [ALC882_3ST_DIG] = {
4761                 .mixers = { alc882_base_mixer },
4762                 .init_verbs = { alc882_init_verbs },
4763                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
4764                 .dac_nids = alc882_dac_nids,
4765                 .dig_out_nid = ALC882_DIGOUT_NID,
4766                 .dig_in_nid = ALC882_DIGIN_NID,
4767                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
4768                 .channel_mode = alc882_ch_modes,
4769                 .need_dac_fix = 1,
4770                 .input_mux = &alc882_capture_source,
4771         },
4772         [ALC882_6ST_DIG] = {
4773                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
4774                 .init_verbs = { alc882_init_verbs },
4775                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
4776                 .dac_nids = alc882_dac_nids,
4777                 .dig_out_nid = ALC882_DIGOUT_NID,
4778                 .dig_in_nid = ALC882_DIGIN_NID,
4779                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
4780                 .channel_mode = alc882_sixstack_modes,
4781                 .input_mux = &alc882_capture_source,
4782         },
4783         [ALC882_ARIMA] = {
4784                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
4785                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs },
4786                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
4787                 .dac_nids = alc882_dac_nids,
4788                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
4789                 .channel_mode = alc882_sixstack_modes,
4790                 .input_mux = &alc882_capture_source,
4791         },
4792         [ALC885_MACPRO] = {
4793                 .mixers = { alc882_macpro_mixer },
4794                 .init_verbs = { alc882_macpro_init_verbs },
4795                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
4796                 .dac_nids = alc882_dac_nids,
4797                 .dig_out_nid = ALC882_DIGOUT_NID,
4798                 .dig_in_nid = ALC882_DIGIN_NID,
4799                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
4800                 .channel_mode = alc882_ch_modes,
4801                 .input_mux = &alc882_capture_source,
4802         },
4803 };
4804
4805
4806 /*
4807  * BIOS auto configuration
4808  */
4809 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
4810                                               hda_nid_t nid, int pin_type,
4811                                               int dac_idx)
4812 {
4813         /* set as output */
4814         struct alc_spec *spec = codec->spec;
4815         int idx; 
4816         
4817         if (spec->multiout.dac_nids[dac_idx] == 0x25)
4818                 idx = 4;
4819         else
4820                 idx = spec->multiout.dac_nids[dac_idx] - 2;
4821
4822         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
4823         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
4824         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
4825
4826 }
4827
4828 static void alc882_auto_init_multi_out(struct hda_codec *codec)
4829 {
4830         struct alc_spec *spec = codec->spec;
4831         int i;
4832
4833         for (i = 0; i <= HDA_SIDE; i++) {
4834                 hda_nid_t nid = spec->autocfg.line_out_pins[i]; 
4835                 if (nid)
4836                         alc882_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
4837         }
4838 }
4839
4840 static void alc882_auto_init_hp_out(struct hda_codec *codec)
4841 {
4842         struct alc_spec *spec = codec->spec;
4843         hda_nid_t pin;
4844
4845         pin = spec->autocfg.hp_pins[0];
4846         if (pin) /* connect to front */
4847                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0); /* use dac 0 */
4848 }
4849
4850 #define alc882_is_input_pin(nid)        alc880_is_input_pin(nid)
4851 #define ALC882_PIN_CD_NID               ALC880_PIN_CD_NID
4852
4853 static void alc882_auto_init_analog_input(struct hda_codec *codec)
4854 {
4855         struct alc_spec *spec = codec->spec;
4856         int i;
4857
4858         for (i = 0; i < AUTO_PIN_LAST; i++) {
4859                 hda_nid_t nid = spec->autocfg.input_pins[i];
4860                 if (alc882_is_input_pin(nid)) {
4861                         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4862                                             i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
4863                         if (nid != ALC882_PIN_CD_NID)
4864                                 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4865                                                     AMP_OUT_MUTE);
4866                 }
4867         }
4868 }
4869
4870 /* almost identical with ALC880 parser... */
4871 static int alc882_parse_auto_config(struct hda_codec *codec)
4872 {
4873         struct alc_spec *spec = codec->spec;
4874         int err = alc880_parse_auto_config(codec);
4875
4876         if (err < 0)
4877                 return err;
4878         else if (err > 0)
4879                 /* hack - override the init verbs */
4880                 spec->init_verbs[0] = alc882_auto_init_verbs;
4881         return err;
4882 }
4883
4884 /* additional initialization for auto-configuration model */
4885 static void alc882_auto_init(struct hda_codec *codec)
4886 {
4887         alc882_auto_init_multi_out(codec);
4888         alc882_auto_init_hp_out(codec);
4889         alc882_auto_init_analog_input(codec);
4890 }
4891
4892 static int patch_alc882(struct hda_codec *codec)
4893 {
4894         struct alc_spec *spec;
4895         int err, board_config;
4896
4897         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4898         if (spec == NULL)
4899                 return -ENOMEM;
4900
4901         codec->spec = spec;
4902
4903         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
4904                                                   alc882_models,
4905                                                   alc882_cfg_tbl);
4906
4907         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
4908                 printk(KERN_INFO "hda_codec: Unknown model for ALC882, "
4909                        "trying auto-probe from BIOS...\n");
4910                 board_config = ALC882_AUTO;
4911         }
4912
4913         if (board_config == ALC882_AUTO) {
4914                 /* automatic parse from the BIOS config */
4915                 err = alc882_parse_auto_config(codec);
4916                 if (err < 0) {
4917                         alc_free(codec);
4918                         return err;
4919                 } else if (! err) {
4920                         printk(KERN_INFO
4921                                "hda_codec: Cannot set up configuration "
4922                                "from BIOS.  Using base mode...\n");
4923                         board_config = ALC882_3ST_DIG;
4924                 }
4925         }
4926
4927         if (board_config != ALC882_AUTO)
4928                 setup_preset(spec, &alc882_presets[board_config]);
4929
4930         if (board_config == ALC885_MACPRO) {
4931                 alc882_gpio_mute(codec, 0, 0);
4932                 alc882_gpio_mute(codec, 1, 0);
4933         }
4934
4935         spec->stream_name_analog = "ALC882 Analog";
4936         spec->stream_analog_playback = &alc882_pcm_analog_playback;
4937         spec->stream_analog_capture = &alc882_pcm_analog_capture;
4938
4939         spec->stream_name_digital = "ALC882 Digital";
4940         spec->stream_digital_playback = &alc882_pcm_digital_playback;
4941         spec->stream_digital_capture = &alc882_pcm_digital_capture;
4942
4943         if (! spec->adc_nids && spec->input_mux) {
4944                 /* check whether NID 0x07 is valid */
4945                 unsigned int wcap = get_wcaps(codec, 0x07);
4946                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */
4947                 if (wcap != AC_WID_AUD_IN) {
4948                         spec->adc_nids = alc882_adc_nids_alt;
4949                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
4950                         spec->mixers[spec->num_mixers] = alc882_capture_alt_mixer;
4951                         spec->num_mixers++;
4952                 } else {
4953                         spec->adc_nids = alc882_adc_nids;
4954                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
4955                         spec->mixers[spec->num_mixers] = alc882_capture_mixer;
4956                         spec->num_mixers++;
4957                 }
4958         }
4959
4960         codec->patch_ops = alc_patch_ops;
4961         if (board_config == ALC882_AUTO)
4962                 spec->init_hook = alc882_auto_init;
4963
4964         return 0;
4965 }
4966
4967 /*
4968  * ALC883 support
4969  *
4970  * ALC883 is almost identical with ALC880 but has cleaner and more flexible
4971  * configuration.  Each pin widget can choose any input DACs and a mixer.
4972  * Each ADC is connected from a mixer of all inputs.  This makes possible
4973  * 6-channel independent captures.
4974  *
4975  * In addition, an independent DAC for the multi-playback (not used in this
4976  * driver yet).
4977  */
4978 #define ALC883_DIGOUT_NID       0x06
4979 #define ALC883_DIGIN_NID        0x0a
4980
4981 static hda_nid_t alc883_dac_nids[4] = {
4982         /* front, rear, clfe, rear_surr */
4983         0x02, 0x04, 0x03, 0x05
4984 };
4985
4986 static hda_nid_t alc883_adc_nids[2] = {
4987         /* ADC1-2 */
4988         0x08, 0x09,
4989 };
4990 /* input MUX */
4991 /* FIXME: should be a matrix-type input source selection */
4992
4993 static struct hda_input_mux alc883_capture_source = {
4994         .num_items = 4,
4995         .items = {
4996                 { "Mic", 0x0 },
4997                 { "Front Mic", 0x1 },
4998                 { "Line", 0x2 },
4999                 { "CD", 0x4 },
5000         },
5001 };
5002 #define alc883_mux_enum_info alc_mux_enum_info
5003 #define alc883_mux_enum_get alc_mux_enum_get
5004
5005 static int alc883_mux_enum_put(struct snd_kcontrol *kcontrol,
5006                                struct snd_ctl_elem_value *ucontrol)
5007 {
5008         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5009         struct alc_spec *spec = codec->spec;
5010         const struct hda_input_mux *imux = spec->input_mux;
5011         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
5012         static hda_nid_t capture_mixers[3] = { 0x24, 0x23, 0x22 };
5013         hda_nid_t nid = capture_mixers[adc_idx];
5014         unsigned int *cur_val = &spec->cur_mux[adc_idx];
5015         unsigned int i, idx;
5016
5017         idx = ucontrol->value.enumerated.item[0];
5018         if (idx >= imux->num_items)
5019                 idx = imux->num_items - 1;
5020         if (*cur_val == idx && ! codec->in_resume)
5021                 return 0;
5022         for (i = 0; i < imux->num_items; i++) {
5023                 unsigned int v = (i == idx) ? 0x7000 : 0x7080;
5024                 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
5025                                     v | (imux->items[i].index << 8));
5026         }
5027         *cur_val = idx;
5028         return 1;
5029 }
5030 /*
5031  * 2ch mode
5032  */
5033 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
5034         { 2, NULL }
5035 };
5036
5037 /*
5038  * 2ch mode
5039  */
5040 static struct hda_verb alc883_3ST_ch2_init[] = {
5041         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
5042         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5043         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5044         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5045         { } /* end */
5046 };
5047
5048 /*
5049  * 6ch mode
5050  */
5051 static struct hda_verb alc883_3ST_ch6_init[] = {
5052         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5053         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5054         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
5055         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5056         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5057         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5058         { } /* end */
5059 };
5060
5061 static struct hda_channel_mode alc883_3ST_6ch_modes[2] = {
5062         { 2, alc883_3ST_ch2_init },
5063         { 6, alc883_3ST_ch6_init },
5064 };
5065
5066 /*
5067  * 6ch mode
5068  */
5069 static struct hda_verb alc883_sixstack_ch6_init[] = {
5070         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
5071         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5072         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5073         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5074         { } /* end */
5075 };
5076
5077 /*
5078  * 8ch mode
5079  */
5080 static struct hda_verb alc883_sixstack_ch8_init[] = {
5081         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5082         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5083         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5084         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5085         { } /* end */
5086 };
5087
5088 static struct hda_channel_mode alc883_sixstack_modes[2] = {
5089         { 6, alc883_sixstack_ch6_init },
5090         { 8, alc883_sixstack_ch8_init },
5091 };
5092
5093 static struct hda_verb alc883_medion_eapd_verbs[] = {
5094         /* eanable EAPD on medion laptop */
5095         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
5096         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
5097         { }
5098 };
5099
5100 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
5101  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
5102  */
5103
5104 static struct snd_kcontrol_new alc883_base_mixer[] = {
5105         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5106         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5107         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
5108         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
5109         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
5110         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
5111         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
5112         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
5113         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
5114         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
5115         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5116         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5117         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5118         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5119         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5120         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5121         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5122         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5123         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5124         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5125         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5126         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5127         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5128         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
5129         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
5130         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
5131         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
5132         {
5133                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5134                 /* .name = "Capture Source", */
5135                 .name = "Input Source",
5136                 .count = 2,
5137                 .info = alc883_mux_enum_info,
5138                 .get = alc883_mux_enum_get,
5139                 .put = alc883_mux_enum_put,
5140         },
5141         { } /* end */
5142 };
5143
5144 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
5145         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5146         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5147         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5148         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5149         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5150         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5151         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5152         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5153         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5154         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5155         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5156         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5157         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5158         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5159         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5160         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
5161         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
5162         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
5163         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
5164         {
5165                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5166                 /* .name = "Capture Source", */
5167                 .name = "Input Source",
5168                 .count = 2,
5169                 .info = alc883_mux_enum_info,
5170                 .get = alc883_mux_enum_get,
5171                 .put = alc883_mux_enum_put,
5172         },
5173         { } /* end */
5174 };
5175
5176 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
5177         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5178         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5179         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
5180         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
5181         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
5182         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
5183         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
5184         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
5185         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5186         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5187         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5188         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5189         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5190         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5191         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5192         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5193         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5194         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5195         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5196         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5197         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5198         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
5199         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
5200         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
5201         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
5202         {
5203                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5204                 /* .name = "Capture Source", */
5205                 .name = "Input Source",
5206                 .count = 2,
5207                 .info = alc883_mux_enum_info,
5208                 .get = alc883_mux_enum_get,
5209                 .put = alc883_mux_enum_put,
5210         },
5211         { } /* end */
5212 };
5213
5214 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
5215         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5216         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
5217         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
5218         HDA_CODEC_MUTE("Surround Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5219         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
5220         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
5221         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x16, 1, 0x0, HDA_OUTPUT),
5222         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
5223         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5224         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5225         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5226         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5227         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5228         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5229         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5230         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5231         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5232         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5233         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5234         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5235         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5236         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
5237         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
5238
5239         {
5240                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5241                 /* .name = "Capture Source", */
5242                 .name = "Input Source",
5243                 .count = 1,
5244                 .info = alc883_mux_enum_info,
5245                 .get = alc883_mux_enum_get,
5246                 .put = alc883_mux_enum_put,
5247         },
5248         { } /* end */
5249 };
5250
5251 static struct snd_kcontrol_new alc883_tagra_mixer[] = {
5252         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5253         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
5254         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5255         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
5256         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
5257         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
5258         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
5259         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
5260         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
5261         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5262         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5263         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5264         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5265         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5266         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5267         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5268         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
5269         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
5270         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
5271         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
5272         {
5273                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5274                 /* .name = "Capture Source", */
5275                 .name = "Input Source",
5276                 .count = 2,
5277                 .info = alc883_mux_enum_info,
5278                 .get = alc883_mux_enum_get,
5279                 .put = alc883_mux_enum_put,
5280         },
5281         { } /* end */
5282 };      
5283
5284 static struct snd_kcontrol_new alc883_tagra_2ch_mixer[] = {
5285         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5286         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
5287         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5288         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5289         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5290         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5291         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5292         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5293         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
5294         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
5295         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
5296         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
5297         {
5298                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5299                 /* .name = "Capture Source", */
5300                 .name = "Input Source",
5301                 .count = 2,
5302                 .info = alc883_mux_enum_info,
5303                 .get = alc883_mux_enum_get,
5304                 .put = alc883_mux_enum_put,
5305         },
5306         { } /* end */
5307 };      
5308
5309 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
5310         {
5311                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5312                 .name = "Channel Mode",
5313                 .info = alc_ch_mode_info,
5314                 .get = alc_ch_mode_get,
5315                 .put = alc_ch_mode_put,
5316         },
5317         { } /* end */
5318 };
5319
5320 static struct hda_verb alc883_init_verbs[] = {
5321         /* ADC1: mute amp left and right */
5322         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5323         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5324         /* ADC2: mute amp left and right */
5325         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5326         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5327         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5328         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5329         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5330         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5331         /* Rear mixer */
5332         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5333         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5334         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5335         /* CLFE mixer */
5336         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5337         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5338         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5339         /* Side mixer */
5340         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5341         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5342         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5343
5344         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5345         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5346         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
5347         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
5348         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
5349
5350         /* Front Pin: output 0 (0x0c) */
5351         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5352         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5353         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5354         /* Rear Pin: output 1 (0x0d) */
5355         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5356         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5357         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5358         /* CLFE Pin: output 2 (0x0e) */
5359         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5360         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5361         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
5362         /* Side Pin: output 3 (0x0f) */
5363         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5364         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5365         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
5366         /* Mic (rear) pin: input vref at 80% */
5367         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5368         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5369         /* Front Mic pin: input vref at 80% */
5370         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5371         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5372         /* Line In pin: input */
5373         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5374         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5375         /* Line-2 In: Headphone output (output 0 - 0x0c) */
5376         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5377         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5378         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
5379         /* CD pin widget for input */
5380         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5381
5382         /* FIXME: use matrix-type input source selection */
5383         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5384         /* Input mixer2 */
5385         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5386         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5387         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
5388         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
5389         /* Input mixer3 */
5390         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5391         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5392         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
5393         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
5394         { }
5395 };
5396
5397 static struct hda_verb alc883_tagra_verbs[] = {
5398         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5399         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5400
5401         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5402         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5403         
5404         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
5405         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
5406         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5407
5408         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5409         {0x01, AC_VERB_SET_GPIO_MASK, 0x03}, 
5410         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03}, 
5411         {0x01, AC_VERB_SET_GPIO_DATA, 0x03}, 
5412
5413         { } /* end */
5414 };
5415
5416 /* toggle speaker-output according to the hp-jack state */
5417 static void alc883_tagra_automute(struct hda_codec *codec)
5418 {
5419         unsigned int present;
5420
5421         present = snd_hda_codec_read(codec, 0x14, 0,
5422                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5423         snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0,
5424                                  0x80, present ? 0x80 : 0);
5425         snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0,
5426                                  0x80, present ? 0x80 : 0);
5427         snd_hda_codec_write(codec, 1, 0, AC_VERB_SET_GPIO_DATA, present ? 1 : 3);
5428 }
5429
5430 static void alc883_tagra_unsol_event(struct hda_codec *codec, unsigned int res)
5431 {
5432         if ((res >> 26) == ALC880_HP_EVENT)
5433                 alc883_tagra_automute(codec);
5434 }
5435
5436 /*
5437  * generic initialization of ADC, input mixers and output mixers
5438  */
5439 static struct hda_verb alc883_auto_init_verbs[] = {
5440         /*
5441          * Unmute ADC0-2 and set the default input to mic-in
5442          */
5443         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5444         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5445         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5446         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5447
5448         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5449          * mixer widget
5450          * Note: PASD motherboards uses the Line In 2 as the input for front panel
5451          * mic (mic 2)
5452          */
5453         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
5454         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5455         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5456         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
5457         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
5458         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
5459
5460         /*
5461          * Set up output mixers (0x0c - 0x0f)
5462          */
5463         /* set vol=0 to output mixers */
5464         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5465         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5466         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5467         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5468         /* set up input amps for analog loopback */
5469         /* Amp Indices: DAC = 0, mixer = 1 */
5470         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5471         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5472         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5473         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5474         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5475         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5476         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5477         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5478         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5479         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5480
5481         /* FIXME: use matrix-type input source selection */
5482         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5483         /* Input mixer1 */
5484         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5485         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5486         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
5487         //{0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
5488         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
5489         /* Input mixer2 */
5490         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5491         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5492         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
5493         //{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
5494         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
5495
5496         { }
5497 };
5498
5499 /* capture mixer elements */
5500 static struct snd_kcontrol_new alc883_capture_mixer[] = {
5501         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
5502         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
5503         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
5504         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
5505         {
5506                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5507                 /* The multiple "Capture Source" controls confuse alsamixer
5508                  * So call somewhat different..
5509                  * FIXME: the controls appear in the "playback" view!
5510                  */
5511                 /* .name = "Capture Source", */
5512                 .name = "Input Source",
5513                 .count = 2,
5514                 .info = alc882_mux_enum_info,
5515                 .get = alc882_mux_enum_get,
5516                 .put = alc882_mux_enum_put,
5517         },
5518         { } /* end */
5519 };
5520
5521 /* pcm configuration: identiacal with ALC880 */
5522 #define alc883_pcm_analog_playback      alc880_pcm_analog_playback
5523 #define alc883_pcm_analog_capture       alc880_pcm_analog_capture
5524 #define alc883_pcm_digital_playback     alc880_pcm_digital_playback
5525 #define alc883_pcm_digital_capture      alc880_pcm_digital_capture
5526
5527 /*
5528  * configuration and preset
5529  */
5530 static const char *alc883_models[ALC883_MODEL_LAST] = {
5531         [ALC883_3ST_2ch_DIG]    = "3stack-dig",
5532         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
5533         [ALC883_3ST_6ch]        = "3stack-6ch",
5534         [ALC883_6ST_DIG]        = "6stack-dig",
5535         [ALC883_TARGA_DIG]      = "targa-dig",
5536         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
5537         [ALC888_DEMO_BOARD]     = "6stack-dig-demo",
5538         [ALC883_ACER]           = "acer",
5539         [ALC883_MEDION]         = "medion",
5540         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
5541         [ALC883_AUTO]           = "auto",
5542 };
5543
5544 static struct snd_pci_quirk alc883_cfg_tbl[] = {
5545         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG),
5546         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
5547         SND_PCI_QUIRK(0x1558, 0, "Clevo laptop", ALC883_LAPTOP_EAPD),
5548         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
5549         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
5550         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
5551         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
5552         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
5553         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
5554         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
5555         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
5556         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
5557         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
5558         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
5559         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
5560         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
5561         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
5562         SND_PCI_QUIRK(0x1025, 0, "Acer laptop", ALC883_ACER),
5563         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
5564         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
5565         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
5566         {}
5567 };
5568
5569 static struct alc_config_preset alc883_presets[] = {
5570         [ALC883_3ST_2ch_DIG] = {
5571                 .mixers = { alc883_3ST_2ch_mixer },
5572                 .init_verbs = { alc883_init_verbs },
5573                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
5574                 .dac_nids = alc883_dac_nids,
5575                 .dig_out_nid = ALC883_DIGOUT_NID,
5576                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
5577                 .adc_nids = alc883_adc_nids,
5578                 .dig_in_nid = ALC883_DIGIN_NID,
5579                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
5580                 .channel_mode = alc883_3ST_2ch_modes,
5581                 .input_mux = &alc883_capture_source,
5582         },
5583         [ALC883_3ST_6ch_DIG] = {
5584                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
5585                 .init_verbs = { alc883_init_verbs },
5586                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
5587                 .dac_nids = alc883_dac_nids,
5588                 .dig_out_nid = ALC883_DIGOUT_NID,
5589                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
5590                 .adc_nids = alc883_adc_nids,
5591                 .dig_in_nid = ALC883_DIGIN_NID,
5592                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
5593                 .channel_mode = alc883_3ST_6ch_modes,
5594                 .need_dac_fix = 1,
5595                 .input_mux = &alc883_capture_source,
5596         },      
5597         [ALC883_3ST_6ch] = {
5598                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
5599                 .init_verbs = { alc883_init_verbs },
5600                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
5601                 .dac_nids = alc883_dac_nids,
5602                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
5603                 .adc_nids = alc883_adc_nids,
5604                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
5605                 .channel_mode = alc883_3ST_6ch_modes,
5606                 .need_dac_fix = 1,
5607                 .input_mux = &alc883_capture_source,
5608         },      
5609         [ALC883_6ST_DIG] = {
5610                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
5611                 .init_verbs = { alc883_init_verbs },
5612                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
5613                 .dac_nids = alc883_dac_nids,
5614                 .dig_out_nid = ALC883_DIGOUT_NID,
5615                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
5616                 .adc_nids = alc883_adc_nids,
5617                 .dig_in_nid = ALC883_DIGIN_NID,
5618                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
5619                 .channel_mode = alc883_sixstack_modes,
5620                 .input_mux = &alc883_capture_source,
5621         },
5622         [ALC883_TARGA_DIG] = {
5623                 .mixers = { alc883_tagra_mixer, alc883_chmode_mixer },
5624                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
5625                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
5626                 .dac_nids = alc883_dac_nids,
5627                 .dig_out_nid = ALC883_DIGOUT_NID,
5628                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
5629                 .adc_nids = alc883_adc_nids,
5630                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
5631                 .channel_mode = alc883_3ST_6ch_modes,
5632                 .need_dac_fix = 1,
5633                 .input_mux = &alc883_capture_source,
5634                 .unsol_event = alc883_tagra_unsol_event,
5635                 .init_hook = alc883_tagra_automute,
5636         },
5637         [ALC883_TARGA_2ch_DIG] = {
5638                 .mixers = { alc883_tagra_2ch_mixer},
5639                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
5640                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
5641                 .dac_nids = alc883_dac_nids,
5642                 .dig_out_nid = ALC883_DIGOUT_NID,
5643                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
5644                 .adc_nids = alc883_adc_nids,
5645                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
5646                 .channel_mode = alc883_3ST_2ch_modes,
5647                 .input_mux = &alc883_capture_source,
5648                 .unsol_event = alc883_tagra_unsol_event,
5649                 .init_hook = alc883_tagra_automute,
5650         },
5651         [ALC888_DEMO_BOARD] = {
5652                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
5653                 .init_verbs = { alc883_init_verbs },
5654                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
5655                 .dac_nids = alc883_dac_nids,
5656                 .dig_out_nid = ALC883_DIGOUT_NID,
5657                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
5658                 .adc_nids = alc883_adc_nids,
5659                 .dig_in_nid = ALC883_DIGIN_NID,
5660                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
5661                 .channel_mode = alc883_sixstack_modes,
5662                 .input_mux = &alc883_capture_source,
5663         },
5664         [ALC883_ACER] = {
5665                 .mixers = { alc883_base_mixer,
5666                             alc883_chmode_mixer },
5667                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
5668                  * and the headphone jack.  Turn this on and rely on the
5669                  * standard mute methods whenever the user wants to turn
5670                  * these outputs off.
5671                  */
5672                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
5673                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
5674                 .dac_nids = alc883_dac_nids,
5675                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
5676                 .adc_nids = alc883_adc_nids,
5677                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
5678                 .channel_mode = alc883_3ST_2ch_modes,
5679                 .input_mux = &alc883_capture_source,
5680         },
5681         [ALC883_MEDION] = {
5682                 .mixers = { alc883_fivestack_mixer,
5683                             alc883_chmode_mixer },
5684                 .init_verbs = { alc883_init_verbs,
5685                                 alc883_medion_eapd_verbs },
5686                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
5687                 .dac_nids = alc883_dac_nids,
5688                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
5689                 .adc_nids = alc883_adc_nids,
5690                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
5691                 .channel_mode = alc883_sixstack_modes,
5692                 .input_mux = &alc883_capture_source,
5693         },
5694         [ALC883_LAPTOP_EAPD] = {
5695                 .mixers = { alc883_base_mixer,
5696                             alc883_chmode_mixer },
5697                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
5698                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
5699                 .dac_nids = alc883_dac_nids,
5700                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
5701                 .adc_nids = alc883_adc_nids,
5702                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
5703                 .channel_mode = alc883_3ST_2ch_modes,
5704                 .input_mux = &alc883_capture_source,
5705         },
5706 };
5707
5708
5709 /*
5710  * BIOS auto configuration
5711  */
5712 static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
5713                                               hda_nid_t nid, int pin_type,
5714                                               int dac_idx)
5715 {
5716         /* set as output */
5717         struct alc_spec *spec = codec->spec;
5718         int idx; 
5719         
5720         if (spec->multiout.dac_nids[dac_idx] == 0x25)
5721                 idx = 4;
5722         else
5723                 idx = spec->multiout.dac_nids[dac_idx] - 2;
5724
5725         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5726                             pin_type);
5727         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
5728                             AMP_OUT_UNMUTE);
5729         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
5730
5731 }
5732
5733 static void alc883_auto_init_multi_out(struct hda_codec *codec)
5734 {
5735         struct alc_spec *spec = codec->spec;
5736         int i;
5737
5738         for (i = 0; i <= HDA_SIDE; i++) {
5739                 hda_nid_t nid = spec->autocfg.line_out_pins[i]; 
5740                 if (nid)
5741                         alc883_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
5742         }
5743 }
5744
5745 static void alc883_auto_init_hp_out(struct hda_codec *codec)
5746 {
5747         struct alc_spec *spec = codec->spec;
5748         hda_nid_t pin;
5749
5750         pin = spec->autocfg.hp_pins[0];
5751         if (pin) /* connect to front */
5752                 /* use dac 0 */
5753                 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
5754 }
5755
5756 #define alc883_is_input_pin(nid)        alc880_is_input_pin(nid)
5757 #define ALC883_PIN_CD_NID               ALC880_PIN_CD_NID
5758
5759 static void alc883_auto_init_analog_input(struct hda_codec *codec)
5760 {
5761         struct alc_spec *spec = codec->spec;
5762         int i;
5763
5764         for (i = 0; i < AUTO_PIN_LAST; i++) {
5765                 hda_nid_t nid = spec->autocfg.input_pins[i];
5766                 if (alc883_is_input_pin(nid)) {
5767                         snd_hda_codec_write(codec, nid, 0,
5768                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
5769                                             (i <= AUTO_PIN_FRONT_MIC ?
5770                                              PIN_VREF80 : PIN_IN));
5771                         if (nid != ALC883_PIN_CD_NID)
5772                                 snd_hda_codec_write(codec, nid, 0,
5773                                                     AC_VERB_SET_AMP_GAIN_MUTE,
5774                                                     AMP_OUT_MUTE);
5775                 }
5776         }
5777 }
5778
5779 /* almost identical with ALC880 parser... */
5780 static int alc883_parse_auto_config(struct hda_codec *codec)
5781 {
5782         struct alc_spec *spec = codec->spec;
5783         int err = alc880_parse_auto_config(codec);
5784
5785         if (err < 0)
5786                 return err;
5787         else if (err > 0)
5788                 /* hack - override the init verbs */
5789                 spec->init_verbs[0] = alc883_auto_init_verbs;
5790                 spec->mixers[spec->num_mixers] = alc883_capture_mixer;
5791                 spec->num_mixers++;
5792         return err;
5793 }
5794
5795 /* additional initialization for auto-configuration model */
5796 static void alc883_auto_init(struct hda_codec *codec)
5797 {
5798         alc883_auto_init_multi_out(codec);
5799         alc883_auto_init_hp_out(codec);
5800         alc883_auto_init_analog_input(codec);
5801 }
5802
5803 static int patch_alc883(struct hda_codec *codec)
5804 {
5805         struct alc_spec *spec;
5806         int err, board_config;
5807
5808         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5809         if (spec == NULL)
5810                 return -ENOMEM;
5811
5812         codec->spec = spec;
5813
5814         board_config = snd_hda_check_board_config(codec, ALC883_MODEL_LAST,
5815                                                   alc883_models,
5816                                                   alc883_cfg_tbl);
5817         if (board_config < 0) {
5818                 printk(KERN_INFO "hda_codec: Unknown model for ALC883, "
5819                        "trying auto-probe from BIOS...\n");
5820                 board_config = ALC883_AUTO;
5821         }
5822
5823         if (board_config == ALC883_AUTO) {
5824                 /* automatic parse from the BIOS config */
5825                 err = alc883_parse_auto_config(codec);
5826                 if (err < 0) {
5827                         alc_free(codec);
5828                         return err;
5829                 } else if (! err) {
5830                         printk(KERN_INFO
5831                                "hda_codec: Cannot set up configuration "
5832                                "from BIOS.  Using base mode...\n");
5833                         board_config = ALC883_3ST_2ch_DIG;
5834                 }
5835         }
5836
5837         if (board_config != ALC883_AUTO)
5838                 setup_preset(spec, &alc883_presets[board_config]);
5839
5840         spec->stream_name_analog = "ALC883 Analog";
5841         spec->stream_analog_playback = &alc883_pcm_analog_playback;
5842         spec->stream_analog_capture = &alc883_pcm_analog_capture;
5843
5844         spec->stream_name_digital = "ALC883 Digital";
5845         spec->stream_digital_playback = &alc883_pcm_digital_playback;
5846         spec->stream_digital_capture = &alc883_pcm_digital_capture;
5847
5848         if (! spec->adc_nids && spec->input_mux) {
5849                 spec->adc_nids = alc883_adc_nids;
5850                 spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
5851         }
5852
5853         codec->patch_ops = alc_patch_ops;
5854         if (board_config == ALC883_AUTO)
5855                 spec->init_hook = alc883_auto_init;
5856
5857         return 0;
5858 }
5859
5860 /*
5861  * ALC262 support
5862  */
5863
5864 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
5865 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
5866
5867 #define alc262_dac_nids         alc260_dac_nids
5868 #define alc262_adc_nids         alc882_adc_nids
5869 #define alc262_adc_nids_alt     alc882_adc_nids_alt
5870
5871 #define alc262_modes            alc260_modes
5872 #define alc262_capture_source   alc882_capture_source
5873
5874 static struct snd_kcontrol_new alc262_base_mixer[] = {
5875         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5876         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
5877         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5878         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5879         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5880         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5881         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5882         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5883         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
5884         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
5885         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
5886            HDA_CODEC_MUTE("PC Beelp Playback Switch", 0x0b, 0x05, HDA_INPUT), */
5887         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
5888         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5889         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
5890         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
5891         { } /* end */
5892 };
5893
5894 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
5895         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5896         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
5897         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5898         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5899         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5900         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5901         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5902         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5903         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
5904         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
5905         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
5906            HDA_CODEC_MUTE("PC Beelp Playback Switch", 0x0b, 0x05, HDA_INPUT), */
5907         /*HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),*/
5908         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5909         { } /* end */
5910 };
5911
5912 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
5913         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5914         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5915         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5916         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
5917         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
5918
5919         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5920         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5921         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
5922         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
5923         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5924         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5925         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5926         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5927         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
5928         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
5929         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
5930         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
5931         { } /* end */
5932 };
5933
5934 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
5935         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5936         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5937         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
5938         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5939         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
5940         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
5941         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
5942         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
5943         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
5944         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
5945         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5946         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5947         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
5948         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
5949         { } /* end */
5950 };
5951
5952 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
5953         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5954         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5955         { } /* end */
5956 };
5957
5958 #define alc262_capture_mixer            alc882_capture_mixer
5959 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
5960
5961 /*
5962  * generic initialization of ADC, input mixers and output mixers
5963  */
5964 static struct hda_verb alc262_init_verbs[] = {
5965         /*
5966          * Unmute ADC0-2 and set the default input to mic-in
5967          */
5968         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5969         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5970         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5971         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5972         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5973         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5974
5975         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5976          * mixer widget
5977          * Note: PASD motherboards uses the Line In 2 as the input for front panel
5978          * mic (mic 2)
5979          */
5980         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
5981         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5982         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5983         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
5984         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
5985         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
5986
5987         /*
5988          * Set up output mixers (0x0c - 0x0e)
5989          */
5990         /* set vol=0 to output mixers */
5991         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5992         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5993         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5994         /* set up input amps for analog loopback */
5995         /* Amp Indices: DAC = 0, mixer = 1 */
5996         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5997         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5998         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5999         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6000         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6001         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6002
6003         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
6004         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
6005         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
6006         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
6007         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
6008         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
6009
6010         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
6011         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
6012         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
6013         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
6014         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
6015         
6016         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6017         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
6018         
6019         /* FIXME: use matrix-type input source selection */
6020         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6021         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6022         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6023         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6024         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6025         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6026         /* Input mixer2 */
6027         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6028         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6029         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6030         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6031         /* Input mixer3 */
6032         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6033         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6034         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6035         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},      
6036
6037         { }
6038 };
6039
6040 static struct hda_verb alc262_hippo_unsol_verbs[] = {
6041         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
6042         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6043         {}
6044 };
6045
6046 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
6047         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
6048         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
6049         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
6050
6051         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
6052         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6053         {}
6054 };
6055
6056 /* mute/unmute internal speaker according to the hp jack and mute state */
6057 static void alc262_hippo_automute(struct hda_codec *codec, int force)
6058 {
6059         struct alc_spec *spec = codec->spec;
6060         unsigned int mute;
6061
6062         if (force || ! spec->sense_updated) {
6063                 unsigned int present;
6064                 /* need to execute and sync at first */
6065                 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
6066                 present = snd_hda_codec_read(codec, 0x15, 0,
6067                                          AC_VERB_GET_PIN_SENSE, 0);
6068                 spec->jack_present = (present & 0x80000000) != 0;
6069                 spec->sense_updated = 1;
6070         }
6071         if (spec->jack_present) {
6072                 /* mute internal speaker */
6073                 snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
6074                                          0x80, 0x80);
6075                 snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
6076                                          0x80, 0x80);
6077         } else {
6078                 /* unmute internal speaker if necessary */
6079                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
6080                 snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
6081                                          0x80, mute & 0x80);
6082                 mute = snd_hda_codec_amp_read(codec, 0x15, 1, HDA_OUTPUT, 0);
6083                 snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
6084                                          0x80, mute & 0x80);
6085         }
6086 }
6087
6088 /* unsolicited event for HP jack sensing */
6089 static void alc262_hippo_unsol_event(struct hda_codec *codec,
6090                                        unsigned int res)
6091 {
6092         if ((res >> 26) != ALC880_HP_EVENT)
6093                 return;
6094         alc262_hippo_automute(codec, 1);
6095 }
6096
6097 static void alc262_hippo1_automute(struct hda_codec *codec, int force)
6098 {
6099         struct alc_spec *spec = codec->spec;
6100         unsigned int mute;
6101
6102         if (force || ! spec->sense_updated) {
6103                 unsigned int present;
6104                 /* need to execute and sync at first */
6105                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
6106                 present = snd_hda_codec_read(codec, 0x1b, 0,
6107                                          AC_VERB_GET_PIN_SENSE, 0);
6108                 spec->jack_present = (present & 0x80000000) != 0;
6109                 spec->sense_updated = 1;
6110         }
6111         if (spec->jack_present) {
6112                 /* mute internal speaker */
6113                 snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
6114                                          0x80, 0x80);
6115                 snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
6116                                          0x80, 0x80);
6117         } else {
6118                 /* unmute internal speaker if necessary */
6119                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
6120                 snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
6121                                          0x80, mute & 0x80);
6122                 mute = snd_hda_codec_amp_read(codec, 0x1b, 1, HDA_OUTPUT, 0);
6123                 snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
6124                                          0x80, mute & 0x80);
6125         }
6126 }
6127
6128 /* unsolicited event for HP jack sensing */
6129 static void alc262_hippo1_unsol_event(struct hda_codec *codec,
6130                                        unsigned int res)
6131 {
6132         if ((res >> 26) != ALC880_HP_EVENT)
6133                 return;
6134         alc262_hippo1_automute(codec, 1);
6135 }
6136
6137 /*
6138  * fujitsu model
6139  *  0x14 = headphone/spdif-out, 0x15 = internal speaker
6140  */
6141
6142 #define ALC_HP_EVENT    0x37
6143
6144 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
6145         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
6146         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6147         {}
6148 };
6149
6150 static struct hda_input_mux alc262_fujitsu_capture_source = {
6151         .num_items = 2,
6152         .items = {
6153                 { "Mic", 0x0 },
6154                 { "CD", 0x4 },
6155         },
6156 };
6157
6158 static struct hda_input_mux alc262_HP_capture_source = {
6159         .num_items = 5,
6160         .items = {
6161                 { "Mic", 0x0 },
6162                 { "Front Mic", 0x3 },
6163                 { "Line", 0x2 },
6164                 { "CD", 0x4 },
6165                 { "AUX IN", 0x6 },
6166         },
6167 };
6168
6169 /* mute/unmute internal speaker according to the hp jack and mute state */
6170 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
6171 {
6172         struct alc_spec *spec = codec->spec;
6173         unsigned int mute;
6174
6175         if (force || ! spec->sense_updated) {
6176                 unsigned int present;
6177                 /* need to execute and sync at first */
6178                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
6179                 present = snd_hda_codec_read(codec, 0x14, 0,
6180                                          AC_VERB_GET_PIN_SENSE, 0);
6181                 spec->jack_present = (present & 0x80000000) != 0;
6182                 spec->sense_updated = 1;
6183         }
6184         if (spec->jack_present) {
6185                 /* mute internal speaker */
6186                 snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
6187                                          0x80, 0x80);
6188                 snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
6189                                          0x80, 0x80);
6190         } else {
6191                 /* unmute internal speaker if necessary */
6192                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
6193                 snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
6194                                          0x80, mute & 0x80);
6195                 mute = snd_hda_codec_amp_read(codec, 0x14, 1, HDA_OUTPUT, 0);
6196                 snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
6197                                          0x80, mute & 0x80);
6198         }
6199 }
6200
6201 /* unsolicited event for HP jack sensing */
6202 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
6203                                        unsigned int res)
6204 {
6205         if ((res >> 26) != ALC_HP_EVENT)
6206                 return;
6207         alc262_fujitsu_automute(codec, 1);
6208 }
6209
6210 /* bind volumes of both NID 0x0c and 0x0d */
6211 static int alc262_fujitsu_master_vol_put(struct snd_kcontrol *kcontrol,
6212                                          struct snd_ctl_elem_value *ucontrol)
6213 {
6214         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6215         long *valp = ucontrol->value.integer.value;
6216         int change;
6217
6218         change = snd_hda_codec_amp_update(codec, 0x0c, 0, HDA_OUTPUT, 0,
6219                                           0x7f, valp[0] & 0x7f);
6220         change |= snd_hda_codec_amp_update(codec, 0x0c, 1, HDA_OUTPUT, 0,
6221                                            0x7f, valp[1] & 0x7f);
6222         snd_hda_codec_amp_update(codec, 0x0d, 0, HDA_OUTPUT, 0,
6223                                  0x7f, valp[0] & 0x7f);
6224         snd_hda_codec_amp_update(codec, 0x0d, 1, HDA_OUTPUT, 0,
6225                                  0x7f, valp[1] & 0x7f);
6226         return change;
6227 }
6228
6229 /* bind hp and internal speaker mute (with plug check) */
6230 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
6231                                          struct snd_ctl_elem_value *ucontrol)
6232 {
6233         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6234         long *valp = ucontrol->value.integer.value;
6235         int change;
6236
6237         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
6238                                           0x80, valp[0] ? 0 : 0x80);
6239         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
6240                                            0x80, valp[1] ? 0 : 0x80);
6241         if (change || codec->in_resume)
6242                 alc262_fujitsu_automute(codec, codec->in_resume);
6243         return change;
6244 }
6245
6246 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
6247         {
6248                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6249                 .name = "Master Playback Volume",
6250                 .info = snd_hda_mixer_amp_volume_info,
6251                 .get = snd_hda_mixer_amp_volume_get,
6252                 .put = alc262_fujitsu_master_vol_put,
6253                 .tlv = { .c = snd_hda_mixer_amp_tlv },
6254                 .private_value = HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
6255         },
6256         {
6257                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6258                 .name = "Master Playback Switch",
6259                 .info = snd_hda_mixer_amp_switch_info,
6260                 .get = snd_hda_mixer_amp_switch_get,
6261                 .put = alc262_fujitsu_master_sw_put,
6262                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
6263         },
6264         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6265         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6266         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6267         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6268         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6269         { } /* end */
6270 };
6271
6272 /* additional init verbs for Benq laptops */
6273 static struct hda_verb alc262_EAPD_verbs[] = {
6274         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
6275         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
6276         {}
6277 };
6278
6279 /* add playback controls from the parsed DAC table */
6280 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec, const struct auto_pin_cfg *cfg)
6281 {
6282         hda_nid_t nid;
6283         int err;
6284
6285         spec->multiout.num_dacs = 1;    /* only use one dac */
6286         spec->multiout.dac_nids = spec->private_dac_nids;
6287         spec->multiout.dac_nids[0] = 2;
6288
6289         nid = cfg->line_out_pins[0];
6290         if (nid) {
6291                 if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, "Front Playback Volume",
6292                                        HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT))) < 0)
6293                         return err;
6294                 if ((err = add_control(spec, ALC_CTL_WIDGET_MUTE, "Front Playback Switch",
6295                                        HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
6296                         return err;
6297         }
6298
6299         nid = cfg->speaker_pins[0];
6300         if (nid) {
6301                 if (nid == 0x16) {
6302                         if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, "Speaker Playback Volume",
6303                                                HDA_COMPOSE_AMP_VAL(0x0e, 2, 0, HDA_OUTPUT))) < 0)
6304                                 return err;
6305                         if ((err = add_control(spec, ALC_CTL_WIDGET_MUTE, "Speaker Playback Switch",
6306                                                HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
6307                                 return err;
6308                 } else {
6309                         if ((err = add_control(spec, ALC_CTL_WIDGET_MUTE, "Speaker Playback Switch",
6310                                                HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
6311                                 return err;
6312                 }
6313         }
6314         nid = cfg->hp_pins[0];
6315         if (nid) {
6316                 /* spec->multiout.hp_nid = 2; */
6317                 if (nid == 0x16) {
6318                         if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, "Headphone Playback Volume",
6319                                                HDA_COMPOSE_AMP_VAL(0x0e, 2, 0, HDA_OUTPUT))) < 0)
6320                                 return err;
6321                         if ((err = add_control(spec, ALC_CTL_WIDGET_MUTE, "Headphone Playback Switch",
6322                                                HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
6323                                 return err;
6324                 } else {
6325                         if ((err = add_control(spec, ALC_CTL_WIDGET_MUTE, "Headphone Playback Switch",
6326                                                HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
6327                                 return err;
6328                 }
6329         }
6330         return 0;       
6331 }
6332
6333 /* identical with ALC880 */
6334 #define alc262_auto_create_analog_input_ctls alc880_auto_create_analog_input_ctls
6335
6336 /*
6337  * generic initialization of ADC, input mixers and output mixers
6338  */
6339 static struct hda_verb alc262_volume_init_verbs[] = {
6340         /*
6341          * Unmute ADC0-2 and set the default input to mic-in
6342          */
6343         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6344         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6345         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6346         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6347         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6348         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6349
6350         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
6351          * mixer widget
6352          * Note: PASD motherboards uses the Line In 2 as the input for front panel
6353          * mic (mic 2)
6354          */
6355         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
6356         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6357         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6358         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6359         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
6360         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
6361
6362         /*
6363          * Set up output mixers (0x0c - 0x0f)
6364          */
6365         /* set vol=0 to output mixers */
6366         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6367         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6368         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6369         
6370         /* set up input amps for analog loopback */
6371         /* Amp Indices: DAC = 0, mixer = 1 */
6372         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6373         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6374         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6375         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6376         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6377         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6378
6379         /* FIXME: use matrix-type input source selection */
6380         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6381         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6382         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6383         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6384         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6385         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6386         /* Input mixer2 */
6387         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6388         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6389         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6390         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6391         /* Input mixer3 */
6392         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6393         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6394         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6395         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6396
6397         { }
6398 };
6399
6400 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
6401         /*
6402          * Unmute ADC0-2 and set the default input to mic-in
6403          */
6404         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6405         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6406         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6407         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6408         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6409         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6410
6411         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
6412          * mixer widget
6413          * Note: PASD motherboards uses the Line In 2 as the input for front panel
6414          * mic (mic 2)
6415          */
6416         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
6417         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6418         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6419         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6420         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
6421         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
6422         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
6423         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(6)},
6424         
6425         /*
6426          * Set up output mixers (0x0c - 0x0e)
6427          */
6428         /* set vol=0 to output mixers */
6429         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6430         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6431         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6432
6433         /* set up input amps for analog loopback */
6434         /* Amp Indices: DAC = 0, mixer = 1 */
6435         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6436         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6437         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6438         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6439         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6440         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6441
6442         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
6443         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6444         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6445
6446         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6447         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6448
6449         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
6450         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6451
6452         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
6453         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
6454         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
6455         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
6456         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
6457
6458         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
6459         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
6460         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
6461         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
6462         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
6463         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
6464
6465
6466         /* FIXME: use matrix-type input source selection */
6467         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6468         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6469         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6470         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
6471         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
6472         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
6473         /* Input mixer2 */
6474         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6475         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
6476         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
6477         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
6478         /* Input mixer3 */
6479         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6480         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
6481         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
6482         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
6483
6484         { }
6485 };
6486
6487 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
6488         /*
6489          * Unmute ADC0-2 and set the default input to mic-in
6490          */
6491         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6492         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6493         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6494         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6495         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6496         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6497
6498         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
6499          * mixer widget
6500          * Note: PASD motherboards uses the Line In 2 as the input for front
6501          * panel mic (mic 2)
6502          */
6503         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
6504         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6505         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6506         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6507         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
6508         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
6509         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
6510         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(6)},
6511         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(7)},
6512         /*
6513          * Set up output mixers (0x0c - 0x0e)
6514          */
6515         /* set vol=0 to output mixers */
6516         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6517         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6518         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6519
6520         /* set up input amps for analog loopback */
6521         /* Amp Indices: DAC = 0, mixer = 1 */
6522         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6523         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6524         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6525         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6526         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6527         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6528
6529
6530         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
6531         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
6532         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
6533         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
6534         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
6535         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
6536         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
6537
6538         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6539         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6540
6541         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
6542         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
6543
6544         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
6545         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
6546         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
6547         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
6548         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
6549         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
6550
6551         /* FIXME: use matrix-type input source selection */
6552         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6553         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6554         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
6555         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
6556         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
6557         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
6558         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
6559         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
6560         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
6561         /* Input mixer2 */
6562         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6563         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
6564         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
6565         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
6566         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
6567         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
6568         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
6569         /* Input mixer3 */
6570         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6571         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
6572         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
6573         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
6574         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
6575         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
6576         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
6577
6578         { }
6579 };
6580
6581 /* pcm configuration: identiacal with ALC880 */
6582 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
6583 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
6584 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
6585 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
6586
6587 /*
6588  * BIOS auto configuration
6589  */
6590 static int alc262_parse_auto_config(struct hda_codec *codec)
6591 {
6592         struct alc_spec *spec = codec->spec;
6593         int err;
6594         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
6595
6596         if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
6597                                                 alc262_ignore)) < 0)
6598                 return err;
6599         if (! spec->autocfg.line_outs)
6600                 return 0; /* can't find valid BIOS pin config */
6601         if ((err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
6602             (err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
6603                 return err;
6604
6605         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
6606
6607         if (spec->autocfg.dig_out_pin)
6608                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
6609         if (spec->autocfg.dig_in_pin)
6610                 spec->dig_in_nid = ALC262_DIGIN_NID;
6611
6612         if (spec->kctl_alloc)
6613                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
6614
6615         spec->init_verbs[spec->num_init_verbs++] = alc262_volume_init_verbs;
6616         spec->num_mux_defs = 1;
6617         spec->input_mux = &spec->private_imux;
6618
6619         return 1;
6620 }
6621
6622 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
6623 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
6624 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
6625
6626
6627 /* init callback for auto-configuration model -- overriding the default init */
6628 static void alc262_auto_init(struct hda_codec *codec)
6629 {
6630         alc262_auto_init_multi_out(codec);
6631         alc262_auto_init_hp_out(codec);
6632         alc262_auto_init_analog_input(codec);
6633 }
6634
6635 /*
6636  * configuration and preset
6637  */
6638 static const char *alc262_models[ALC262_MODEL_LAST] = {
6639         [ALC262_BASIC]          = "basic",
6640         [ALC262_HIPPO]          = "hippo",
6641         [ALC262_HIPPO_1]        = "hippo_1",
6642         [ALC262_FUJITSU]        = "fujitsu",
6643         [ALC262_HP_BPC]         = "hp-bpc",
6644         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
6645         [ALC262_BENQ_ED8]       = "benq",
6646         [ALC262_AUTO]           = "auto",
6647 };
6648
6649 static struct snd_pci_quirk alc262_cfg_tbl[] = {
6650         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
6651         SND_PCI_QUIRK(0x103c, 0x12fe, "HP xw9400", ALC262_HP_BPC),
6652         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
6653         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
6654         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
6655         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
6656         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
6657         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
6658         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
6659         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
6660         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
6661         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
6662         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
6663         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
6664         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
6665         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
6666         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
6667         {}
6668 };
6669
6670 static struct alc_config_preset alc262_presets[] = {
6671         [ALC262_BASIC] = {
6672                 .mixers = { alc262_base_mixer },
6673                 .init_verbs = { alc262_init_verbs },
6674                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
6675                 .dac_nids = alc262_dac_nids,
6676                 .hp_nid = 0x03,
6677                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
6678                 .channel_mode = alc262_modes,
6679                 .input_mux = &alc262_capture_source,
6680         },
6681         [ALC262_HIPPO] = {
6682                 .mixers = { alc262_base_mixer },
6683                 .init_verbs = { alc262_init_verbs, alc262_hippo_unsol_verbs},
6684                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
6685                 .dac_nids = alc262_dac_nids,
6686                 .hp_nid = 0x03,
6687                 .dig_out_nid = ALC262_DIGOUT_NID,
6688                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
6689                 .channel_mode = alc262_modes,
6690                 .input_mux = &alc262_capture_source,
6691                 .unsol_event = alc262_hippo_unsol_event,
6692         },
6693         [ALC262_HIPPO_1] = {
6694                 .mixers = { alc262_hippo1_mixer },
6695                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
6696                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
6697                 .dac_nids = alc262_dac_nids,
6698                 .hp_nid = 0x02,
6699                 .dig_out_nid = ALC262_DIGOUT_NID,
6700                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
6701                 .channel_mode = alc262_modes,
6702                 .input_mux = &alc262_capture_source,
6703                 .unsol_event = alc262_hippo1_unsol_event,
6704         },
6705         [ALC262_FUJITSU] = {
6706                 .mixers = { alc262_fujitsu_mixer },
6707                 .init_verbs = { alc262_init_verbs, alc262_fujitsu_unsol_verbs },
6708                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
6709                 .dac_nids = alc262_dac_nids,
6710                 .hp_nid = 0x03,
6711                 .dig_out_nid = ALC262_DIGOUT_NID,
6712                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
6713                 .channel_mode = alc262_modes,
6714                 .input_mux = &alc262_fujitsu_capture_source,
6715                 .unsol_event = alc262_fujitsu_unsol_event,
6716         },
6717         [ALC262_HP_BPC] = {
6718                 .mixers = { alc262_HP_BPC_mixer },
6719                 .init_verbs = { alc262_HP_BPC_init_verbs },
6720                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
6721                 .dac_nids = alc262_dac_nids,
6722                 .hp_nid = 0x03,
6723                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
6724                 .channel_mode = alc262_modes,
6725                 .input_mux = &alc262_HP_capture_source,
6726         },      
6727         [ALC262_HP_BPC_D7000_WF] = {
6728                 .mixers = { alc262_HP_BPC_WildWest_mixer },
6729                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
6730                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
6731                 .dac_nids = alc262_dac_nids,
6732                 .hp_nid = 0x03,
6733                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
6734                 .channel_mode = alc262_modes,
6735                 .input_mux = &alc262_HP_capture_source,
6736         },      
6737         [ALC262_HP_BPC_D7000_WL] = {
6738                 .mixers = { alc262_HP_BPC_WildWest_mixer,
6739                             alc262_HP_BPC_WildWest_option_mixer },
6740                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
6741                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
6742                 .dac_nids = alc262_dac_nids,
6743                 .hp_nid = 0x03,
6744                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
6745                 .channel_mode = alc262_modes,
6746                 .input_mux = &alc262_HP_capture_source,
6747         },      
6748         [ALC262_BENQ_ED8] = {
6749                 .mixers = { alc262_base_mixer },
6750                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
6751                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
6752                 .dac_nids = alc262_dac_nids,
6753                 .hp_nid = 0x03,
6754                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
6755                 .channel_mode = alc262_modes,
6756                 .input_mux = &alc262_capture_source,
6757         },              
6758 };
6759
6760 static int patch_alc262(struct hda_codec *codec)
6761 {
6762         struct alc_spec *spec;
6763         int board_config;
6764         int err;
6765
6766         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6767         if (spec == NULL)
6768                 return -ENOMEM;
6769
6770         codec->spec = spec;
6771 #if 0
6772         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is under-run */
6773         {
6774         int tmp;
6775         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
6776         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
6777         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
6778         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
6779         }
6780 #endif
6781
6782         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
6783                                                   alc262_models,
6784                                                   alc262_cfg_tbl);
6785
6786         if (board_config < 0) {
6787                 printk(KERN_INFO "hda_codec: Unknown model for ALC262, "
6788                        "trying auto-probe from BIOS...\n");
6789                 board_config = ALC262_AUTO;
6790         }
6791
6792         if (board_config == ALC262_AUTO) {
6793                 /* automatic parse from the BIOS config */
6794                 err = alc262_parse_auto_config(codec);
6795                 if (err < 0) {
6796                         alc_free(codec);
6797                         return err;
6798                 } else if (! err) {
6799                         printk(KERN_INFO
6800                                "hda_codec: Cannot set up configuration "
6801                                "from BIOS.  Using base mode...\n");
6802                         board_config = ALC262_BASIC;
6803                 }
6804         }
6805
6806         if (board_config != ALC262_AUTO)
6807                 setup_preset(spec, &alc262_presets[board_config]);
6808
6809         spec->stream_name_analog = "ALC262 Analog";
6810         spec->stream_analog_playback = &alc262_pcm_analog_playback;
6811         spec->stream_analog_capture = &alc262_pcm_analog_capture;
6812                 
6813         spec->stream_name_digital = "ALC262 Digital";
6814         spec->stream_digital_playback = &alc262_pcm_digital_playback;
6815         spec->stream_digital_capture = &alc262_pcm_digital_capture;
6816
6817         if (! spec->adc_nids && spec->input_mux) {
6818                 /* check whether NID 0x07 is valid */
6819                 unsigned int wcap = get_wcaps(codec, 0x07);
6820
6821                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */
6822                 if (wcap != AC_WID_AUD_IN) {
6823                         spec->adc_nids = alc262_adc_nids_alt;
6824                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
6825                         spec->mixers[spec->num_mixers] = alc262_capture_alt_mixer;
6826                         spec->num_mixers++;
6827                 } else {
6828                         spec->adc_nids = alc262_adc_nids;
6829                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
6830                         spec->mixers[spec->num_mixers] = alc262_capture_mixer;
6831                         spec->num_mixers++;
6832                 }
6833         }
6834
6835         codec->patch_ops = alc_patch_ops;
6836         if (board_config == ALC262_AUTO)
6837                 spec->init_hook = alc262_auto_init;
6838                 
6839         return 0;
6840 }
6841
6842 /*
6843  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
6844  */
6845
6846 /*
6847  * set the path ways for 2 channel output
6848  * need to set the codec line out and mic 1 pin widgets to inputs
6849  */
6850 static struct hda_verb alc861_threestack_ch2_init[] = {
6851         /* set pin widget 1Ah (line in) for input */
6852         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
6853         /* set pin widget 18h (mic1/2) for input, for mic also enable the vref */
6854         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
6855
6856         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
6857 #if 0
6858         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
6859         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
6860 #endif
6861         { } /* end */
6862 };
6863 /*
6864  * 6ch mode
6865  * need to set the codec line out and mic 1 pin widgets to outputs
6866  */
6867 static struct hda_verb alc861_threestack_ch6_init[] = {
6868         /* set pin widget 1Ah (line in) for output (Back Surround)*/
6869         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
6870         /* set pin widget 18h (mic1) for output (CLFE)*/
6871         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
6872
6873         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
6874         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
6875
6876         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
6877 #if 0
6878         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
6879         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
6880 #endif
6881         { } /* end */
6882 };
6883
6884 static struct hda_channel_mode alc861_threestack_modes[2] = {
6885         { 2, alc861_threestack_ch2_init },
6886         { 6, alc861_threestack_ch6_init },
6887 };
6888 /* Set mic1 as input and unmute the mixer */
6889 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
6890         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
6891         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
6892         { } /* end */
6893 };
6894 /* Set mic1 as output and mute mixer */
6895 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
6896         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
6897         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
6898         { } /* end */
6899 };
6900
6901 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
6902         { 2, alc861_uniwill_m31_ch2_init },
6903         { 4, alc861_uniwill_m31_ch4_init },
6904 };
6905
6906 /* Set mic1 and line-in as input and unmute the mixer */
6907 static struct hda_verb alc861_asus_ch2_init[] = {
6908         /* set pin widget 1Ah (line in) for input */
6909         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
6910         /* set pin widget 18h (mic1/2) for input, for mic also enable the vref */
6911         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
6912
6913         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
6914 #if 0
6915         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
6916         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
6917 #endif
6918         { } /* end */
6919 };
6920 /* Set mic1 nad line-in as output and mute mixer */
6921 static struct hda_verb alc861_asus_ch6_init[] = {
6922         /* set pin widget 1Ah (line in) for output (Back Surround)*/
6923         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
6924         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
6925         /* set pin widget 18h (mic1) for output (CLFE)*/
6926         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
6927         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
6928         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
6929         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
6930
6931         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
6932 #if 0
6933         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
6934         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
6935 #endif
6936         { } /* end */
6937 };
6938
6939 static struct hda_channel_mode alc861_asus_modes[2] = {
6940         { 2, alc861_asus_ch2_init },
6941         { 6, alc861_asus_ch6_init },
6942 };
6943
6944 /* patch-ALC861 */
6945
6946 static struct snd_kcontrol_new alc861_base_mixer[] = {
6947         /* output mixer control */
6948         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
6949         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
6950         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
6951         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
6952         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
6953
6954         /*Input mixer control */
6955         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
6956            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
6957         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
6958         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
6959         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
6960         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
6961         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
6962         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
6963         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
6964         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
6965  
6966         /* Capture mixer control */
6967         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6968         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6969         {
6970                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6971                 .name = "Capture Source",
6972                 .count = 1,
6973                 .info = alc_mux_enum_info,
6974                 .get = alc_mux_enum_get,
6975                 .put = alc_mux_enum_put,
6976         },
6977         { } /* end */
6978 };
6979
6980 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
6981         /* output mixer control */
6982         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
6983         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
6984         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
6985         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
6986         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
6987
6988         /* Input mixer control */
6989         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
6990            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
6991         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
6992         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
6993         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
6994         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
6995         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
6996         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
6997         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
6998         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
6999  
7000         /* Capture mixer control */
7001         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7002         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7003         {
7004                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7005                 .name = "Capture Source",
7006                 .count = 1,
7007                 .info = alc_mux_enum_info,
7008                 .get = alc_mux_enum_get,
7009                 .put = alc_mux_enum_put,
7010         },
7011         {
7012                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7013                 .name = "Channel Mode",
7014                 .info = alc_ch_mode_info,
7015                 .get = alc_ch_mode_get,
7016                 .put = alc_ch_mode_put,
7017                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
7018         },
7019         { } /* end */
7020 };
7021
7022 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
7023         /* output mixer control */
7024         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
7025         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
7026         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
7027         
7028         /*Capture mixer control */
7029         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7030         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7031         {
7032                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7033                 .name = "Capture Source",
7034                 .count = 1,
7035                 .info = alc_mux_enum_info,
7036                 .get = alc_mux_enum_get,
7037                 .put = alc_mux_enum_put,
7038         },
7039
7040         { } /* end */
7041 };      
7042
7043 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
7044         /* output mixer control */
7045         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
7046         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
7047         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
7048         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
7049         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
7050
7051         /* Input mixer control */
7052         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
7053            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
7054         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
7055         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
7056         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
7057         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
7058         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
7059         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
7060         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
7061         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
7062  
7063         /* Capture mixer control */
7064         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7065         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7066         {
7067                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7068                 .name = "Capture Source",
7069                 .count = 1,
7070                 .info = alc_mux_enum_info,
7071                 .get = alc_mux_enum_get,
7072                 .put = alc_mux_enum_put,
7073         },
7074         {
7075                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7076                 .name = "Channel Mode",
7077                 .info = alc_ch_mode_info,
7078                 .get = alc_ch_mode_get,
7079                 .put = alc_ch_mode_put,
7080                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
7081         },
7082         { } /* end */
7083 };                      
7084
7085 static struct snd_kcontrol_new alc861_asus_mixer[] = {
7086         /* output mixer control */
7087         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
7088         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
7089         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
7090         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
7091         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
7092
7093         /* Input mixer control */
7094         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
7095         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7096         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
7097         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
7098         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
7099         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
7100         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
7101         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
7102         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
7103         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT), /* was HDA_INPUT (why?) */
7104  
7105         /* Capture mixer control */
7106         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7107         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7108         {
7109                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7110                 .name = "Capture Source",
7111                 .count = 1,
7112                 .info = alc_mux_enum_info,
7113                 .get = alc_mux_enum_get,
7114                 .put = alc_mux_enum_put,
7115         },
7116         {
7117                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7118                 .name = "Channel Mode",
7119                 .info = alc_ch_mode_info,
7120                 .get = alc_ch_mode_get,
7121                 .put = alc_ch_mode_put,
7122                 .private_value = ARRAY_SIZE(alc861_asus_modes),
7123         },
7124         { }
7125 };
7126
7127 /* additional mixer */
7128 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
7129         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
7130         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
7131         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x23, 0x0, HDA_OUTPUT),
7132         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x23, 0x0, HDA_OUTPUT),
7133         { }
7134 };
7135
7136 /*
7137  * generic initialization of ADC, input mixers and output mixers
7138  */
7139 static struct hda_verb alc861_base_init_verbs[] = {
7140         /*
7141          * Unmute ADC0 and set the default input to mic-in
7142          */
7143         /* port-A for surround (rear panel) */
7144         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
7145         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
7146         /* port-B for mic-in (rear panel) with vref */
7147         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
7148         /* port-C for line-in (rear panel) */
7149         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
7150         /* port-D for Front */
7151         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
7152         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
7153         /* port-E for HP out (front panel) */
7154         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
7155         /* route front PCM to HP */
7156         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
7157         /* port-F for mic-in (front panel) with vref */
7158         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
7159         /* port-G for CLFE (rear panel) */
7160         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
7161         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
7162         /* port-H for side (rear panel) */
7163         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
7164         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
7165         /* CD-in */
7166         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
7167         /* route front mic to ADC1*/
7168         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7169         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7170         
7171         /* Unmute DAC0~3 & spdif out*/
7172         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7173         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7174         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7175         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7176         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7177         
7178         /* Unmute Mixer 14 (mic) 1c (Line in)*/
7179         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7180         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7181         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7182         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7183         
7184         /* Unmute Stereo Mixer 15 */
7185         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7186         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7187         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7188         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c          }, //Output 0~12 step
7189
7190         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7191         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7192         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7193         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7194         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7195         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7196         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7197         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7198         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, // hp used DAC 3 (Front)
7199         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7200
7201         { }
7202 };
7203
7204 static struct hda_verb alc861_threestack_init_verbs[] = {
7205         /*
7206          * Unmute ADC0 and set the default input to mic-in
7207          */
7208         /* port-A for surround (rear panel) */
7209         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
7210         /* port-B for mic-in (rear panel) with vref */
7211         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
7212         /* port-C for line-in (rear panel) */
7213         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
7214         /* port-D for Front */
7215         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
7216         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
7217         /* port-E for HP out (front panel) */
7218         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
7219         /* route front PCM to HP */
7220         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
7221         /* port-F for mic-in (front panel) with vref */
7222         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
7223         /* port-G for CLFE (rear panel) */
7224         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
7225         /* port-H for side (rear panel) */
7226         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
7227         /* CD-in */
7228         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
7229         /* route front mic to ADC1*/
7230         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7231         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7232         /* Unmute DAC0~3 & spdif out*/
7233         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7234         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7235         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7236         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7237         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7238         
7239         /* Unmute Mixer 14 (mic) 1c (Line in)*/
7240         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7241         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7242         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7243         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7244         
7245         /* Unmute Stereo Mixer 15 */
7246         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7247         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7248         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7249         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c          }, //Output 0~12 step
7250
7251         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7252         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7253         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7254         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7255         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7256         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7257         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7258         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7259         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, // hp used DAC 3 (Front)
7260         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7261         { }
7262 };
7263
7264 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
7265         /*
7266          * Unmute ADC0 and set the default input to mic-in
7267          */
7268         /* port-A for surround (rear panel) */
7269         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
7270         /* port-B for mic-in (rear panel) with vref */
7271         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
7272         /* port-C for line-in (rear panel) */
7273         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
7274         /* port-D for Front */
7275         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
7276         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
7277         /* port-E for HP out (front panel) */
7278         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 }, // this has to be set to VREF80
7279         /* route front PCM to HP */
7280         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
7281         /* port-F for mic-in (front panel) with vref */
7282         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
7283         /* port-G for CLFE (rear panel) */
7284         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
7285         /* port-H for side (rear panel) */
7286         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
7287         /* CD-in */
7288         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
7289         /* route front mic to ADC1*/
7290         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7291         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7292         /* Unmute DAC0~3 & spdif out*/
7293         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7294         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7295         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7296         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7297         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7298         
7299         /* Unmute Mixer 14 (mic) 1c (Line in)*/
7300         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7301         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7302         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7303         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7304         
7305         /* Unmute Stereo Mixer 15 */
7306         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7307         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7308         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7309         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c          }, //Output 0~12 step
7310
7311         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7312         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7313         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7314         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7315         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7316         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7317         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7318         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7319         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, // hp used DAC 3 (Front)
7320         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7321         { }
7322 };
7323
7324 static struct hda_verb alc861_asus_init_verbs[] = {
7325         /*
7326          * Unmute ADC0 and set the default input to mic-in
7327          */
7328         /* port-A for surround (rear panel) | according to codec#0 this is the HP jack*/
7329         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
7330         /* route front PCM to HP */
7331         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
7332         /* port-B for mic-in (rear panel) with vref */
7333         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
7334         /* port-C for line-in (rear panel) */
7335         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
7336         /* port-D for Front */
7337         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
7338         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
7339         /* port-E for HP out (front panel) */
7340         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 }, /* this has to be set to VREF80 */
7341         /* route front PCM to HP */
7342         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
7343         /* port-F for mic-in (front panel) with vref */
7344         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
7345         /* port-G for CLFE (rear panel) */
7346         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
7347         /* port-H for side (rear panel) */
7348         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
7349         /* CD-in */
7350         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
7351         /* route front mic to ADC1*/
7352         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7353         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7354         /* Unmute DAC0~3 & spdif out*/
7355         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7356         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7357         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7358         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7359         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7360         /* Unmute Mixer 14 (mic) 1c (Line in)*/
7361         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7362         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7363         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7364         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7365         
7366         /* Unmute Stereo Mixer 15 */
7367         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7368         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7369         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7370         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c          }, /* Output 0~12 step */
7371
7372         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7373         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7374         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7375         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7376         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7377         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7378         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7379         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7380         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, /* hp used DAC 3 (Front) */
7381         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7382         { }
7383 };
7384
7385 /* additional init verbs for ASUS laptops */
7386 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
7387         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
7388         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
7389         { }
7390 };
7391
7392 /*
7393  * generic initialization of ADC, input mixers and output mixers
7394  */
7395 static struct hda_verb alc861_auto_init_verbs[] = {
7396         /*
7397          * Unmute ADC0 and set the default input to mic-in
7398          */
7399 //      {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7400         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7401         
7402         /* Unmute DAC0~3 & spdif out*/
7403         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7404         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7405         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7406         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7407         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7408         
7409         /* Unmute Mixer 14 (mic) 1c (Line in)*/
7410         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7411         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7412         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7413         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7414         
7415         /* Unmute Stereo Mixer 15 */
7416         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7417         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7418         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7419         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
7420
7421         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7422         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7423         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7424         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7425         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7426         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7427         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7428         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7429
7430         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7431         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7432         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},    
7433         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},            
7434         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7435         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7436         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},    
7437         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},    
7438
7439         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  // set Mic 1
7440
7441         { }
7442 };
7443
7444 static struct hda_verb alc861_toshiba_init_verbs[] = {
7445         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
7446         
7447         { }
7448 };
7449
7450 /* toggle speaker-output according to the hp-jack state */
7451 static void alc861_toshiba_automute(struct hda_codec *codec)
7452 {
7453         unsigned int present;
7454
7455         present = snd_hda_codec_read(codec, 0x0f, 0,
7456                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7457         snd_hda_codec_amp_update(codec, 0x16, 0, HDA_INPUT, 0,
7458                                  0x80, present ? 0x80 : 0);
7459         snd_hda_codec_amp_update(codec, 0x16, 1, HDA_INPUT, 0,
7460                                  0x80, present ? 0x80 : 0);
7461         snd_hda_codec_amp_update(codec, 0x1a, 0, HDA_INPUT, 3,
7462                                  0x80, present ? 0 : 0x80);
7463         snd_hda_codec_amp_update(codec, 0x1a, 1, HDA_INPUT, 3,
7464                                  0x80, present ? 0 : 0x80);
7465 }
7466
7467 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
7468                                        unsigned int res)
7469 {
7470         /* Looks like the unsol event is incompatible with the standard
7471          * definition.  6bit tag is placed at 26 bit!
7472          */
7473         if ((res >> 26) == ALC880_HP_EVENT)
7474                 alc861_toshiba_automute(codec);
7475 }
7476
7477 /* pcm configuration: identiacal with ALC880 */
7478 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
7479 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
7480 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
7481 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
7482
7483
7484 #define ALC861_DIGOUT_NID       0x07
7485
7486 static struct hda_channel_mode alc861_8ch_modes[1] = {
7487         { 8, NULL }
7488 };
7489
7490 static hda_nid_t alc861_dac_nids[4] = {
7491         /* front, surround, clfe, side */
7492         0x03, 0x06, 0x05, 0x04
7493 };
7494
7495 static hda_nid_t alc660_dac_nids[3] = {
7496         /* front, clfe, surround */
7497         0x03, 0x05, 0x06
7498 };
7499
7500 static hda_nid_t alc861_adc_nids[1] = {
7501         /* ADC0-2 */
7502         0x08,
7503 };
7504
7505 static struct hda_input_mux alc861_capture_source = {
7506         .num_items = 5,
7507         .items = {
7508                 { "Mic", 0x0 },
7509                 { "Front Mic", 0x3 },
7510                 { "Line", 0x1 },
7511                 { "CD", 0x4 },
7512                 { "Mixer", 0x5 },
7513         },
7514 };
7515
7516 /* fill in the dac_nids table from the parsed pin configuration */
7517 static int alc861_auto_fill_dac_nids(struct alc_spec *spec, const struct auto_pin_cfg *cfg)
7518 {
7519         int i;
7520         hda_nid_t nid;
7521
7522         spec->multiout.dac_nids = spec->private_dac_nids;
7523         for (i = 0; i < cfg->line_outs; i++) {
7524                 nid = cfg->line_out_pins[i];
7525                 if (nid) {
7526                         if (i >= ARRAY_SIZE(alc861_dac_nids))
7527                                 continue;
7528                         spec->multiout.dac_nids[i] = alc861_dac_nids[i];
7529                 }
7530         }
7531         spec->multiout.num_dacs = cfg->line_outs;
7532         return 0;
7533 }
7534
7535 /* add playback controls from the parsed DAC table */
7536 static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
7537                                              const struct auto_pin_cfg *cfg)
7538 {
7539         char name[32];
7540         static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
7541         hda_nid_t nid;
7542         int i, idx, err;
7543
7544         for (i = 0; i < cfg->line_outs; i++) {
7545                 nid = spec->multiout.dac_nids[i];
7546                 if (! nid)
7547                         continue;
7548                 if (nid == 0x05) {
7549                         /* Center/LFE */
7550                         if ((err = add_control(spec, ALC_CTL_BIND_MUTE, "Center Playback Switch",
7551                                                HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
7552                                 return err;
7553                         if ((err = add_control(spec, ALC_CTL_BIND_MUTE, "LFE Playback Switch",
7554                                                HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
7555                                 return err;
7556                 } else {
7557                         for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1; idx++)
7558                                 if (nid == alc861_dac_nids[idx])
7559                                         break;
7560                         sprintf(name, "%s Playback Switch", chname[idx]);
7561                         if ((err = add_control(spec, ALC_CTL_BIND_MUTE, name,
7562                                                HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
7563                                 return err;
7564                 }
7565         }
7566         return 0;
7567 }
7568
7569 static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
7570 {
7571         int err;
7572         hda_nid_t nid;
7573
7574         if (! pin)
7575                 return 0;
7576
7577         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
7578                 nid = 0x03;
7579                 if ((err = add_control(spec, ALC_CTL_WIDGET_MUTE, "Headphone Playback Switch",
7580                                        HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
7581                         return err;
7582                 spec->multiout.hp_nid = nid;
7583         }
7584         return 0;
7585 }
7586
7587 /* create playback/capture controls for input pins */
7588 static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec, const struct auto_pin_cfg *cfg)
7589 {
7590         struct hda_input_mux *imux = &spec->private_imux;
7591         int i, err, idx, idx1;
7592
7593         for (i = 0; i < AUTO_PIN_LAST; i++) {
7594                 switch(cfg->input_pins[i]) {
7595                 case 0x0c:
7596                         idx1 = 1;
7597                         idx = 2;        // Line In
7598                         break;
7599                 case 0x0f:
7600                         idx1 = 2;
7601                         idx = 2;        // Line In
7602                         break;
7603                 case 0x0d:
7604                         idx1 = 0;
7605                         idx = 1;        // Mic In 
7606                         break;
7607                 case 0x10:      
7608                         idx1 = 3;
7609                         idx = 1;        // Mic In 
7610                         break;
7611                 case 0x11:
7612                         idx1 = 4;
7613                         idx = 0;        // CD
7614                         break;
7615                 default:
7616                         continue;
7617                 }
7618
7619                 err = new_analog_input(spec, cfg->input_pins[i],
7620                                        auto_pin_cfg_labels[i], idx, 0x15);
7621                 if (err < 0)
7622                         return err;
7623
7624                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
7625                 imux->items[imux->num_items].index = idx1;
7626                 imux->num_items++;      
7627         }
7628         return 0;
7629 }
7630
7631 static struct snd_kcontrol_new alc861_capture_mixer[] = {
7632         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7633         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7634
7635         {
7636                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7637                 /* The multiple "Capture Source" controls confuse alsamixer
7638                  * So call somewhat different..
7639                  *FIXME: the controls appear in the "playback" view!
7640                  */
7641                 /* .name = "Capture Source", */
7642                 .name = "Input Source",
7643                 .count = 1,
7644                 .info = alc_mux_enum_info,
7645                 .get = alc_mux_enum_get,
7646                 .put = alc_mux_enum_put,
7647         },
7648         { } /* end */
7649 };
7650
7651 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec, hda_nid_t nid,
7652                                               int pin_type, int dac_idx)
7653 {
7654         /* set as output */
7655
7656         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
7657         snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
7658
7659 }
7660
7661 static void alc861_auto_init_multi_out(struct hda_codec *codec)
7662 {
7663         struct alc_spec *spec = codec->spec;
7664         int i;
7665
7666         for (i = 0; i < spec->autocfg.line_outs; i++) {
7667                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
7668                 if (nid)
7669                         alc861_auto_set_output_and_unmute(codec, nid, PIN_OUT, spec->multiout.dac_nids[i]);
7670         }
7671 }
7672
7673 static void alc861_auto_init_hp_out(struct hda_codec *codec)
7674 {
7675         struct alc_spec *spec = codec->spec;
7676         hda_nid_t pin;
7677
7678         pin = spec->autocfg.hp_pins[0];
7679         if (pin) /* connect to front */
7680                 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP, spec->multiout.dac_nids[0]);
7681 }
7682
7683 static void alc861_auto_init_analog_input(struct hda_codec *codec)
7684 {
7685         struct alc_spec *spec = codec->spec;
7686         int i;
7687
7688         for (i = 0; i < AUTO_PIN_LAST; i++) {
7689                 hda_nid_t nid = spec->autocfg.input_pins[i];
7690                 if ((nid>=0x0c) && (nid <=0x11)) {
7691                         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
7692                                             i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
7693                 }
7694         }
7695 }
7696
7697 /* parse the BIOS configuration and set up the alc_spec */
7698 /* return 1 if successful, 0 if the proper config is not found, or a negative error code */
7699 static int alc861_parse_auto_config(struct hda_codec *codec)
7700 {
7701         struct alc_spec *spec = codec->spec;
7702         int err;
7703         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
7704
7705         if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
7706                                                 alc861_ignore)) < 0)
7707                 return err;
7708         if (! spec->autocfg.line_outs)
7709                 return 0; /* can't find valid BIOS pin config */
7710
7711         if ((err = alc861_auto_fill_dac_nids(spec, &spec->autocfg)) < 0 ||
7712             (err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
7713             (err = alc861_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0])) < 0 ||
7714             (err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
7715                 return err;
7716
7717         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
7718
7719         if (spec->autocfg.dig_out_pin)
7720                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
7721
7722         if (spec->kctl_alloc)
7723                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
7724
7725         spec->init_verbs[spec->num_init_verbs++] = alc861_auto_init_verbs;
7726
7727         spec->num_mux_defs = 1;
7728         spec->input_mux = &spec->private_imux;
7729
7730         spec->adc_nids = alc861_adc_nids;
7731         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
7732         spec->mixers[spec->num_mixers] = alc861_capture_mixer;
7733         spec->num_mixers++;
7734
7735         return 1;
7736 }
7737
7738 /* additional initialization for auto-configuration model */
7739 static void alc861_auto_init(struct hda_codec *codec)
7740 {
7741         alc861_auto_init_multi_out(codec);
7742         alc861_auto_init_hp_out(codec);
7743         alc861_auto_init_analog_input(codec);
7744 }
7745
7746
7747 /*
7748  * configuration and preset
7749  */
7750 static const char *alc861_models[ALC861_MODEL_LAST] = {
7751         [ALC861_3ST]            = "3stack",
7752         [ALC660_3ST]            = "3stack-660",
7753         [ALC861_3ST_DIG]        = "3stack-dig",
7754         [ALC861_6ST_DIG]        = "6stack-dig",
7755         [ALC861_UNIWILL_M31]    = "uniwill-m31",
7756         [ALC861_TOSHIBA]        = "toshiba",
7757         [ALC861_ASUS]           = "asus",
7758         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
7759         [ALC861_AUTO]           = "auto",
7760 };
7761
7762 static struct snd_pci_quirk alc861_cfg_tbl[] = {
7763         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
7764         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
7765         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
7766         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
7767         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660_3ST),
7768         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
7769         SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA),
7770         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
7771         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
7772         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
7773         {}
7774 };
7775
7776 static struct alc_config_preset alc861_presets[] = {
7777         [ALC861_3ST] = {
7778                 .mixers = { alc861_3ST_mixer },
7779                 .init_verbs = { alc861_threestack_init_verbs },
7780                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
7781                 .dac_nids = alc861_dac_nids,
7782                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
7783                 .channel_mode = alc861_threestack_modes,
7784                 .need_dac_fix = 1,
7785                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
7786                 .adc_nids = alc861_adc_nids,
7787                 .input_mux = &alc861_capture_source,
7788         },
7789         [ALC861_3ST_DIG] = {
7790                 .mixers = { alc861_base_mixer },
7791                 .init_verbs = { alc861_threestack_init_verbs },
7792                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
7793                 .dac_nids = alc861_dac_nids,
7794                 .dig_out_nid = ALC861_DIGOUT_NID,
7795                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
7796                 .channel_mode = alc861_threestack_modes,
7797                 .need_dac_fix = 1,
7798                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
7799                 .adc_nids = alc861_adc_nids,
7800                 .input_mux = &alc861_capture_source,
7801         },
7802         [ALC861_6ST_DIG] = {
7803                 .mixers = { alc861_base_mixer },
7804                 .init_verbs = { alc861_base_init_verbs },
7805                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
7806                 .dac_nids = alc861_dac_nids,
7807                 .dig_out_nid = ALC861_DIGOUT_NID,
7808                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
7809                 .channel_mode = alc861_8ch_modes,
7810                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
7811                 .adc_nids = alc861_adc_nids,
7812                 .input_mux = &alc861_capture_source,
7813         },
7814         [ALC660_3ST] = {
7815                 .mixers = { alc861_3ST_mixer },
7816                 .init_verbs = { alc861_threestack_init_verbs },
7817                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
7818                 .dac_nids = alc660_dac_nids,
7819                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
7820                 .channel_mode = alc861_threestack_modes,
7821                 .need_dac_fix = 1,
7822                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
7823                 .adc_nids = alc861_adc_nids,
7824                 .input_mux = &alc861_capture_source,
7825         },
7826         [ALC861_UNIWILL_M31] = {
7827                 .mixers = { alc861_uniwill_m31_mixer },
7828                 .init_verbs = { alc861_uniwill_m31_init_verbs },
7829                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
7830                 .dac_nids = alc861_dac_nids,
7831                 .dig_out_nid = ALC861_DIGOUT_NID,
7832                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
7833                 .channel_mode = alc861_uniwill_m31_modes,
7834                 .need_dac_fix = 1,
7835                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
7836                 .adc_nids = alc861_adc_nids,
7837                 .input_mux = &alc861_capture_source,
7838         },
7839         [ALC861_TOSHIBA] = {
7840                 .mixers = { alc861_toshiba_mixer },
7841                 .init_verbs = { alc861_base_init_verbs, alc861_toshiba_init_verbs },
7842                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
7843                 .dac_nids = alc861_dac_nids,
7844                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7845                 .channel_mode = alc883_3ST_2ch_modes,
7846                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
7847                 .adc_nids = alc861_adc_nids,
7848                 .input_mux = &alc861_capture_source,
7849                 .unsol_event = alc861_toshiba_unsol_event,
7850                 .init_hook = alc861_toshiba_automute,
7851         },
7852         [ALC861_ASUS] = {
7853                 .mixers = { alc861_asus_mixer },
7854                 .init_verbs = { alc861_asus_init_verbs },
7855                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
7856                 .dac_nids = alc861_dac_nids,
7857                 .dig_out_nid = ALC861_DIGOUT_NID,
7858                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
7859                 .channel_mode = alc861_asus_modes,
7860                 .need_dac_fix = 1,
7861                 .hp_nid = 0x06,
7862                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
7863                 .adc_nids = alc861_adc_nids,
7864                 .input_mux = &alc861_capture_source,
7865         },
7866         [ALC861_ASUS_LAPTOP] = {
7867                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
7868                 .init_verbs = { alc861_asus_init_verbs,
7869                                 alc861_asus_laptop_init_verbs },
7870                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
7871                 .dac_nids = alc861_dac_nids,
7872                 .dig_out_nid = ALC861_DIGOUT_NID,
7873                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7874                 .channel_mode = alc883_3ST_2ch_modes,
7875                 .need_dac_fix = 1,
7876                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
7877                 .adc_nids = alc861_adc_nids,
7878                 .input_mux = &alc861_capture_source,
7879         },
7880 };
7881
7882
7883 static int patch_alc861(struct hda_codec *codec)
7884 {
7885         struct alc_spec *spec;
7886         int board_config;
7887         int err;
7888
7889         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
7890         if (spec == NULL)
7891                 return -ENOMEM;
7892
7893         codec->spec = spec;     
7894
7895         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
7896                                                   alc861_models,
7897                                                   alc861_cfg_tbl);
7898
7899         if (board_config < 0) {
7900                 printk(KERN_INFO "hda_codec: Unknown model for ALC861, "
7901                        "trying auto-probe from BIOS...\n");
7902                 board_config = ALC861_AUTO;
7903         }
7904
7905         if (board_config == ALC861_AUTO) {
7906                 /* automatic parse from the BIOS config */
7907                 err = alc861_parse_auto_config(codec);
7908                 if (err < 0) {
7909                         alc_free(codec);
7910                         return err;
7911                 } else if (! err) {
7912                         printk(KERN_INFO
7913                                "hda_codec: Cannot set up configuration "
7914                                "from BIOS.  Using base mode...\n");
7915                    board_config = ALC861_3ST_DIG;
7916                 }
7917         }
7918
7919         if (board_config != ALC861_AUTO)
7920                 setup_preset(spec, &alc861_presets[board_config]);
7921
7922         spec->stream_name_analog = "ALC861 Analog";
7923         spec->stream_analog_playback = &alc861_pcm_analog_playback;
7924         spec->stream_analog_capture = &alc861_pcm_analog_capture;
7925
7926         spec->stream_name_digital = "ALC861 Digital";
7927         spec->stream_digital_playback = &alc861_pcm_digital_playback;
7928         spec->stream_digital_capture = &alc861_pcm_digital_capture;
7929
7930         codec->patch_ops = alc_patch_ops;
7931         if (board_config == ALC861_AUTO)
7932                 spec->init_hook = alc861_auto_init;
7933                 
7934         return 0;
7935 }
7936
7937 /*
7938  * ALC861-VD support
7939  *
7940  * Based on ALC882
7941  *
7942  * In addition, an independent DAC
7943  */
7944 #define ALC861VD_DIGOUT_NID     0x06
7945
7946 static hda_nid_t alc861vd_dac_nids[4] = {
7947         /* front, surr, clfe, side surr */
7948         0x02, 0x03, 0x04, 0x05
7949 };
7950
7951 /* dac_nids for ALC660vd are in a different order - according to
7952  * Realtek's driver.
7953  * This should probably tesult in a different mixer for 6stack models
7954  * of ALC660vd codecs, but for now there is only 3stack mixer
7955  * - and it is the same as in 861vd.
7956  * adc_nids in ALC660vd are (is) the same as in 861vd
7957  */
7958 static hda_nid_t alc660vd_dac_nids[3] = {
7959         /* front, rear, clfe, rear_surr */
7960         0x02, 0x04, 0x03
7961 };
7962
7963 static hda_nid_t alc861vd_adc_nids[1] = {
7964         /* ADC0 */
7965         0x09,
7966 };
7967
7968 /* input MUX */
7969 /* FIXME: should be a matrix-type input source selection */
7970 static struct hda_input_mux alc861vd_capture_source = {
7971         .num_items = 4,
7972         .items = {
7973                 { "Mic", 0x0 },
7974                 { "Front Mic", 0x1 },
7975                 { "Line", 0x2 },
7976                 { "CD", 0x4 },
7977         },
7978 };
7979
7980 #define alc861vd_mux_enum_info alc_mux_enum_info
7981 #define alc861vd_mux_enum_get alc_mux_enum_get
7982
7983 static int alc861vd_mux_enum_put(struct snd_kcontrol *kcontrol,
7984                                 struct snd_ctl_elem_value *ucontrol)
7985 {
7986         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
7987         struct alc_spec *spec = codec->spec;
7988         const struct hda_input_mux *imux = spec->input_mux;
7989         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
7990         static hda_nid_t capture_mixers[1] = { 0x22 };
7991         hda_nid_t nid = capture_mixers[adc_idx];
7992         unsigned int *cur_val = &spec->cur_mux[adc_idx];
7993         unsigned int i, idx;
7994
7995         idx = ucontrol->value.enumerated.item[0];
7996         if (idx >= imux->num_items)
7997                 idx = imux->num_items - 1;
7998         if (*cur_val == idx && ! codec->in_resume)
7999                 return 0;
8000         for (i = 0; i < imux->num_items; i++) {
8001                 unsigned int v = (i == idx) ? 0x7000 : 0x7080;
8002                 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8003                                     v | (imux->items[i].index << 8));
8004         }
8005         *cur_val = idx;
8006         return 1;
8007 }
8008
8009 /*
8010  * 2ch mode
8011  */
8012 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
8013         { 2, NULL }
8014 };
8015
8016 /*
8017  * 6ch mode
8018  */
8019 static struct hda_verb alc861vd_6stack_ch6_init[] = {
8020         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
8021         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8022         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8023         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8024         { } /* end */
8025 };
8026
8027 /*
8028  * 8ch mode
8029  */
8030 static struct hda_verb alc861vd_6stack_ch8_init[] = {
8031         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8032         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8033         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8034         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8035         { } /* end */
8036 };
8037
8038 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
8039         { 6, alc861vd_6stack_ch6_init },
8040         { 8, alc861vd_6stack_ch8_init },
8041 };
8042
8043 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
8044         {
8045                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8046                 .name = "Channel Mode",
8047                 .info = alc_ch_mode_info,
8048                 .get = alc_ch_mode_get,
8049                 .put = alc_ch_mode_put,
8050         },
8051         { } /* end */
8052 };
8053
8054 static struct snd_kcontrol_new alc861vd_capture_mixer[] = {
8055         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
8056         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
8057
8058         {
8059                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8060                 /* The multiple "Capture Source" controls confuse alsamixer
8061                  * So call somewhat different..
8062                  *FIXME: the controls appear in the "playback" view!
8063                  */
8064                 /* .name = "Capture Source", */
8065                 .name = "Input Source",
8066                 .count = 1,
8067                 .info = alc861vd_mux_enum_info,
8068                 .get = alc861vd_mux_enum_get,
8069                 .put = alc861vd_mux_enum_put,
8070         },
8071         { } /* end */
8072 };
8073
8074 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
8075  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
8076  */
8077 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
8078         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
8079         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8080
8081         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
8082         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
8083
8084         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
8085                                 HDA_OUTPUT),
8086         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
8087                                 HDA_OUTPUT),
8088         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
8089         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
8090
8091         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
8092         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
8093
8094         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8095
8096         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8097         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8098         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8099
8100         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8101         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8102         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8103
8104         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8105         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8106
8107         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8108         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8109
8110         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
8111         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
8112
8113         { } /* end */
8114 };
8115
8116 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
8117         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
8118         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8119
8120         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8121
8122         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8123         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8124         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8125
8126         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8127         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8128         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8129
8130         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8131         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8132
8133         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8134         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8135
8136         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
8137         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
8138
8139         { } /* end */
8140 };
8141
8142 /*
8143  * generic initialization of ADC, input mixers and output mixers
8144  */
8145 static struct hda_verb alc861vd_volume_init_verbs[] = {
8146         /*
8147          * Unmute ADC0 and set the default input to mic-in
8148          */
8149         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8150         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8151
8152         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
8153          * the analog-loopback mixer widget
8154          */
8155         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8156         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8157         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8158         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8159         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
8160         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8161
8162         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
8163         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8164         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
8165         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(6)},
8166         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(8)},
8167
8168         /*
8169          * Set up output mixers (0x02 - 0x05)
8170          */
8171         /* set vol=0 to output mixers */
8172         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8173         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8174         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8175         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8176
8177         /* set up input amps for analog loopback */
8178         /* Amp Indices: DAC = 0, mixer = 1 */
8179         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8180         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8181         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8182         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8183         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8184         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8185         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8186         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8187
8188         { }
8189 };
8190
8191 /*
8192  * 3-stack pin configuration:
8193  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
8194  */
8195 static struct hda_verb alc861vd_3stack_init_verbs[] = {
8196         /*
8197          * Set pin mode and muting
8198          */
8199         /* set front pin widgets 0x14 for output */
8200         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8201         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8202         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8203
8204         /* Mic (rear) pin: input vref at 80% */
8205         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8206         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8207         /* Front Mic pin: input vref at 80% */
8208         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8209         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8210         /* Line In pin: input */
8211         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8212         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8213         /* Line-2 In: Headphone output (output 0 - 0x0c) */
8214         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8215         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8216         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8217         /* CD pin widget for input */
8218         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8219
8220         { }
8221 };
8222
8223 /*
8224  * 6-stack pin configuration:
8225  */
8226 static struct hda_verb alc861vd_6stack_init_verbs[] = {
8227         /*
8228          * Set pin mode and muting
8229          */
8230         /* set front pin widgets 0x14 for output */
8231         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8232         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8233         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8234
8235         /* Rear Pin: output 1 (0x0d) */
8236         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8237         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8238         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
8239         /* CLFE Pin: output 2 (0x0e) */
8240         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8241         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8242         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
8243         /* Side Pin: output 3 (0x0f) */
8244         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8245         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8246         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
8247
8248         /* Mic (rear) pin: input vref at 80% */
8249         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8250         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8251         /* Front Mic pin: input vref at 80% */
8252         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8253         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8254         /* Line In pin: input */
8255         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8256         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8257         /* Line-2 In: Headphone output (output 0 - 0x0c) */
8258         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8259         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8260         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8261         /* CD pin widget for input */
8262         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8263
8264         { }
8265 };
8266
8267 /* pcm configuration: identiacal with ALC880 */
8268 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
8269 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
8270 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
8271 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
8272
8273 /*
8274  * configuration and preset
8275  */
8276 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
8277         [ALC660VD_3ST]          = "3stack-660",
8278         [ALC861VD_3ST]          = "3stack",
8279         [ALC861VD_3ST_DIG]      = "3stack-digout",
8280         [ALC861VD_6ST_DIG]      = "6stack-digout",
8281         [ALC861VD_AUTO]         = "auto",
8282 };
8283
8284 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
8285         SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),
8286         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
8287         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
8288
8289         SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo 3000 C200", ALC861VD_3ST),
8290         {}
8291 };
8292
8293 static struct alc_config_preset alc861vd_presets[] = {
8294         [ALC660VD_3ST] = {
8295                 .mixers = { alc861vd_3st_mixer },
8296                 .init_verbs = { alc861vd_volume_init_verbs,
8297                                  alc861vd_3stack_init_verbs },
8298                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
8299                 .dac_nids = alc660vd_dac_nids,
8300                 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
8301                 .adc_nids = alc861vd_adc_nids,
8302                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
8303                 .channel_mode = alc861vd_3stack_2ch_modes,
8304                 .input_mux = &alc861vd_capture_source,
8305         },
8306         [ALC861VD_3ST] = {
8307                 .mixers = { alc861vd_3st_mixer },
8308                 .init_verbs = { alc861vd_volume_init_verbs,
8309                                  alc861vd_3stack_init_verbs },
8310                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
8311                 .dac_nids = alc861vd_dac_nids,
8312                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
8313                 .channel_mode = alc861vd_3stack_2ch_modes,
8314                 .input_mux = &alc861vd_capture_source,
8315         },
8316         [ALC861VD_3ST_DIG] = {
8317                 .mixers = { alc861vd_3st_mixer },
8318                 .init_verbs = { alc861vd_volume_init_verbs,
8319                                  alc861vd_3stack_init_verbs },
8320                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
8321                 .dac_nids = alc861vd_dac_nids,
8322                 .dig_out_nid = ALC861VD_DIGOUT_NID,
8323                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
8324                 .channel_mode = alc861vd_3stack_2ch_modes,
8325                 .input_mux = &alc861vd_capture_source,
8326         },
8327         [ALC861VD_6ST_DIG] = {
8328                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
8329                 .init_verbs = { alc861vd_volume_init_verbs,
8330                                 alc861vd_6stack_init_verbs },
8331                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
8332                 .dac_nids = alc861vd_dac_nids,
8333                 .dig_out_nid = ALC861VD_DIGOUT_NID,
8334                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
8335                 .channel_mode = alc861vd_6stack_modes,
8336                 .input_mux = &alc861vd_capture_source,
8337         },
8338 };
8339
8340 /*
8341  * BIOS auto configuration
8342  */
8343 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
8344                                 hda_nid_t nid, int pin_type, int dac_idx)
8345 {
8346         /* set as output */
8347         snd_hda_codec_write(codec, nid, 0,
8348                                 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
8349         snd_hda_codec_write(codec, nid, 0,
8350                                 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
8351 }
8352
8353 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
8354 {
8355         struct alc_spec *spec = codec->spec;
8356         int i;
8357
8358         for (i = 0; i <= HDA_SIDE; i++) {
8359                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
8360                 if (nid)
8361                         alc861vd_auto_set_output_and_unmute(codec, nid,
8362                                                                 PIN_OUT, i);
8363         }
8364 }
8365
8366
8367 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
8368 {
8369         struct alc_spec *spec = codec->spec;
8370         hda_nid_t pin;
8371
8372         pin = spec->autocfg.hp_pins[0];
8373         if (pin) /* connect to front and  use dac 0 */
8374                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
8375 }
8376
8377 #define alc861vd_is_input_pin(nid)      alc880_is_input_pin(nid)
8378 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
8379
8380 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
8381 {
8382         struct alc_spec *spec = codec->spec;
8383         int i;
8384
8385         for (i = 0; i < AUTO_PIN_LAST; i++) {
8386                 hda_nid_t nid = spec->autocfg.input_pins[i];
8387                 if (alc861vd_is_input_pin(nid)) {
8388                         snd_hda_codec_write(codec, nid, 0,
8389                                         AC_VERB_SET_PIN_WIDGET_CONTROL,
8390                                         i <= AUTO_PIN_FRONT_MIC ?
8391                                                         PIN_VREF80 : PIN_IN);
8392                         if (nid != ALC861VD_PIN_CD_NID)
8393                                 snd_hda_codec_write(codec, nid, 0,
8394                                                 AC_VERB_SET_AMP_GAIN_MUTE,
8395                                                 AMP_OUT_MUTE);
8396                 }
8397         }
8398 }
8399
8400 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
8401 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
8402
8403 /* add playback controls from the parsed DAC table */
8404 /* Based on ALC880 version. But ALC861VD has separate,
8405  * different NIDs for mute/unmute switch and volume control */
8406 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
8407                                              const struct auto_pin_cfg *cfg)
8408 {
8409         char name[32];
8410         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
8411         hda_nid_t nid_v, nid_s;
8412         int i, err;
8413
8414         for (i = 0; i < cfg->line_outs; i++) {
8415                 if (! spec->multiout.dac_nids[i])
8416                         continue;
8417                 nid_v = alc861vd_idx_to_mixer_vol(
8418                                 alc880_dac_to_idx(
8419                                         spec->multiout.dac_nids[i]));
8420                 nid_s = alc861vd_idx_to_mixer_switch(
8421                                 alc880_dac_to_idx(
8422                                         spec->multiout.dac_nids[i]));
8423
8424                 if (i == 2) {
8425                         /* Center/LFE */
8426                         if ((err = add_control(spec, ALC_CTL_WIDGET_VOL,
8427                                                 "Center Playback Volume",
8428                                                 HDA_COMPOSE_AMP_VAL(nid_v, 1,
8429                                                         0, HDA_OUTPUT))) < 0)
8430                                 return err;
8431                         if ((err = add_control(spec, ALC_CTL_WIDGET_VOL,
8432                                                 "LFE Playback Volume",
8433                                                 HDA_COMPOSE_AMP_VAL(nid_v, 2,
8434                                                         0, HDA_OUTPUT))) < 0)
8435                                 return err;
8436                         if ((err = add_control(spec, ALC_CTL_BIND_MUTE,
8437                                                 "Center Playback Switch",
8438                                                 HDA_COMPOSE_AMP_VAL(nid_s, 1,
8439                                                 2, HDA_INPUT))) < 0)
8440                                 return err;
8441                         if ((err = add_control(spec, ALC_CTL_BIND_MUTE,
8442                                                 "LFE Playback Switch",
8443                                                 HDA_COMPOSE_AMP_VAL(nid_s, 2,
8444                                                 2, HDA_INPUT))) < 0)
8445                                 return err;
8446                 } else {
8447                         sprintf(name, "%s Playback Volume", chname[i]);
8448                         if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
8449                                                 HDA_COMPOSE_AMP_VAL(nid_v, 3,
8450                                                         0, HDA_OUTPUT))) < 0)
8451                                 return err;
8452                         sprintf(name, "%s Playback Switch", chname[i]);
8453                         if ((err = add_control(spec, ALC_CTL_BIND_MUTE, name,
8454                                                 HDA_COMPOSE_AMP_VAL(nid_v, 3,
8455                                                         2, HDA_INPUT))) < 0)
8456                                 return err;
8457                 }
8458         }
8459         return 0;
8460 }
8461
8462 /* add playback controls for speaker and HP outputs */
8463 /* Based on ALC880 version. But ALC861VD has separate,
8464  * different NIDs for mute/unmute switch and volume control */
8465 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
8466                                         hda_nid_t pin, const char *pfx)
8467 {
8468         hda_nid_t nid_v, nid_s;
8469         int err;
8470         char name[32];
8471
8472         if (! pin)
8473                 return 0;
8474
8475         if (alc880_is_fixed_pin(pin)) {
8476                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
8477                 /* specify the DAC as the extra output */
8478                 if (! spec->multiout.hp_nid)
8479                         spec->multiout.hp_nid = nid_v;
8480                 else
8481                         spec->multiout.extra_out_nid[0] = nid_v;
8482                 /* control HP volume/switch on the output mixer amp */
8483                 nid_v = alc861vd_idx_to_mixer_vol(
8484                                 alc880_fixed_pin_idx(pin));
8485                 nid_s = alc861vd_idx_to_mixer_switch(
8486                                 alc880_fixed_pin_idx(pin));
8487
8488                 sprintf(name, "%s Playback Volume", pfx);
8489                 if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
8490                                 HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
8491                                                         HDA_OUTPUT))) < 0)
8492                         return err;
8493                 sprintf(name, "%s Playback Switch", pfx);
8494                 if ((err = add_control(spec, ALC_CTL_BIND_MUTE, name,
8495                                 HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
8496                                                         HDA_INPUT))) < 0)
8497                         return err;
8498         } else if (alc880_is_multi_pin(pin)) {
8499                 /* set manual connection */
8500                 /* we have only a switch on HP-out PIN */
8501                 sprintf(name, "%s Playback Switch", pfx);
8502                 if ((err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
8503                                 HDA_COMPOSE_AMP_VAL(pin, 3, 0,
8504                                                         HDA_OUTPUT))) < 0)
8505                         return err;
8506         }
8507         return 0;
8508 }
8509
8510 /* parse the BIOS configuration and set up the alc_spec
8511  * return 1 if successful, 0 if the proper config is not found,
8512  * or a negative error code
8513  * Based on ALC880 version - had to change it to override
8514  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
8515 static int alc861vd_parse_auto_config(struct hda_codec *codec)
8516 {
8517         struct alc_spec *spec = codec->spec;
8518         int err;
8519         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
8520
8521         if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
8522                                                 alc861vd_ignore)) < 0)
8523                 return err;
8524         if (! spec->autocfg.line_outs)
8525                 return 0; /* can't find valid BIOS pin config */
8526
8527         if ((err = alc880_auto_fill_dac_nids(spec, &spec->autocfg)) < 0 ||
8528                 (err = alc861vd_auto_create_multi_out_ctls(spec,
8529                         &spec->autocfg)) < 0 ||
8530                 (err = alc861vd_auto_create_extra_out(spec,
8531                         spec->autocfg.speaker_pins[0], "Speaker")) < 0 ||
8532                 (err = alc861vd_auto_create_extra_out(spec,
8533                         spec->autocfg.hp_pins[0], "Headphone")) < 0 ||
8534                 (err = alc880_auto_create_analog_input_ctls(spec,
8535                         &spec->autocfg)) < 0)
8536                 return err;
8537
8538         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
8539
8540         if (spec->autocfg.dig_out_pin)
8541                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
8542
8543         if (spec->kctl_alloc)
8544                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
8545
8546         spec->init_verbs[spec->num_init_verbs++]
8547                 = alc861vd_volume_init_verbs;
8548
8549         spec->num_mux_defs = 1;
8550         spec->input_mux = &spec->private_imux;
8551
8552         return 1;
8553 }
8554
8555 /* additional initialization for auto-configuration model */
8556 static void alc861vd_auto_init(struct hda_codec *codec)
8557 {
8558         alc861vd_auto_init_multi_out(codec);
8559         alc861vd_auto_init_hp_out(codec);
8560         alc861vd_auto_init_analog_input(codec);
8561 }
8562
8563 static int patch_alc861vd(struct hda_codec *codec)
8564 {
8565         struct alc_spec *spec;
8566         int err, board_config;
8567
8568         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
8569         if (spec == NULL)
8570                 return -ENOMEM;
8571
8572         codec->spec = spec;
8573
8574         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
8575                                                   alc861vd_models,
8576                                                   alc861vd_cfg_tbl);
8577
8578         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
8579                 printk(KERN_INFO "hda_codec: Unknown model for ALC660VD/"
8580                         "ALC861VD, trying auto-probe from BIOS...\n");
8581                 board_config = ALC861VD_AUTO;
8582         }
8583
8584         if (board_config == ALC861VD_AUTO) {
8585                 /* automatic parse from the BIOS config */
8586                 err = alc861vd_parse_auto_config(codec);
8587                 if (err < 0) {
8588                         alc_free(codec);
8589                         return err;
8590                 } else if (! err) {
8591                         printk(KERN_INFO
8592                                "hda_codec: Cannot set up configuration "
8593                                "from BIOS.  Using base mode...\n");
8594                         board_config = ALC861VD_3ST;
8595                 }
8596         }
8597
8598         if (board_config != ALC861VD_AUTO)
8599                 setup_preset(spec, &alc861vd_presets[board_config]);
8600
8601         spec->stream_name_analog = "ALC861VD Analog";
8602         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
8603         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
8604
8605         spec->stream_name_digital = "ALC861VD Digital";
8606         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
8607         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
8608
8609         spec->adc_nids = alc861vd_adc_nids;
8610         spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
8611
8612         spec->mixers[spec->num_mixers] = alc861vd_capture_mixer;
8613         spec->num_mixers++;
8614
8615         codec->patch_ops = alc_patch_ops;
8616
8617         if (board_config == ALC861VD_AUTO)
8618                 spec->init_hook = alc861vd_auto_init;
8619
8620         return 0;
8621 }
8622
8623 /*
8624  * patch entries
8625  */
8626 struct hda_codec_preset snd_hda_preset_realtek[] = {
8627         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
8628         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
8629         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
8630                 .patch = patch_alc861 },
8631         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
8632         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
8633         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
8634         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
8635         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
8636         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
8637         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
8638         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
8639         {} /* terminator */
8640 };