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