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