]> git.karo-electronics.de Git - karo-tx-linux.git/blob - sound/pci/hda/patch_realtek.c
8491b046a9f41a442f02d16f58fcc568c2a99c33
[karo-tx-linux.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_BENQ_T31,
98         ALC262_AUTO,
99         ALC262_MODEL_LAST /* last tag */
100 };
101
102 /* ALC268 models */
103 enum {
104         ALC268_3ST,
105         ALC268_TOSHIBA,
106         ALC268_ACER,
107         ALC268_AUTO,
108         ALC268_MODEL_LAST /* last tag */
109 };
110
111 /* ALC861 models */
112 enum {
113         ALC861_3ST,
114         ALC660_3ST,
115         ALC861_3ST_DIG,
116         ALC861_6ST_DIG,
117         ALC861_UNIWILL_M31,
118         ALC861_TOSHIBA,
119         ALC861_ASUS,
120         ALC861_ASUS_LAPTOP,
121         ALC861_AUTO,
122         ALC861_MODEL_LAST,
123 };
124
125 /* ALC861-VD models */
126 enum {
127         ALC660VD_3ST,
128         ALC660VD_3ST_DIG,
129         ALC861VD_3ST,
130         ALC861VD_3ST_DIG,
131         ALC861VD_6ST_DIG,
132         ALC861VD_LENOVO,
133         ALC861VD_DALLAS,
134         ALC861VD_HP,
135         ALC861VD_AUTO,
136         ALC861VD_MODEL_LAST,
137 };
138
139 /* ALC662 models */
140 enum {
141         ALC662_3ST_2ch_DIG,
142         ALC662_3ST_6ch_DIG,
143         ALC662_3ST_6ch,
144         ALC662_5ST_DIG,
145         ALC662_LENOVO_101E,
146         ALC662_AUTO,
147         ALC662_MODEL_LAST,
148 };
149
150 /* ALC882 models */
151 enum {
152         ALC882_3ST_DIG,
153         ALC882_6ST_DIG,
154         ALC882_ARIMA,
155         ALC882_W2JC,
156         ALC882_TARGA,
157         ALC882_ASUS_A7J,
158         ALC882_ASUS_A7M,
159         ALC885_MACPRO,
160         ALC885_MBP3,
161         ALC885_IMAC24,
162         ALC882_AUTO,
163         ALC882_MODEL_LAST,
164 };
165
166 /* ALC883 models */
167 enum {
168         ALC883_3ST_2ch_DIG,
169         ALC883_3ST_6ch_DIG,
170         ALC883_3ST_6ch,
171         ALC883_6ST_DIG,
172         ALC883_TARGA_DIG,
173         ALC883_TARGA_2ch_DIG,
174         ALC883_ACER,
175         ALC883_ACER_ASPIRE,
176         ALC883_MEDION,
177         ALC883_MEDION_MD2,      
178         ALC883_LAPTOP_EAPD,
179         ALC883_LENOVO_101E_2ch,
180         ALC883_LENOVO_NB0763,
181         ALC888_LENOVO_MS7195_DIG,
182         ALC883_HAIER_W66,               
183         ALC888_6ST_HP,
184         ALC888_3ST_HP,
185         ALC883_AUTO,
186         ALC883_MODEL_LAST,
187 };
188
189 /* for GPIO Poll */
190 #define GPIO_MASK       0x03
191
192 struct alc_spec {
193         /* codec parameterization */
194         struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
195         unsigned int num_mixers;
196
197         const struct hda_verb *init_verbs[5];   /* initialization verbs
198                                                  * don't forget NULL
199                                                  * termination!
200                                                  */
201         unsigned int num_init_verbs;
202
203         char *stream_name_analog;       /* analog PCM stream */
204         struct hda_pcm_stream *stream_analog_playback;
205         struct hda_pcm_stream *stream_analog_capture;
206
207         char *stream_name_digital;      /* digital PCM stream */
208         struct hda_pcm_stream *stream_digital_playback;
209         struct hda_pcm_stream *stream_digital_capture;
210
211         /* playback */
212         struct hda_multi_out multiout;  /* playback set-up
213                                          * max_channels, dacs must be set
214                                          * dig_out_nid and hp_nid are optional
215                                          */
216
217         /* capture */
218         unsigned int num_adc_nids;
219         hda_nid_t *adc_nids;
220         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
221
222         /* capture source */
223         unsigned int num_mux_defs;
224         const struct hda_input_mux *input_mux;
225         unsigned int cur_mux[3];
226
227         /* channel model */
228         const struct hda_channel_mode *channel_mode;
229         int num_channel_mode;
230         int need_dac_fix;
231
232         /* PCM information */
233         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
234
235         /* dynamic controls, init_verbs and input_mux */
236         struct auto_pin_cfg autocfg;
237         unsigned int num_kctl_alloc, num_kctl_used;
238         struct snd_kcontrol_new *kctl_alloc;
239         struct hda_input_mux private_imux;
240         hda_nid_t private_dac_nids[5];
241
242         /* hooks */
243         void (*init_hook)(struct hda_codec *codec);
244         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
245
246         /* for pin sensing */
247         unsigned int sense_updated: 1;
248         unsigned int jack_present: 1;
249
250 #ifdef CONFIG_SND_HDA_POWER_SAVE
251         struct hda_loopback_check loopback;
252 #endif
253 };
254
255 /*
256  * configuration template - to be copied to the spec instance
257  */
258 struct alc_config_preset {
259         struct snd_kcontrol_new *mixers[5]; /* should be identical size
260                                              * with spec
261                                              */
262         const struct hda_verb *init_verbs[5];
263         unsigned int num_dacs;
264         hda_nid_t *dac_nids;
265         hda_nid_t dig_out_nid;          /* optional */
266         hda_nid_t hp_nid;               /* optional */
267         unsigned int num_adc_nids;
268         hda_nid_t *adc_nids;
269         hda_nid_t dig_in_nid;
270         unsigned int num_channel_mode;
271         const struct hda_channel_mode *channel_mode;
272         int need_dac_fix;
273         unsigned int num_mux_defs;
274         const struct hda_input_mux *input_mux;
275         void (*unsol_event)(struct hda_codec *, unsigned int);
276         void (*init_hook)(struct hda_codec *);
277 #ifdef CONFIG_SND_HDA_POWER_SAVE
278         struct hda_amp_list *loopbacks;
279 #endif
280 };
281
282
283 /*
284  * input MUX handling
285  */
286 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
287                              struct snd_ctl_elem_info *uinfo)
288 {
289         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
290         struct alc_spec *spec = codec->spec;
291         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
292         if (mux_idx >= spec->num_mux_defs)
293                 mux_idx = 0;
294         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
295 }
296
297 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
298                             struct snd_ctl_elem_value *ucontrol)
299 {
300         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
301         struct alc_spec *spec = codec->spec;
302         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
303
304         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
305         return 0;
306 }
307
308 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
309                             struct snd_ctl_elem_value *ucontrol)
310 {
311         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
312         struct alc_spec *spec = codec->spec;
313         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
314         unsigned int mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
315         return snd_hda_input_mux_put(codec, &spec->input_mux[mux_idx], ucontrol,
316                                      spec->adc_nids[adc_idx],
317                                      &spec->cur_mux[adc_idx]);
318 }
319
320
321 /*
322  * channel mode setting
323  */
324 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
325                             struct snd_ctl_elem_info *uinfo)
326 {
327         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
328         struct alc_spec *spec = codec->spec;
329         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
330                                     spec->num_channel_mode);
331 }
332
333 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
334                            struct snd_ctl_elem_value *ucontrol)
335 {
336         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
337         struct alc_spec *spec = codec->spec;
338         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
339                                    spec->num_channel_mode,
340                                    spec->multiout.max_channels);
341 }
342
343 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
344                            struct snd_ctl_elem_value *ucontrol)
345 {
346         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
347         struct alc_spec *spec = codec->spec;
348         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
349                                       spec->num_channel_mode,
350                                       &spec->multiout.max_channels);
351         if (err >= 0 && spec->need_dac_fix)
352                 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
353         return err;
354 }
355
356 /*
357  * Control the mode of pin widget settings via the mixer.  "pc" is used
358  * instead of "%" to avoid consequences of accidently treating the % as 
359  * being part of a format specifier.  Maximum allowed length of a value is
360  * 63 characters plus NULL terminator.
361  *
362  * Note: some retasking pin complexes seem to ignore requests for input
363  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
364  * are requested.  Therefore order this list so that this behaviour will not
365  * cause problems when mixer clients move through the enum sequentially.
366  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
367  * March 2006.
368  */
369 static char *alc_pin_mode_names[] = {
370         "Mic 50pc bias", "Mic 80pc bias",
371         "Line in", "Line out", "Headphone out",
372 };
373 static unsigned char alc_pin_mode_values[] = {
374         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
375 };
376 /* The control can present all 5 options, or it can limit the options based
377  * in the pin being assumed to be exclusively an input or an output pin.  In
378  * addition, "input" pins may or may not process the mic bias option
379  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
380  * accept requests for bias as of chip versions up to March 2006) and/or
381  * wiring in the computer.
382  */
383 #define ALC_PIN_DIR_IN              0x00
384 #define ALC_PIN_DIR_OUT             0x01
385 #define ALC_PIN_DIR_INOUT           0x02
386 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
387 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
388
389 /* Info about the pin modes supported by the different pin direction modes. 
390  * For each direction the minimum and maximum values are given.
391  */
392 static signed char alc_pin_mode_dir_info[5][2] = {
393         { 0, 2 },    /* ALC_PIN_DIR_IN */
394         { 3, 4 },    /* ALC_PIN_DIR_OUT */
395         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
396         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
397         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
398 };
399 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
400 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
401 #define alc_pin_mode_n_items(_dir) \
402         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
403
404 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
405                              struct snd_ctl_elem_info *uinfo)
406 {
407         unsigned int item_num = uinfo->value.enumerated.item;
408         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
409
410         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
411         uinfo->count = 1;
412         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
413
414         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
415                 item_num = alc_pin_mode_min(dir);
416         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
417         return 0;
418 }
419
420 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
421                             struct snd_ctl_elem_value *ucontrol)
422 {
423         unsigned int i;
424         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
425         hda_nid_t nid = kcontrol->private_value & 0xffff;
426         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
427         long *valp = ucontrol->value.integer.value;
428         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
429                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
430                                                  0x00);
431
432         /* Find enumerated value for current pinctl setting */
433         i = alc_pin_mode_min(dir);
434         while (alc_pin_mode_values[i] != pinctl && i <= alc_pin_mode_max(dir))
435                 i++;
436         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
437         return 0;
438 }
439
440 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
441                             struct snd_ctl_elem_value *ucontrol)
442 {
443         signed int change;
444         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
445         hda_nid_t nid = kcontrol->private_value & 0xffff;
446         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
447         long val = *ucontrol->value.integer.value;
448         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
449                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
450                                                  0x00);
451
452         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
453                 val = alc_pin_mode_min(dir);
454
455         change = pinctl != alc_pin_mode_values[val];
456         if (change) {
457                 /* Set pin mode to that requested */
458                 snd_hda_codec_write_cache(codec, nid, 0,
459                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
460                                           alc_pin_mode_values[val]);
461
462                 /* Also enable the retasking pin's input/output as required 
463                  * for the requested pin mode.  Enum values of 2 or less are
464                  * input modes.
465                  *
466                  * Dynamically switching the input/output buffers probably
467                  * reduces noise slightly (particularly on input) so we'll
468                  * do it.  However, having both input and output buffers
469                  * enabled simultaneously doesn't seem to be problematic if
470                  * this turns out to be necessary in the future.
471                  */
472                 if (val <= 2) {
473                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
474                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
475                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
476                                                  HDA_AMP_MUTE, 0);
477                 } else {
478                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
479                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
480                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
481                                                  HDA_AMP_MUTE, 0);
482                 }
483         }
484         return change;
485 }
486
487 #define ALC_PIN_MODE(xname, nid, dir) \
488         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
489           .info = alc_pin_mode_info, \
490           .get = alc_pin_mode_get, \
491           .put = alc_pin_mode_put, \
492           .private_value = nid | (dir<<16) }
493
494 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
495  * together using a mask with more than one bit set.  This control is
496  * currently used only by the ALC260 test model.  At this stage they are not
497  * needed for any "production" models.
498  */
499 #ifdef CONFIG_SND_DEBUG
500 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
501
502 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
503                              struct snd_ctl_elem_value *ucontrol)
504 {
505         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
506         hda_nid_t nid = kcontrol->private_value & 0xffff;
507         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
508         long *valp = ucontrol->value.integer.value;
509         unsigned int val = snd_hda_codec_read(codec, nid, 0,
510                                               AC_VERB_GET_GPIO_DATA, 0x00);
511
512         *valp = (val & mask) != 0;
513         return 0;
514 }
515 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
516                              struct snd_ctl_elem_value *ucontrol)
517 {
518         signed int change;
519         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
520         hda_nid_t nid = kcontrol->private_value & 0xffff;
521         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
522         long val = *ucontrol->value.integer.value;
523         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
524                                                     AC_VERB_GET_GPIO_DATA,
525                                                     0x00);
526
527         /* Set/unset the masked GPIO bit(s) as needed */
528         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
529         if (val == 0)
530                 gpio_data &= ~mask;
531         else
532                 gpio_data |= mask;
533         snd_hda_codec_write_cache(codec, nid, 0,
534                                   AC_VERB_SET_GPIO_DATA, gpio_data);
535
536         return change;
537 }
538 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
539         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
540           .info = alc_gpio_data_info, \
541           .get = alc_gpio_data_get, \
542           .put = alc_gpio_data_put, \
543           .private_value = nid | (mask<<16) }
544 #endif   /* CONFIG_SND_DEBUG */
545
546 /* A switch control to allow the enabling of the digital IO pins on the
547  * ALC260.  This is incredibly simplistic; the intention of this control is
548  * to provide something in the test model allowing digital outputs to be
549  * identified if present.  If models are found which can utilise these
550  * outputs a more complete mixer control can be devised for those models if
551  * necessary.
552  */
553 #ifdef CONFIG_SND_DEBUG
554 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
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_cache(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 #ifdef CONFIG_SND_HDA_POWER_SAVE
638         spec->loopback.amplist = preset->loopbacks;
639 #endif
640 }
641
642 /* Enable GPIO mask and set output */
643 static struct hda_verb alc_gpio1_init_verbs[] = {
644         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
645         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
646         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
647         { }
648 };
649
650 static struct hda_verb alc_gpio2_init_verbs[] = {
651         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
652         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
653         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
654         { }
655 };
656
657 static struct hda_verb alc_gpio3_init_verbs[] = {
658         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
659         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
660         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
661         { }
662 };
663
664 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
665  *      31 ~ 16 :       Manufacture ID
666  *      15 ~ 8  :       SKU ID
667  *      7  ~ 0  :       Assembly ID
668  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
669  */
670 static void alc_subsystem_id(struct hda_codec *codec,
671                              unsigned int porta, unsigned int porte,
672                              unsigned int portd)
673 {
674         unsigned int ass, tmp;
675
676         ass = codec->subsystem_id;
677         if (!(ass & 1))
678                 return;
679
680         /* Override */
681         tmp = (ass & 0x38) >> 3;        /* external Amp control */
682         switch (tmp) {
683         case 1:
684                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
685                 break;
686         case 3:
687                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
688                 break;
689         case 7:
690                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
691                 break;
692         case 5:
693                 switch (codec->vendor_id) {
694                 case 0x10ec0862:
695                 case 0x10ec0660:
696                 case 0x10ec0662:        
697                 case 0x10ec0267:
698                 case 0x10ec0268:
699                         snd_hda_codec_write(codec, 0x14, 0,
700                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
701                         snd_hda_codec_write(codec, 0x15, 0,
702                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
703                         return;
704                 }
705         case 6:
706                 if (ass & 4) {  /* bit 2 : 0 = Desktop, 1 = Laptop */
707                         hda_nid_t port = 0;
708                         tmp = (ass & 0x1800) >> 11;
709                         switch (tmp) {
710                         case 0: port = porta; break;
711                         case 1: port = porte; break;
712                         case 2: port = portd; break;
713                         }
714                         if (port)
715                                 snd_hda_codec_write(codec, port, 0,
716                                                     AC_VERB_SET_EAPD_BTLENABLE,
717                                                     2);
718                 }
719                 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
720                 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF,
721                                     (tmp == 5 ? 0x3040 : 0x3050));
722                 break;
723         }
724 }
725
726 /*
727  * Fix-up pin default configurations
728  */
729
730 struct alc_pincfg {
731         hda_nid_t nid;
732         u32 val;
733 };
734
735 static void alc_fix_pincfg(struct hda_codec *codec,
736                            const struct snd_pci_quirk *quirk,
737                            const struct alc_pincfg **pinfix)
738 {
739         const struct alc_pincfg *cfg;
740
741         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
742         if (!quirk)
743                 return;
744
745         cfg = pinfix[quirk->value];
746         for (; cfg->nid; cfg++) {
747                 int i;
748                 u32 val = cfg->val;
749                 for (i = 0; i < 4; i++) {
750                         snd_hda_codec_write(codec, cfg->nid, 0,
751                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0 + i,
752                                     val & 0xff);
753                         val >>= 8;
754                 }
755         }
756 }
757
758 /*
759  * ALC880 3-stack model
760  *
761  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
762  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
763  *                 F-Mic = 0x1b, HP = 0x19
764  */
765
766 static hda_nid_t alc880_dac_nids[4] = {
767         /* front, rear, clfe, rear_surr */
768         0x02, 0x05, 0x04, 0x03
769 };
770
771 static hda_nid_t alc880_adc_nids[3] = {
772         /* ADC0-2 */
773         0x07, 0x08, 0x09,
774 };
775
776 /* The datasheet says the node 0x07 is connected from inputs,
777  * but it shows zero connection in the real implementation on some devices.
778  * Note: this is a 915GAV bug, fixed on 915GLV
779  */
780 static hda_nid_t alc880_adc_nids_alt[2] = {
781         /* ADC1-2 */
782         0x08, 0x09,
783 };
784
785 #define ALC880_DIGOUT_NID       0x06
786 #define ALC880_DIGIN_NID        0x0a
787
788 static struct hda_input_mux alc880_capture_source = {
789         .num_items = 4,
790         .items = {
791                 { "Mic", 0x0 },
792                 { "Front Mic", 0x3 },
793                 { "Line", 0x2 },
794                 { "CD", 0x4 },
795         },
796 };
797
798 /* channel source setting (2/6 channel selection for 3-stack) */
799 /* 2ch mode */
800 static struct hda_verb alc880_threestack_ch2_init[] = {
801         /* set line-in to input, mute it */
802         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
803         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
804         /* set mic-in to input vref 80%, mute it */
805         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
806         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
807         { } /* end */
808 };
809
810 /* 6ch mode */
811 static struct hda_verb alc880_threestack_ch6_init[] = {
812         /* set line-in to output, unmute it */
813         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
814         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
815         /* set mic-in to output, unmute it */
816         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
817         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
818         { } /* end */
819 };
820
821 static struct hda_channel_mode alc880_threestack_modes[2] = {
822         { 2, alc880_threestack_ch2_init },
823         { 6, alc880_threestack_ch6_init },
824 };
825
826 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
827         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
828         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
829         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
830         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
831         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
832         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
833         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
834         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
835         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
836         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
837         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
838         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
839         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
840         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
841         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
842         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
843         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
844         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
845         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
846         {
847                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
848                 .name = "Channel Mode",
849                 .info = alc_ch_mode_info,
850                 .get = alc_ch_mode_get,
851                 .put = alc_ch_mode_put,
852         },
853         { } /* end */
854 };
855
856 /* capture mixer elements */
857 static struct snd_kcontrol_new alc880_capture_mixer[] = {
858         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
859         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
860         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
861         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
862         HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
863         HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
864         {
865                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
866                 /* The multiple "Capture Source" controls confuse alsamixer
867                  * So call somewhat different..
868                  * FIXME: the controls appear in the "playback" view!
869                  */
870                 /* .name = "Capture Source", */
871                 .name = "Input Source",
872                 .count = 3,
873                 .info = alc_mux_enum_info,
874                 .get = alc_mux_enum_get,
875                 .put = alc_mux_enum_put,
876         },
877         { } /* end */
878 };
879
880 /* capture mixer elements (in case NID 0x07 not available) */
881 static struct snd_kcontrol_new alc880_capture_alt_mixer[] = {
882         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
883         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
884         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
885         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
886         {
887                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
888                 /* The multiple "Capture Source" controls confuse alsamixer
889                  * So call somewhat different..
890                  * FIXME: the controls appear in the "playback" view!
891                  */
892                 /* .name = "Capture Source", */
893                 .name = "Input Source",
894                 .count = 2,
895                 .info = alc_mux_enum_info,
896                 .get = alc_mux_enum_get,
897                 .put = alc_mux_enum_put,
898         },
899         { } /* end */
900 };
901
902
903
904 /*
905  * ALC880 5-stack model
906  *
907  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
908  *      Side = 0x02 (0xd)
909  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
910  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
911  */
912
913 /* additional mixers to alc880_three_stack_mixer */
914 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
915         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
916         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
917         { } /* end */
918 };
919
920 /* channel source setting (6/8 channel selection for 5-stack) */
921 /* 6ch mode */
922 static struct hda_verb alc880_fivestack_ch6_init[] = {
923         /* set line-in to input, mute it */
924         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
925         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
926         { } /* end */
927 };
928
929 /* 8ch mode */
930 static struct hda_verb alc880_fivestack_ch8_init[] = {
931         /* set line-in to output, unmute it */
932         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
933         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
934         { } /* end */
935 };
936
937 static struct hda_channel_mode alc880_fivestack_modes[2] = {
938         { 6, alc880_fivestack_ch6_init },
939         { 8, alc880_fivestack_ch8_init },
940 };
941
942
943 /*
944  * ALC880 6-stack model
945  *
946  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
947  *      Side = 0x05 (0x0f)
948  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
949  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
950  */
951
952 static hda_nid_t alc880_6st_dac_nids[4] = {
953         /* front, rear, clfe, rear_surr */
954         0x02, 0x03, 0x04, 0x05
955 };
956
957 static struct hda_input_mux alc880_6stack_capture_source = {
958         .num_items = 4,
959         .items = {
960                 { "Mic", 0x0 },
961                 { "Front Mic", 0x1 },
962                 { "Line", 0x2 },
963                 { "CD", 0x4 },
964         },
965 };
966
967 /* fixed 8-channels */
968 static struct hda_channel_mode alc880_sixstack_modes[1] = {
969         { 8, NULL },
970 };
971
972 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
973         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
974         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
975         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
976         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
977         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
978         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
979         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
980         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
981         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
982         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
983         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
984         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
985         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
986         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
987         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
988         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
989         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
990         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
991         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
992         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
993         {
994                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
995                 .name = "Channel Mode",
996                 .info = alc_ch_mode_info,
997                 .get = alc_ch_mode_get,
998                 .put = alc_ch_mode_put,
999         },
1000         { } /* end */
1001 };
1002
1003
1004 /*
1005  * ALC880 W810 model
1006  *
1007  * W810 has rear IO for:
1008  * Front (DAC 02)
1009  * Surround (DAC 03)
1010  * Center/LFE (DAC 04)
1011  * Digital out (06)
1012  *
1013  * The system also has a pair of internal speakers, and a headphone jack.
1014  * These are both connected to Line2 on the codec, hence to DAC 02.
1015  * 
1016  * There is a variable resistor to control the speaker or headphone
1017  * volume. This is a hardware-only device without a software API.
1018  *
1019  * Plugging headphones in will disable the internal speakers. This is
1020  * implemented in hardware, not via the driver using jack sense. In
1021  * a similar fashion, plugging into the rear socket marked "front" will
1022  * disable both the speakers and headphones.
1023  *
1024  * For input, there's a microphone jack, and an "audio in" jack.
1025  * These may not do anything useful with this driver yet, because I
1026  * haven't setup any initialization verbs for these yet...
1027  */
1028
1029 static hda_nid_t alc880_w810_dac_nids[3] = {
1030         /* front, rear/surround, clfe */
1031         0x02, 0x03, 0x04
1032 };
1033
1034 /* fixed 6 channels */
1035 static struct hda_channel_mode alc880_w810_modes[1] = {
1036         { 6, NULL }
1037 };
1038
1039 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
1040 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
1041         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1042         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1043         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1044         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1045         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1046         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1047         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1048         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1049         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1050         { } /* end */
1051 };
1052
1053
1054 /*
1055  * Z710V model
1056  *
1057  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
1058  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
1059  *                 Line = 0x1a
1060  */
1061
1062 static hda_nid_t alc880_z71v_dac_nids[1] = {
1063         0x02
1064 };
1065 #define ALC880_Z71V_HP_DAC      0x03
1066
1067 /* fixed 2 channels */
1068 static struct hda_channel_mode alc880_2_jack_modes[1] = {
1069         { 2, NULL }
1070 };
1071
1072 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
1073         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1074         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1075         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1076         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
1077         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1078         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1079         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1080         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1081         { } /* end */
1082 };
1083
1084
1085 /* FIXME! */
1086 /*
1087  * ALC880 F1734 model
1088  *
1089  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
1090  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
1091  */
1092
1093 static hda_nid_t alc880_f1734_dac_nids[1] = {
1094         0x03
1095 };
1096 #define ALC880_F1734_HP_DAC     0x02
1097
1098 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
1099         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1100         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1101         HDA_CODEC_VOLUME("Internal Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1102         HDA_BIND_MUTE("Internal Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1103         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1104         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1105         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1106         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1107         { } /* end */
1108 };
1109
1110
1111 /* FIXME! */
1112 /*
1113  * ALC880 ASUS model
1114  *
1115  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1116  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1117  *  Mic = 0x18, Line = 0x1a
1118  */
1119
1120 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
1121 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
1122
1123 static struct snd_kcontrol_new alc880_asus_mixer[] = {
1124         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1125         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1126         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1127         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1128         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1129         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1130         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1131         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1132         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1133         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1134         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1135         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1136         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1137         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1138         {
1139                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1140                 .name = "Channel Mode",
1141                 .info = alc_ch_mode_info,
1142                 .get = alc_ch_mode_get,
1143                 .put = alc_ch_mode_put,
1144         },
1145         { } /* end */
1146 };
1147
1148 /* FIXME! */
1149 /*
1150  * ALC880 ASUS W1V model
1151  *
1152  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1153  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1154  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
1155  */
1156
1157 /* additional mixers to alc880_asus_mixer */
1158 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
1159         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
1160         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
1161         { } /* end */
1162 };
1163
1164 /* additional mixers to alc880_asus_mixer */
1165 static struct snd_kcontrol_new alc880_pcbeep_mixer[] = {
1166         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1167         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1168         { } /* end */
1169 };
1170
1171 /* TCL S700 */
1172 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
1173         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1174         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1175         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1176         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
1177         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
1178         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
1179         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
1180         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1181         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1182         {
1183                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1184                 /* The multiple "Capture Source" controls confuse alsamixer
1185                  * So call somewhat different..
1186                  * FIXME: the controls appear in the "playback" view!
1187                  */
1188                 /* .name = "Capture Source", */
1189                 .name = "Input Source",
1190                 .count = 1,
1191                 .info = alc_mux_enum_info,
1192                 .get = alc_mux_enum_get,
1193                 .put = alc_mux_enum_put,
1194         },
1195         { } /* end */
1196 };
1197
1198 /* Uniwill */
1199 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
1200         HDA_CODEC_VOLUME("HPhone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1201         HDA_BIND_MUTE("HPhone Playback Switch", 0x0c, 2, HDA_INPUT),
1202         HDA_CODEC_VOLUME("iSpeaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1203         HDA_BIND_MUTE("iSpeaker Playback Switch", 0x0d, 2, HDA_INPUT),
1204         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1205         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1206         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1207         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1208         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1209         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1210         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1211         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, 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         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1215         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1216         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1217         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1218         {
1219                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1220                 .name = "Channel Mode",
1221                 .info = alc_ch_mode_info,
1222                 .get = alc_ch_mode_get,
1223                 .put = alc_ch_mode_put,
1224         },
1225         { } /* end */
1226 };
1227
1228 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
1229         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1230         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1231         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1232         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1233         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1234         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1235         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1236         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1237         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1238         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1239         { } /* end */
1240 };
1241
1242 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
1243         HDA_CODEC_VOLUME("HPhone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1244         HDA_BIND_MUTE("HPhone Playback Switch", 0x0c, 2, HDA_INPUT),
1245         HDA_CODEC_VOLUME("iSpeaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1246         HDA_BIND_MUTE("iSpeaker Playback Switch", 0x0d, 2, HDA_INPUT),
1247         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1248         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1249         { } /* end */
1250 };
1251
1252 /*
1253  * build control elements
1254  */
1255 static int alc_build_controls(struct hda_codec *codec)
1256 {
1257         struct alc_spec *spec = codec->spec;
1258         int err;
1259         int i;
1260
1261         for (i = 0; i < spec->num_mixers; i++) {
1262                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1263                 if (err < 0)
1264                         return err;
1265         }
1266
1267         if (spec->multiout.dig_out_nid) {
1268                 err = snd_hda_create_spdif_out_ctls(codec,
1269                                                     spec->multiout.dig_out_nid);
1270                 if (err < 0)
1271                         return err;
1272         }
1273         if (spec->dig_in_nid) {
1274                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1275                 if (err < 0)
1276                         return err;
1277         }
1278         return 0;
1279 }
1280
1281
1282 /*
1283  * initialize the codec volumes, etc
1284  */
1285
1286 /*
1287  * generic initialization of ADC, input mixers and output mixers
1288  */
1289 static struct hda_verb alc880_volume_init_verbs[] = {
1290         /*
1291          * Unmute ADC0-2 and set the default input to mic-in
1292          */
1293         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
1294         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1295         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
1296         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1297         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
1298         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1299
1300         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1301          * mixer widget
1302          * Note: PASD motherboards uses the Line In 2 as the input for front
1303          * panel mic (mic 2)
1304          */
1305         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
1306         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1307         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1308         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
1309         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
1310         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
1311         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
1312         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
1313
1314         /*
1315          * Set up output mixers (0x0c - 0x0f)
1316          */
1317         /* set vol=0 to output mixers */
1318         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1319         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1320         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1321         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1322         /* set up input amps for analog loopback */
1323         /* Amp Indices: DAC = 0, mixer = 1 */
1324         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1325         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1326         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1327         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1328         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1329         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1330         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1331         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1332
1333         { }
1334 };
1335
1336 /*
1337  * 3-stack pin configuration:
1338  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
1339  */
1340 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
1341         /*
1342          * preset connection lists of input pins
1343          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1344          */
1345         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
1346         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1347         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
1348
1349         /*
1350          * Set pin mode and muting
1351          */
1352         /* set front pin widgets 0x14 for output */
1353         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1354         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1355         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1356         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1357         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1358         /* Mic2 (as headphone out) for HP output */
1359         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1360         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1361         /* Line In pin widget for input */
1362         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1363         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1364         /* Line2 (as front mic) pin widget for input and vref at 80% */
1365         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1366         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1367         /* CD pin widget for input */
1368         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1369
1370         { }
1371 };
1372
1373 /*
1374  * 5-stack pin configuration:
1375  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
1376  * line-in/side = 0x1a, f-mic = 0x1b
1377  */
1378 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
1379         /*
1380          * preset connection lists of input pins
1381          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1382          */
1383         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1384         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
1385
1386         /*
1387          * Set pin mode and muting
1388          */
1389         /* set pin widgets 0x14-0x17 for output */
1390         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1391         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1392         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1393         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1394         /* unmute pins for output (no gain on this amp) */
1395         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1396         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1397         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1398         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1399
1400         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1401         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1402         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1403         /* Mic2 (as headphone out) for HP output */
1404         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1405         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1406         /* Line In pin widget for input */
1407         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1408         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1409         /* Line2 (as front mic) pin widget for input and vref at 80% */
1410         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1411         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1412         /* CD pin widget for input */
1413         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1414
1415         { }
1416 };
1417
1418 /*
1419  * W810 pin configuration:
1420  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
1421  */
1422 static struct hda_verb alc880_pin_w810_init_verbs[] = {
1423         /* hphone/speaker input selector: front DAC */
1424         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
1425
1426         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1427         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1428         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1429         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1430         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1431         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1432
1433         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1434         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1435
1436         { }
1437 };
1438
1439 /*
1440  * Z71V pin configuration:
1441  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
1442  */
1443 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
1444         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1445         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1446         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1447         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1448
1449         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1450         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1451         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1452         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1453
1454         { }
1455 };
1456
1457 /*
1458  * 6-stack pin configuration:
1459  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
1460  * f-mic = 0x19, line = 0x1a, HP = 0x1b
1461  */
1462 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
1463         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1464
1465         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1466         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1467         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1468         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1469         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1470         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1471         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1472         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1473
1474         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1475         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1476         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1477         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1478         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1479         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1480         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1481         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1482         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1483         
1484         { }
1485 };
1486
1487 /*
1488  * Uniwill pin configuration:
1489  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
1490  * line = 0x1a
1491  */
1492 static struct hda_verb alc880_uniwill_init_verbs[] = {
1493         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1494
1495         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1496         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1497         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1498         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1499         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1500         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1501         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1502         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1503         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1504         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1505         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1506         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1507         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1508         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1509
1510         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1511         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1512         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1513         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1514         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1515         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1516         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
1517         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
1518         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1519
1520         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
1521         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
1522
1523         { }
1524 };
1525
1526 /*
1527 * Uniwill P53
1528 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19, 
1529  */
1530 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
1531         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1532
1533         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1534         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1535         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1536         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1537         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1538         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1539         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1540         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1541         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1542         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1543         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1544         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1545
1546         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1547         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1548         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1549         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1550         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1551         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1552
1553         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
1554         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
1555
1556         { }
1557 };
1558
1559 static struct hda_verb alc880_beep_init_verbs[] = {
1560         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
1561         { }
1562 };
1563
1564 /* toggle speaker-output according to the hp-jack state */
1565 static void alc880_uniwill_hp_automute(struct hda_codec *codec)
1566 {
1567         unsigned int present;
1568         unsigned char bits;
1569
1570         present = snd_hda_codec_read(codec, 0x14, 0,
1571                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1572         bits = present ? HDA_AMP_MUTE : 0;
1573         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
1574                                  HDA_AMP_MUTE, bits);
1575         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
1576                                  HDA_AMP_MUTE, bits);
1577 }
1578
1579 /* auto-toggle front mic */
1580 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
1581 {
1582         unsigned int present;
1583         unsigned char bits;
1584
1585         present = snd_hda_codec_read(codec, 0x18, 0,
1586                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1587         bits = present ? HDA_AMP_MUTE : 0;
1588         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
1589 }
1590
1591 static void alc880_uniwill_automute(struct hda_codec *codec)
1592 {
1593         alc880_uniwill_hp_automute(codec);
1594         alc880_uniwill_mic_automute(codec);
1595 }
1596
1597 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
1598                                        unsigned int res)
1599 {
1600         /* Looks like the unsol event is incompatible with the standard
1601          * definition.  4bit tag is placed at 28 bit!
1602          */
1603         switch (res >> 28) {
1604         case ALC880_HP_EVENT:
1605                 alc880_uniwill_hp_automute(codec);
1606                 break;
1607         case ALC880_MIC_EVENT:
1608                 alc880_uniwill_mic_automute(codec);
1609                 break;
1610         }
1611 }
1612
1613 static void alc880_uniwill_p53_hp_automute(struct hda_codec *codec)
1614 {
1615         unsigned int present;
1616         unsigned char bits;
1617
1618         present = snd_hda_codec_read(codec, 0x14, 0,
1619                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1620         bits = present ? HDA_AMP_MUTE : 0;
1621         snd_hda_codec_amp_stereo(codec, 0x15, HDA_INPUT, 0, HDA_AMP_MUTE, bits);
1622 }
1623
1624 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
1625 {
1626         unsigned int present;
1627         
1628         present = snd_hda_codec_read(codec, 0x21, 0,
1629                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
1630         present &= HDA_AMP_VOLMASK;
1631         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
1632                                  HDA_AMP_VOLMASK, present);
1633         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
1634                                  HDA_AMP_VOLMASK, present);
1635 }
1636
1637 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
1638                                            unsigned int res)
1639 {
1640         /* Looks like the unsol event is incompatible with the standard
1641          * definition.  4bit tag is placed at 28 bit!
1642          */
1643         if ((res >> 28) == ALC880_HP_EVENT)
1644                 alc880_uniwill_p53_hp_automute(codec);
1645         if ((res >> 28) == ALC880_DCVOL_EVENT)
1646                 alc880_uniwill_p53_dcvol_automute(codec);
1647 }
1648
1649 /* FIXME! */
1650 /*
1651  * F1734 pin configuration:
1652  * HP = 0x14, speaker-out = 0x15, mic = 0x18
1653  */
1654 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
1655         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
1656         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
1657         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
1658         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
1659
1660         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1661         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1662         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1663         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1664
1665         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1666         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1667         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1668         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1669         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1670         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1671         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1672         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1673         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1674
1675         { }
1676 };
1677
1678 /* FIXME! */
1679 /*
1680  * ASUS pin configuration:
1681  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
1682  */
1683 static struct hda_verb alc880_pin_asus_init_verbs[] = {
1684         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
1685         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
1686         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
1687         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
1688
1689         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1690         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1691         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1692         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1693         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1694         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1695         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1696         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1697
1698         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1699         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1700         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1701         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1702         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1703         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1704         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1705         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1706         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1707         
1708         { }
1709 };
1710
1711 /* Enable GPIO mask and set output */
1712 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
1713 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
1714
1715 /* Clevo m520g init */
1716 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
1717         /* headphone output */
1718         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
1719         /* line-out */
1720         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1721         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1722         /* Line-in */
1723         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1724         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1725         /* CD */
1726         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1727         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1728         /* Mic1 (rear panel) */
1729         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1730         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1731         /* Mic2 (front panel) */
1732         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1733         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1734         /* headphone */
1735         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1736         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1737         /* change to EAPD mode */
1738         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
1739         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
1740
1741         { }
1742 };
1743
1744 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
1745         /* change to EAPD mode */
1746         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
1747         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
1748
1749         /* Headphone output */
1750         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1751         /* Front output*/
1752         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1753         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1754
1755         /* Line In pin widget for input */
1756         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1757         /* CD pin widget for input */
1758         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1759         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1760         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1761
1762         /* change to EAPD mode */
1763         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
1764         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
1765
1766         { }
1767 };
1768
1769 /*
1770  * LG m1 express dual
1771  *
1772  * Pin assignment:
1773  *   Rear Line-In/Out (blue): 0x14
1774  *   Build-in Mic-In: 0x15
1775  *   Speaker-out: 0x17
1776  *   HP-Out (green): 0x1b
1777  *   Mic-In/Out (red): 0x19
1778  *   SPDIF-Out: 0x1e
1779  */
1780
1781 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
1782 static hda_nid_t alc880_lg_dac_nids[3] = {
1783         0x05, 0x02, 0x03
1784 };
1785
1786 /* seems analog CD is not working */
1787 static struct hda_input_mux alc880_lg_capture_source = {
1788         .num_items = 3,
1789         .items = {
1790                 { "Mic", 0x1 },
1791                 { "Line", 0x5 },
1792                 { "Internal Mic", 0x6 },
1793         },
1794 };
1795
1796 /* 2,4,6 channel modes */
1797 static struct hda_verb alc880_lg_ch2_init[] = {
1798         /* set line-in and mic-in to input */
1799         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1800         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1801         { }
1802 };
1803
1804 static struct hda_verb alc880_lg_ch4_init[] = {
1805         /* set line-in to out and mic-in to input */
1806         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1807         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1808         { }
1809 };
1810
1811 static struct hda_verb alc880_lg_ch6_init[] = {
1812         /* set line-in and mic-in to output */
1813         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1814         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1815         { }
1816 };
1817
1818 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
1819         { 2, alc880_lg_ch2_init },
1820         { 4, alc880_lg_ch4_init },
1821         { 6, alc880_lg_ch6_init },
1822 };
1823
1824 static struct snd_kcontrol_new alc880_lg_mixer[] = {
1825         /* FIXME: it's not really "master" but front channels */
1826         HDA_CODEC_VOLUME("Master Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1827         HDA_BIND_MUTE("Master Playback Switch", 0x0f, 2, HDA_INPUT),
1828         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1829         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
1830         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
1831         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
1832         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
1833         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
1834         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1835         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1836         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
1837         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
1838         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
1839         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
1840         {
1841                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1842                 .name = "Channel Mode",
1843                 .info = alc_ch_mode_info,
1844                 .get = alc_ch_mode_get,
1845                 .put = alc_ch_mode_put,
1846         },
1847         { } /* end */
1848 };
1849
1850 static struct hda_verb alc880_lg_init_verbs[] = {
1851         /* set capture source to mic-in */
1852         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1853         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1854         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1855         /* mute all amp mixer inputs */
1856         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
1857         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
1858         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
1859         /* line-in to input */
1860         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1861         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1862         /* built-in mic */
1863         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1864         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1865         /* speaker-out */
1866         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1867         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1868         /* mic-in to input */
1869         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
1870         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1871         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1872         /* HP-out */
1873         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
1874         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1875         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1876         /* jack sense */
1877         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
1878         { }
1879 };
1880
1881 /* toggle speaker-output according to the hp-jack state */
1882 static void alc880_lg_automute(struct hda_codec *codec)
1883 {
1884         unsigned int present;
1885         unsigned char bits;
1886
1887         present = snd_hda_codec_read(codec, 0x1b, 0,
1888                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1889         bits = present ? HDA_AMP_MUTE : 0;
1890         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
1891                                  HDA_AMP_MUTE, bits);
1892 }
1893
1894 static void alc880_lg_unsol_event(struct hda_codec *codec, unsigned int res)
1895 {
1896         /* Looks like the unsol event is incompatible with the standard
1897          * definition.  4bit tag is placed at 28 bit!
1898          */
1899         if ((res >> 28) == 0x01)
1900                 alc880_lg_automute(codec);
1901 }
1902
1903 /*
1904  * LG LW20
1905  *
1906  * Pin assignment:
1907  *   Speaker-out: 0x14
1908  *   Mic-In: 0x18
1909  *   Built-in Mic-In: 0x19
1910  *   Line-In: 0x1b
1911  *   HP-Out: 0x1a
1912  *   SPDIF-Out: 0x1e
1913  */
1914
1915 static struct hda_input_mux alc880_lg_lw_capture_source = {
1916         .num_items = 3,
1917         .items = {
1918                 { "Mic", 0x0 },
1919                 { "Internal Mic", 0x1 },
1920                 { "Line In", 0x2 },
1921         },
1922 };
1923
1924 #define alc880_lg_lw_modes alc880_threestack_modes
1925
1926 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
1927         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1928         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1929         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1930         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1931         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1932         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1933         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1934         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1935         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1936         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1937         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1938         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1939         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
1940         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
1941         {
1942                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1943                 .name = "Channel Mode",
1944                 .info = alc_ch_mode_info,
1945                 .get = alc_ch_mode_get,
1946                 .put = alc_ch_mode_put,
1947         },
1948         { } /* end */
1949 };
1950
1951 static struct hda_verb alc880_lg_lw_init_verbs[] = {
1952         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1953         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
1954         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
1955
1956         /* set capture source to mic-in */
1957         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1958         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1959         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1960         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
1961         /* speaker-out */
1962         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1963         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1964         /* HP-out */
1965         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1966         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1967         /* mic-in to input */
1968         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1969         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1970         /* built-in mic */
1971         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1972         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1973         /* jack sense */
1974         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
1975         { }
1976 };
1977
1978 /* toggle speaker-output according to the hp-jack state */
1979 static void alc880_lg_lw_automute(struct hda_codec *codec)
1980 {
1981         unsigned int present;
1982         unsigned char bits;
1983
1984         present = snd_hda_codec_read(codec, 0x1b, 0,
1985                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1986         bits = present ? HDA_AMP_MUTE : 0;
1987         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
1988                                  HDA_AMP_MUTE, bits);
1989 }
1990
1991 static void alc880_lg_lw_unsol_event(struct hda_codec *codec, unsigned int res)
1992 {
1993         /* Looks like the unsol event is incompatible with the standard
1994          * definition.  4bit tag is placed at 28 bit!
1995          */
1996         if ((res >> 28) == 0x01)
1997                 alc880_lg_lw_automute(codec);
1998 }
1999
2000 #ifdef CONFIG_SND_HDA_POWER_SAVE
2001 static struct hda_amp_list alc880_loopbacks[] = {
2002         { 0x0b, HDA_INPUT, 0 },
2003         { 0x0b, HDA_INPUT, 1 },
2004         { 0x0b, HDA_INPUT, 2 },
2005         { 0x0b, HDA_INPUT, 3 },
2006         { 0x0b, HDA_INPUT, 4 },
2007         { } /* end */
2008 };
2009
2010 static struct hda_amp_list alc880_lg_loopbacks[] = {
2011         { 0x0b, HDA_INPUT, 1 },
2012         { 0x0b, HDA_INPUT, 6 },
2013         { 0x0b, HDA_INPUT, 7 },
2014         { } /* end */
2015 };
2016 #endif
2017
2018 /*
2019  * Common callbacks
2020  */
2021
2022 static int alc_init(struct hda_codec *codec)
2023 {
2024         struct alc_spec *spec = codec->spec;
2025         unsigned int i;
2026
2027         for (i = 0; i < spec->num_init_verbs; i++)
2028                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2029
2030         if (spec->init_hook)
2031                 spec->init_hook(codec);
2032
2033         return 0;
2034 }
2035
2036 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2037 {
2038         struct alc_spec *spec = codec->spec;
2039
2040         if (spec->unsol_event)
2041                 spec->unsol_event(codec, res);
2042 }
2043
2044 #ifdef CONFIG_SND_HDA_POWER_SAVE
2045 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2046 {
2047         struct alc_spec *spec = codec->spec;
2048         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2049 }
2050 #endif
2051
2052 /*
2053  * Analog playback callbacks
2054  */
2055 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
2056                                     struct hda_codec *codec,
2057                                     struct snd_pcm_substream *substream)
2058 {
2059         struct alc_spec *spec = codec->spec;
2060         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
2061 }
2062
2063 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2064                                        struct hda_codec *codec,
2065                                        unsigned int stream_tag,
2066                                        unsigned int format,
2067                                        struct snd_pcm_substream *substream)
2068 {
2069         struct alc_spec *spec = codec->spec;
2070         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2071                                                 stream_tag, format, substream);
2072 }
2073
2074 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2075                                        struct hda_codec *codec,
2076                                        struct snd_pcm_substream *substream)
2077 {
2078         struct alc_spec *spec = codec->spec;
2079         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2080 }
2081
2082 /*
2083  * Digital out
2084  */
2085 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2086                                         struct hda_codec *codec,
2087                                         struct snd_pcm_substream *substream)
2088 {
2089         struct alc_spec *spec = codec->spec;
2090         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2091 }
2092
2093 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2094                                            struct hda_codec *codec,
2095                                            unsigned int stream_tag,
2096                                            unsigned int format,
2097                                            struct snd_pcm_substream *substream)
2098 {
2099         struct alc_spec *spec = codec->spec;
2100         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2101                                              stream_tag, format, substream);
2102 }
2103
2104 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2105                                          struct hda_codec *codec,
2106                                          struct snd_pcm_substream *substream)
2107 {
2108         struct alc_spec *spec = codec->spec;
2109         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2110 }
2111
2112 /*
2113  * Analog capture
2114  */
2115 static int alc880_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2116                                       struct hda_codec *codec,
2117                                       unsigned int stream_tag,
2118                                       unsigned int format,
2119                                       struct snd_pcm_substream *substream)
2120 {
2121         struct alc_spec *spec = codec->spec;
2122
2123         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
2124                                    stream_tag, 0, format);
2125         return 0;
2126 }
2127
2128 static int alc880_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2129                                       struct hda_codec *codec,
2130                                       struct snd_pcm_substream *substream)
2131 {
2132         struct alc_spec *spec = codec->spec;
2133
2134         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
2135                                    0, 0, 0);
2136         return 0;
2137 }
2138
2139
2140 /*
2141  */
2142 static struct hda_pcm_stream alc880_pcm_analog_playback = {
2143         .substreams = 1,
2144         .channels_min = 2,
2145         .channels_max = 8,
2146         /* NID is set in alc_build_pcms */
2147         .ops = {
2148                 .open = alc880_playback_pcm_open,
2149                 .prepare = alc880_playback_pcm_prepare,
2150                 .cleanup = alc880_playback_pcm_cleanup
2151         },
2152 };
2153
2154 static struct hda_pcm_stream alc880_pcm_analog_capture = {
2155         .substreams = 2,
2156         .channels_min = 2,
2157         .channels_max = 2,
2158         /* NID is set in alc_build_pcms */
2159         .ops = {
2160                 .prepare = alc880_capture_pcm_prepare,
2161                 .cleanup = alc880_capture_pcm_cleanup
2162         },
2163 };
2164
2165 static struct hda_pcm_stream alc880_pcm_digital_playback = {
2166         .substreams = 1,
2167         .channels_min = 2,
2168         .channels_max = 2,
2169         /* NID is set in alc_build_pcms */
2170         .ops = {
2171                 .open = alc880_dig_playback_pcm_open,
2172                 .close = alc880_dig_playback_pcm_close,
2173                 .prepare = alc880_dig_playback_pcm_prepare
2174         },
2175 };
2176
2177 static struct hda_pcm_stream alc880_pcm_digital_capture = {
2178         .substreams = 1,
2179         .channels_min = 2,
2180         .channels_max = 2,
2181         /* NID is set in alc_build_pcms */
2182 };
2183
2184 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2185 static struct hda_pcm_stream alc_pcm_null_playback = {
2186         .substreams = 0,
2187         .channels_min = 0,
2188         .channels_max = 0,
2189 };
2190
2191 static int alc_build_pcms(struct hda_codec *codec)
2192 {
2193         struct alc_spec *spec = codec->spec;
2194         struct hda_pcm *info = spec->pcm_rec;
2195         int i;
2196
2197         codec->num_pcms = 1;
2198         codec->pcm_info = info;
2199
2200         info->name = spec->stream_name_analog;
2201         if (spec->stream_analog_playback) {
2202                 snd_assert(spec->multiout.dac_nids, return -EINVAL);
2203                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
2204                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2205         }
2206         if (spec->stream_analog_capture) {
2207                 snd_assert(spec->adc_nids, return -EINVAL);
2208                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
2209                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2210         }
2211
2212         if (spec->channel_mode) {
2213                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2214                 for (i = 0; i < spec->num_channel_mode; i++) {
2215                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2216                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2217                         }
2218                 }
2219         }
2220
2221         /* SPDIF for stream index #1 */
2222         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2223                 codec->num_pcms = 2;
2224                 info = spec->pcm_rec + 1;
2225                 info->name = spec->stream_name_digital;
2226                 if (spec->multiout.dig_out_nid &&
2227                     spec->stream_digital_playback) {
2228                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
2229                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2230                 }
2231                 if (spec->dig_in_nid &&
2232                     spec->stream_digital_capture) {
2233                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
2234                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2235                 }
2236         }
2237
2238         /* If the use of more than one ADC is requested for the current
2239          * model, configure a second analog capture-only PCM.
2240          */
2241         /* Additional Analaog capture for index #2 */
2242         if (spec->num_adc_nids > 1 && spec->stream_analog_capture &&
2243             spec->adc_nids) {
2244                 codec->num_pcms = 3;
2245                 info = spec->pcm_rec + 2;
2246                 info->name = spec->stream_name_analog;
2247                 /* No playback stream for second PCM */
2248                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = alc_pcm_null_playback;
2249                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2250                 if (spec->stream_analog_capture) {
2251                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
2252                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[1];
2253                 }
2254         }
2255
2256         return 0;
2257 }
2258
2259 static void alc_free(struct hda_codec *codec)
2260 {
2261         struct alc_spec *spec = codec->spec;
2262         unsigned int i;
2263
2264         if (!spec)
2265                 return;
2266
2267         if (spec->kctl_alloc) {
2268                 for (i = 0; i < spec->num_kctl_used; i++)
2269                         kfree(spec->kctl_alloc[i].name);
2270                 kfree(spec->kctl_alloc);
2271         }
2272         kfree(spec);
2273 }
2274
2275 /*
2276  */
2277 static struct hda_codec_ops alc_patch_ops = {
2278         .build_controls = alc_build_controls,
2279         .build_pcms = alc_build_pcms,
2280         .init = alc_init,
2281         .free = alc_free,
2282         .unsol_event = alc_unsol_event,
2283 #ifdef CONFIG_SND_HDA_POWER_SAVE
2284         .check_power_status = alc_check_power_status,
2285 #endif
2286 };
2287
2288
2289 /*
2290  * Test configuration for debugging
2291  *
2292  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
2293  * enum controls.
2294  */
2295 #ifdef CONFIG_SND_DEBUG
2296 static hda_nid_t alc880_test_dac_nids[4] = {
2297         0x02, 0x03, 0x04, 0x05
2298 };
2299
2300 static struct hda_input_mux alc880_test_capture_source = {
2301         .num_items = 7,
2302         .items = {
2303                 { "In-1", 0x0 },
2304                 { "In-2", 0x1 },
2305                 { "In-3", 0x2 },
2306                 { "In-4", 0x3 },
2307                 { "CD", 0x4 },
2308                 { "Front", 0x5 },
2309                 { "Surround", 0x6 },
2310         },
2311 };
2312
2313 static struct hda_channel_mode alc880_test_modes[4] = {
2314         { 2, NULL },
2315         { 4, NULL },
2316         { 6, NULL },
2317         { 8, NULL },
2318 };
2319
2320 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
2321                                  struct snd_ctl_elem_info *uinfo)
2322 {
2323         static char *texts[] = {
2324                 "N/A", "Line Out", "HP Out",
2325                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
2326         };
2327         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2328         uinfo->count = 1;
2329         uinfo->value.enumerated.items = 8;
2330         if (uinfo->value.enumerated.item >= 8)
2331                 uinfo->value.enumerated.item = 7;
2332         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2333         return 0;
2334 }
2335
2336 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
2337                                 struct snd_ctl_elem_value *ucontrol)
2338 {
2339         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2340         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2341         unsigned int pin_ctl, item = 0;
2342
2343         pin_ctl = snd_hda_codec_read(codec, nid, 0,
2344                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2345         if (pin_ctl & AC_PINCTL_OUT_EN) {
2346                 if (pin_ctl & AC_PINCTL_HP_EN)
2347                         item = 2;
2348                 else
2349                         item = 1;
2350         } else if (pin_ctl & AC_PINCTL_IN_EN) {
2351                 switch (pin_ctl & AC_PINCTL_VREFEN) {
2352                 case AC_PINCTL_VREF_HIZ: item = 3; break;
2353                 case AC_PINCTL_VREF_50:  item = 4; break;
2354                 case AC_PINCTL_VREF_GRD: item = 5; break;
2355                 case AC_PINCTL_VREF_80:  item = 6; break;
2356                 case AC_PINCTL_VREF_100: item = 7; break;
2357                 }
2358         }
2359         ucontrol->value.enumerated.item[0] = item;
2360         return 0;
2361 }
2362
2363 static int alc_test_pin_ctl_put(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         static unsigned int ctls[] = {
2369                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
2370                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
2371                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
2372                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
2373                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
2374                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
2375         };
2376         unsigned int old_ctl, new_ctl;
2377
2378         old_ctl = snd_hda_codec_read(codec, nid, 0,
2379                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2380         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
2381         if (old_ctl != new_ctl) {
2382                 int val;
2383                 snd_hda_codec_write_cache(codec, nid, 0,
2384                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
2385                                           new_ctl);
2386                 val = ucontrol->value.enumerated.item[0] >= 3 ?
2387                         HDA_AMP_MUTE : 0;
2388                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
2389                                          HDA_AMP_MUTE, val);
2390                 return 1;
2391         }
2392         return 0;
2393 }
2394
2395 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
2396                                  struct snd_ctl_elem_info *uinfo)
2397 {
2398         static char *texts[] = {
2399                 "Front", "Surround", "CLFE", "Side"
2400         };
2401         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2402         uinfo->count = 1;
2403         uinfo->value.enumerated.items = 4;
2404         if (uinfo->value.enumerated.item >= 4)
2405                 uinfo->value.enumerated.item = 3;
2406         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2407         return 0;
2408 }
2409
2410 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
2411                                 struct snd_ctl_elem_value *ucontrol)
2412 {
2413         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2414         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2415         unsigned int sel;
2416
2417         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
2418         ucontrol->value.enumerated.item[0] = sel & 3;
2419         return 0;
2420 }
2421
2422 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
2423                                 struct snd_ctl_elem_value *ucontrol)
2424 {
2425         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2426         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2427         unsigned int sel;
2428
2429         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
2430         if (ucontrol->value.enumerated.item[0] != sel) {
2431                 sel = ucontrol->value.enumerated.item[0] & 3;
2432                 snd_hda_codec_write_cache(codec, nid, 0,
2433                                           AC_VERB_SET_CONNECT_SEL, sel);
2434                 return 1;
2435         }
2436         return 0;
2437 }
2438
2439 #define PIN_CTL_TEST(xname,nid) {                       \
2440                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
2441                         .name = xname,                 \
2442                         .info = alc_test_pin_ctl_info, \
2443                         .get = alc_test_pin_ctl_get,   \
2444                         .put = alc_test_pin_ctl_put,   \
2445                         .private_value = nid           \
2446                         }
2447
2448 #define PIN_SRC_TEST(xname,nid) {                       \
2449                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
2450                         .name = xname,                 \
2451                         .info = alc_test_pin_src_info, \
2452                         .get = alc_test_pin_src_get,   \
2453                         .put = alc_test_pin_src_put,   \
2454                         .private_value = nid           \
2455                         }
2456
2457 static struct snd_kcontrol_new alc880_test_mixer[] = {
2458         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2459         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2460         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
2461         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2462         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2463         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2464         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
2465         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2466         PIN_CTL_TEST("Front Pin Mode", 0x14),
2467         PIN_CTL_TEST("Surround Pin Mode", 0x15),
2468         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
2469         PIN_CTL_TEST("Side Pin Mode", 0x17),
2470         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
2471         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
2472         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
2473         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
2474         PIN_SRC_TEST("In-1 Pin Source", 0x18),
2475         PIN_SRC_TEST("In-2 Pin Source", 0x19),
2476         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
2477         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
2478         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
2479         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
2480         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
2481         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
2482         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
2483         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
2484         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
2485         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
2486         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
2487         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
2488         {
2489                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2490                 .name = "Channel Mode",
2491                 .info = alc_ch_mode_info,
2492                 .get = alc_ch_mode_get,
2493                 .put = alc_ch_mode_put,
2494         },
2495         { } /* end */
2496 };
2497
2498 static struct hda_verb alc880_test_init_verbs[] = {
2499         /* Unmute inputs of 0x0c - 0x0f */
2500         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2501         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2502         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2503         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2504         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2505         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2506         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2507         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2508         /* Vol output for 0x0c-0x0f */
2509         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2510         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2511         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2512         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2513         /* Set output pins 0x14-0x17 */
2514         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2515         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2516         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2517         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2518         /* Unmute output pins 0x14-0x17 */
2519         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2520         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2521         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2522         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2523         /* Set input pins 0x18-0x1c */
2524         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2525         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2526         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2527         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2528         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2529         /* Mute input pins 0x18-0x1b */
2530         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2531         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2532         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2533         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2534         /* ADC set up */
2535         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2536         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2537         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2538         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2539         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2540         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2541         /* Analog input/passthru */
2542         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2543         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2544         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2545         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2546         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2547         { }
2548 };
2549 #endif
2550
2551 /*
2552  */
2553
2554 static const char *alc880_models[ALC880_MODEL_LAST] = {
2555         [ALC880_3ST]            = "3stack",
2556         [ALC880_TCL_S700]       = "tcl",
2557         [ALC880_3ST_DIG]        = "3stack-digout",
2558         [ALC880_CLEVO]          = "clevo",
2559         [ALC880_5ST]            = "5stack",
2560         [ALC880_5ST_DIG]        = "5stack-digout",
2561         [ALC880_W810]           = "w810",
2562         [ALC880_Z71V]           = "z71v",
2563         [ALC880_6ST]            = "6stack",
2564         [ALC880_6ST_DIG]        = "6stack-digout",
2565         [ALC880_ASUS]           = "asus",
2566         [ALC880_ASUS_W1V]       = "asus-w1v",
2567         [ALC880_ASUS_DIG]       = "asus-dig",
2568         [ALC880_ASUS_DIG2]      = "asus-dig2",
2569         [ALC880_UNIWILL_DIG]    = "uniwill",
2570         [ALC880_UNIWILL_P53]    = "uniwill-p53",
2571         [ALC880_FUJITSU]        = "fujitsu",
2572         [ALC880_F1734]          = "F1734",
2573         [ALC880_LG]             = "lg",
2574         [ALC880_LG_LW]          = "lg-lw",
2575 #ifdef CONFIG_SND_DEBUG
2576         [ALC880_TEST]           = "test",
2577 #endif
2578         [ALC880_AUTO]           = "auto",
2579 };
2580
2581 static struct snd_pci_quirk alc880_cfg_tbl[] = {
2582         /* Broken BIOS configuration */
2583         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG),
2584         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
2585
2586         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
2587         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
2588         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
2589         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
2590         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
2591         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
2592         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
2593         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
2594         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
2595
2596         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
2597         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
2598
2599         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
2600         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
2601         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
2602         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
2603         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
2604         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
2605         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
2606         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
2607         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
2608         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
2609         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS", ALC880_ASUS),
2610         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
2611         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
2612         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
2613         SND_PCI_QUIRK(0x1043, 0, "ASUS", ALC880_ASUS),
2614
2615         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
2616         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
2617         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
2618         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
2619         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
2620         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
2621         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
2622         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
2623         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
2624         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
2625         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
2626         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
2627         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
2628         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
2629         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
2630         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
2631         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
2632         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
2633
2634         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
2635         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
2636         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
2637         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
2638
2639         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
2640         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
2641         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
2642         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
2643
2644         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
2645         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
2646         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
2647         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
2648
2649         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
2650         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
2651         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
2652         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
2653         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
2654         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
2655         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
2656         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
2657         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
2658         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
2659         SND_PCI_QUIRK(0x8086, 0, "Intel mobo", ALC880_3ST),
2660
2661         {}
2662 };
2663
2664 /*
2665  * ALC880 codec presets
2666  */
2667 static struct alc_config_preset alc880_presets[] = {
2668         [ALC880_3ST] = {
2669                 .mixers = { alc880_three_stack_mixer },
2670                 .init_verbs = { alc880_volume_init_verbs,
2671                                 alc880_pin_3stack_init_verbs },
2672                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2673                 .dac_nids = alc880_dac_nids,
2674                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
2675                 .channel_mode = alc880_threestack_modes,
2676                 .need_dac_fix = 1,
2677                 .input_mux = &alc880_capture_source,
2678         },
2679         [ALC880_3ST_DIG] = {
2680                 .mixers = { alc880_three_stack_mixer },
2681                 .init_verbs = { alc880_volume_init_verbs,
2682                                 alc880_pin_3stack_init_verbs },
2683                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2684                 .dac_nids = alc880_dac_nids,
2685                 .dig_out_nid = ALC880_DIGOUT_NID,
2686                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
2687                 .channel_mode = alc880_threestack_modes,
2688                 .need_dac_fix = 1,
2689                 .input_mux = &alc880_capture_source,
2690         },
2691         [ALC880_TCL_S700] = {
2692                 .mixers = { alc880_tcl_s700_mixer },
2693                 .init_verbs = { alc880_volume_init_verbs,
2694                                 alc880_pin_tcl_S700_init_verbs,
2695                                 alc880_gpio2_init_verbs },
2696                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2697                 .dac_nids = alc880_dac_nids,
2698                 .hp_nid = 0x03,
2699                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
2700                 .channel_mode = alc880_2_jack_modes,
2701                 .input_mux = &alc880_capture_source,
2702         },
2703         [ALC880_5ST] = {
2704                 .mixers = { alc880_three_stack_mixer,
2705                             alc880_five_stack_mixer},
2706                 .init_verbs = { alc880_volume_init_verbs,
2707                                 alc880_pin_5stack_init_verbs },
2708                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2709                 .dac_nids = alc880_dac_nids,
2710                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
2711                 .channel_mode = alc880_fivestack_modes,
2712                 .input_mux = &alc880_capture_source,
2713         },
2714         [ALC880_5ST_DIG] = {
2715                 .mixers = { alc880_three_stack_mixer,
2716                             alc880_five_stack_mixer },
2717                 .init_verbs = { alc880_volume_init_verbs,
2718                                 alc880_pin_5stack_init_verbs },
2719                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2720                 .dac_nids = alc880_dac_nids,
2721                 .dig_out_nid = ALC880_DIGOUT_NID,
2722                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
2723                 .channel_mode = alc880_fivestack_modes,
2724                 .input_mux = &alc880_capture_source,
2725         },
2726         [ALC880_6ST] = {
2727                 .mixers = { alc880_six_stack_mixer },
2728                 .init_verbs = { alc880_volume_init_verbs,
2729                                 alc880_pin_6stack_init_verbs },
2730                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
2731                 .dac_nids = alc880_6st_dac_nids,
2732                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
2733                 .channel_mode = alc880_sixstack_modes,
2734                 .input_mux = &alc880_6stack_capture_source,
2735         },
2736         [ALC880_6ST_DIG] = {
2737                 .mixers = { alc880_six_stack_mixer },
2738                 .init_verbs = { alc880_volume_init_verbs,
2739                                 alc880_pin_6stack_init_verbs },
2740                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
2741                 .dac_nids = alc880_6st_dac_nids,
2742                 .dig_out_nid = ALC880_DIGOUT_NID,
2743                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
2744                 .channel_mode = alc880_sixstack_modes,
2745                 .input_mux = &alc880_6stack_capture_source,
2746         },
2747         [ALC880_W810] = {
2748                 .mixers = { alc880_w810_base_mixer },
2749                 .init_verbs = { alc880_volume_init_verbs,
2750                                 alc880_pin_w810_init_verbs,
2751                                 alc880_gpio2_init_verbs },
2752                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
2753                 .dac_nids = alc880_w810_dac_nids,
2754                 .dig_out_nid = ALC880_DIGOUT_NID,
2755                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
2756                 .channel_mode = alc880_w810_modes,
2757                 .input_mux = &alc880_capture_source,
2758         },
2759         [ALC880_Z71V] = {
2760                 .mixers = { alc880_z71v_mixer },
2761                 .init_verbs = { alc880_volume_init_verbs,
2762                                 alc880_pin_z71v_init_verbs },
2763                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
2764                 .dac_nids = alc880_z71v_dac_nids,
2765                 .dig_out_nid = ALC880_DIGOUT_NID,
2766                 .hp_nid = 0x03,
2767                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
2768                 .channel_mode = alc880_2_jack_modes,
2769                 .input_mux = &alc880_capture_source,
2770         },
2771         [ALC880_F1734] = {
2772                 .mixers = { alc880_f1734_mixer },
2773                 .init_verbs = { alc880_volume_init_verbs,
2774                                 alc880_pin_f1734_init_verbs },
2775                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
2776                 .dac_nids = alc880_f1734_dac_nids,
2777                 .hp_nid = 0x02,
2778                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
2779                 .channel_mode = alc880_2_jack_modes,
2780                 .input_mux = &alc880_capture_source,
2781         },
2782         [ALC880_ASUS] = {
2783                 .mixers = { alc880_asus_mixer },
2784                 .init_verbs = { alc880_volume_init_verbs,
2785                                 alc880_pin_asus_init_verbs,
2786                                 alc880_gpio1_init_verbs },
2787                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2788                 .dac_nids = alc880_asus_dac_nids,
2789                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
2790                 .channel_mode = alc880_asus_modes,
2791                 .need_dac_fix = 1,
2792                 .input_mux = &alc880_capture_source,
2793         },
2794         [ALC880_ASUS_DIG] = {
2795                 .mixers = { alc880_asus_mixer },
2796                 .init_verbs = { alc880_volume_init_verbs,
2797                                 alc880_pin_asus_init_verbs,
2798                                 alc880_gpio1_init_verbs },
2799                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2800                 .dac_nids = alc880_asus_dac_nids,
2801                 .dig_out_nid = ALC880_DIGOUT_NID,
2802                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
2803                 .channel_mode = alc880_asus_modes,
2804                 .need_dac_fix = 1,
2805                 .input_mux = &alc880_capture_source,
2806         },
2807         [ALC880_ASUS_DIG2] = {
2808                 .mixers = { alc880_asus_mixer },
2809                 .init_verbs = { alc880_volume_init_verbs,
2810                                 alc880_pin_asus_init_verbs,
2811                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
2812                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2813                 .dac_nids = alc880_asus_dac_nids,
2814                 .dig_out_nid = ALC880_DIGOUT_NID,
2815                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
2816                 .channel_mode = alc880_asus_modes,
2817                 .need_dac_fix = 1,
2818                 .input_mux = &alc880_capture_source,
2819         },
2820         [ALC880_ASUS_W1V] = {
2821                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
2822                 .init_verbs = { alc880_volume_init_verbs,
2823                                 alc880_pin_asus_init_verbs,
2824                                 alc880_gpio1_init_verbs },
2825                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2826                 .dac_nids = alc880_asus_dac_nids,
2827                 .dig_out_nid = ALC880_DIGOUT_NID,
2828                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
2829                 .channel_mode = alc880_asus_modes,
2830                 .need_dac_fix = 1,
2831                 .input_mux = &alc880_capture_source,
2832         },
2833         [ALC880_UNIWILL_DIG] = {
2834                 .mixers = { alc880_asus_mixer, alc880_pcbeep_mixer },
2835                 .init_verbs = { alc880_volume_init_verbs,
2836                                 alc880_pin_asus_init_verbs },
2837                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2838                 .dac_nids = alc880_asus_dac_nids,
2839                 .dig_out_nid = ALC880_DIGOUT_NID,
2840                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
2841                 .channel_mode = alc880_asus_modes,
2842                 .need_dac_fix = 1,
2843                 .input_mux = &alc880_capture_source,
2844         },
2845         [ALC880_UNIWILL] = {
2846                 .mixers = { alc880_uniwill_mixer },
2847                 .init_verbs = { alc880_volume_init_verbs,
2848                                 alc880_uniwill_init_verbs },
2849                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2850                 .dac_nids = alc880_asus_dac_nids,
2851                 .dig_out_nid = ALC880_DIGOUT_NID,
2852                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
2853                 .channel_mode = alc880_threestack_modes,
2854                 .need_dac_fix = 1,
2855                 .input_mux = &alc880_capture_source,
2856                 .unsol_event = alc880_uniwill_unsol_event,
2857                 .init_hook = alc880_uniwill_automute,
2858         },
2859         [ALC880_UNIWILL_P53] = {
2860                 .mixers = { alc880_uniwill_p53_mixer },
2861                 .init_verbs = { alc880_volume_init_verbs,
2862                                 alc880_uniwill_p53_init_verbs },
2863                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2864                 .dac_nids = alc880_asus_dac_nids,
2865                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
2866                 .channel_mode = alc880_threestack_modes,
2867                 .input_mux = &alc880_capture_source,
2868                 .unsol_event = alc880_uniwill_p53_unsol_event,
2869                 .init_hook = alc880_uniwill_p53_hp_automute,
2870         },
2871         [ALC880_FUJITSU] = {
2872                 .mixers = { alc880_fujitsu_mixer,
2873                             alc880_pcbeep_mixer, },
2874                 .init_verbs = { alc880_volume_init_verbs,
2875                                 alc880_uniwill_p53_init_verbs,
2876                                 alc880_beep_init_verbs },
2877                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2878                 .dac_nids = alc880_dac_nids,
2879                 .dig_out_nid = ALC880_DIGOUT_NID,
2880                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
2881                 .channel_mode = alc880_2_jack_modes,
2882                 .input_mux = &alc880_capture_source,
2883                 .unsol_event = alc880_uniwill_p53_unsol_event,
2884                 .init_hook = alc880_uniwill_p53_hp_automute,
2885         },
2886         [ALC880_CLEVO] = {
2887                 .mixers = { alc880_three_stack_mixer },
2888                 .init_verbs = { alc880_volume_init_verbs,
2889                                 alc880_pin_clevo_init_verbs },
2890                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2891                 .dac_nids = alc880_dac_nids,
2892                 .hp_nid = 0x03,
2893                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
2894                 .channel_mode = alc880_threestack_modes,
2895                 .need_dac_fix = 1,
2896                 .input_mux = &alc880_capture_source,
2897         },
2898         [ALC880_LG] = {
2899                 .mixers = { alc880_lg_mixer },
2900                 .init_verbs = { alc880_volume_init_verbs,
2901                                 alc880_lg_init_verbs },
2902                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
2903                 .dac_nids = alc880_lg_dac_nids,
2904                 .dig_out_nid = ALC880_DIGOUT_NID,
2905                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
2906                 .channel_mode = alc880_lg_ch_modes,
2907                 .need_dac_fix = 1,
2908                 .input_mux = &alc880_lg_capture_source,
2909                 .unsol_event = alc880_lg_unsol_event,
2910                 .init_hook = alc880_lg_automute,
2911 #ifdef CONFIG_SND_HDA_POWER_SAVE
2912                 .loopbacks = alc880_lg_loopbacks,
2913 #endif
2914         },
2915         [ALC880_LG_LW] = {
2916                 .mixers = { alc880_lg_lw_mixer },
2917                 .init_verbs = { alc880_volume_init_verbs,
2918                                 alc880_lg_lw_init_verbs },
2919                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2920                 .dac_nids = alc880_dac_nids,
2921                 .dig_out_nid = ALC880_DIGOUT_NID,
2922                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
2923                 .channel_mode = alc880_lg_lw_modes,
2924                 .input_mux = &alc880_lg_lw_capture_source,
2925                 .unsol_event = alc880_lg_lw_unsol_event,
2926                 .init_hook = alc880_lg_lw_automute,
2927         },
2928 #ifdef CONFIG_SND_DEBUG
2929         [ALC880_TEST] = {
2930                 .mixers = { alc880_test_mixer },
2931                 .init_verbs = { alc880_test_init_verbs },
2932                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
2933                 .dac_nids = alc880_test_dac_nids,
2934                 .dig_out_nid = ALC880_DIGOUT_NID,
2935                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
2936                 .channel_mode = alc880_test_modes,
2937                 .input_mux = &alc880_test_capture_source,
2938         },
2939 #endif
2940 };
2941
2942 /*
2943  * Automatic parse of I/O pins from the BIOS configuration
2944  */
2945
2946 #define NUM_CONTROL_ALLOC       32
2947 #define NUM_VERB_ALLOC          32
2948
2949 enum {
2950         ALC_CTL_WIDGET_VOL,
2951         ALC_CTL_WIDGET_MUTE,
2952         ALC_CTL_BIND_MUTE,
2953 };
2954 static struct snd_kcontrol_new alc880_control_templates[] = {
2955         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2956         HDA_CODEC_MUTE(NULL, 0, 0, 0),
2957         HDA_BIND_MUTE(NULL, 0, 0, 0),
2958 };
2959
2960 /* add dynamic controls */
2961 static int add_control(struct alc_spec *spec, int type, const char *name,
2962                        unsigned long val)
2963 {
2964         struct snd_kcontrol_new *knew;
2965
2966         if (spec->num_kctl_used >= spec->num_kctl_alloc) {
2967                 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
2968
2969                 /* array + terminator */
2970                 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL);
2971                 if (!knew)
2972                         return -ENOMEM;
2973                 if (spec->kctl_alloc) {
2974                         memcpy(knew, spec->kctl_alloc,
2975                                sizeof(*knew) * spec->num_kctl_alloc);
2976                         kfree(spec->kctl_alloc);
2977                 }
2978                 spec->kctl_alloc = knew;
2979                 spec->num_kctl_alloc = num;
2980         }
2981
2982         knew = &spec->kctl_alloc[spec->num_kctl_used];
2983         *knew = alc880_control_templates[type];
2984         knew->name = kstrdup(name, GFP_KERNEL);
2985         if (!knew->name)
2986                 return -ENOMEM;
2987         knew->private_value = val;
2988         spec->num_kctl_used++;
2989         return 0;
2990 }
2991
2992 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
2993 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
2994 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
2995 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
2996 #define alc880_is_input_pin(nid)        ((nid) >= 0x18)
2997 #define alc880_input_pin_idx(nid)       ((nid) - 0x18)
2998 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
2999 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
3000 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
3001 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
3002 #define ALC880_PIN_CD_NID               0x1c
3003
3004 /* fill in the dac_nids table from the parsed pin configuration */
3005 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
3006                                      const struct auto_pin_cfg *cfg)
3007 {
3008         hda_nid_t nid;
3009         int assigned[4];
3010         int i, j;
3011
3012         memset(assigned, 0, sizeof(assigned));
3013         spec->multiout.dac_nids = spec->private_dac_nids;
3014
3015         /* check the pins hardwired to audio widget */
3016         for (i = 0; i < cfg->line_outs; i++) {
3017                 nid = cfg->line_out_pins[i];
3018                 if (alc880_is_fixed_pin(nid)) {
3019                         int idx = alc880_fixed_pin_idx(nid);
3020                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
3021                         assigned[idx] = 1;
3022                 }
3023         }
3024         /* left pins can be connect to any audio widget */
3025         for (i = 0; i < cfg->line_outs; i++) {
3026                 nid = cfg->line_out_pins[i];
3027                 if (alc880_is_fixed_pin(nid))
3028                         continue;
3029                 /* search for an empty channel */
3030                 for (j = 0; j < cfg->line_outs; j++) {
3031                         if (!assigned[j]) {
3032                                 spec->multiout.dac_nids[i] =
3033                                         alc880_idx_to_dac(j);
3034                                 assigned[j] = 1;
3035                                 break;
3036                         }
3037                 }
3038         }
3039         spec->multiout.num_dacs = cfg->line_outs;
3040         return 0;
3041 }
3042
3043 /* add playback controls from the parsed DAC table */
3044 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
3045                                              const struct auto_pin_cfg *cfg)
3046 {
3047         char name[32];
3048         static const char *chname[4] = {
3049                 "Front", "Surround", NULL /*CLFE*/, "Side"
3050         };
3051         hda_nid_t nid;
3052         int i, err;
3053
3054         for (i = 0; i < cfg->line_outs; i++) {
3055                 if (!spec->multiout.dac_nids[i])
3056                         continue;
3057                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
3058                 if (i == 2) {
3059                         /* Center/LFE */
3060                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3061                                           "Center Playback Volume",
3062                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
3063                                                               HDA_OUTPUT));
3064                         if (err < 0)
3065                                 return err;
3066                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3067                                           "LFE Playback Volume",
3068                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
3069                                                               HDA_OUTPUT));
3070                         if (err < 0)
3071                                 return err;
3072                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3073                                           "Center Playback Switch",
3074                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
3075                                                               HDA_INPUT));
3076                         if (err < 0)
3077                                 return err;
3078                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3079                                           "LFE Playback Switch",
3080                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
3081                                                               HDA_INPUT));
3082                         if (err < 0)
3083                                 return err;
3084                 } else {
3085                         sprintf(name, "%s Playback Volume", chname[i]);
3086                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3087                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3088                                                               HDA_OUTPUT));
3089                         if (err < 0)
3090                                 return err;
3091                         sprintf(name, "%s Playback Switch", chname[i]);
3092                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3093                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
3094                                                               HDA_INPUT));
3095                         if (err < 0)
3096                                 return err;
3097                 }
3098         }
3099         return 0;
3100 }
3101
3102 /* add playback controls for speaker and HP outputs */
3103 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
3104                                         const char *pfx)
3105 {
3106         hda_nid_t nid;
3107         int err;
3108         char name[32];
3109
3110         if (!pin)
3111                 return 0;
3112
3113         if (alc880_is_fixed_pin(pin)) {
3114                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
3115                 /* specify the DAC as the extra output */
3116                 if (!spec->multiout.hp_nid)
3117                         spec->multiout.hp_nid = nid;
3118                 else
3119                         spec->multiout.extra_out_nid[0] = nid;
3120                 /* control HP volume/switch on the output mixer amp */
3121                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
3122                 sprintf(name, "%s Playback Volume", pfx);
3123                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3124                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3125                 if (err < 0)
3126                         return err;
3127                 sprintf(name, "%s Playback Switch", pfx);
3128                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3129                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
3130                 if (err < 0)
3131                         return err;
3132         } else if (alc880_is_multi_pin(pin)) {
3133                 /* set manual connection */
3134                 /* we have only a switch on HP-out PIN */
3135                 sprintf(name, "%s Playback Switch", pfx);
3136                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3137                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3138                 if (err < 0)
3139                         return err;
3140         }
3141         return 0;
3142 }
3143
3144 /* create input playback/capture controls for the given pin */
3145 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
3146                             const char *ctlname,
3147                             int idx, hda_nid_t mix_nid)
3148 {
3149         char name[32];
3150         int err;
3151
3152         sprintf(name, "%s Playback Volume", ctlname);
3153         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3154                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3155         if (err < 0)
3156                 return err;
3157         sprintf(name, "%s Playback Switch", ctlname);
3158         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3159                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3160         if (err < 0)
3161                 return err;
3162         return 0;
3163 }
3164
3165 /* create playback/capture controls for input pins */
3166 static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
3167                                                 const struct auto_pin_cfg *cfg)
3168 {
3169         struct hda_input_mux *imux = &spec->private_imux;
3170         int i, err, idx;
3171
3172         for (i = 0; i < AUTO_PIN_LAST; i++) {
3173                 if (alc880_is_input_pin(cfg->input_pins[i])) {
3174                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
3175                         err = new_analog_input(spec, cfg->input_pins[i],
3176                                                auto_pin_cfg_labels[i],
3177                                                idx, 0x0b);
3178                         if (err < 0)
3179                                 return err;
3180                         imux->items[imux->num_items].label =
3181                                 auto_pin_cfg_labels[i];
3182                         imux->items[imux->num_items].index =
3183                                 alc880_input_pin_idx(cfg->input_pins[i]);
3184                         imux->num_items++;
3185                 }
3186         }
3187         return 0;
3188 }
3189
3190 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
3191                                               hda_nid_t nid, int pin_type,
3192                                               int dac_idx)
3193 {
3194         /* set as output */
3195         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3196                             pin_type);
3197         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3198                             AMP_OUT_UNMUTE);
3199         /* need the manual connection? */
3200         if (alc880_is_multi_pin(nid)) {
3201                 struct alc_spec *spec = codec->spec;
3202                 int idx = alc880_multi_pin_idx(nid);
3203                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
3204                                     AC_VERB_SET_CONNECT_SEL,
3205                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
3206         }
3207 }
3208
3209 static int get_pin_type(int line_out_type)
3210 {
3211         if (line_out_type == AUTO_PIN_HP_OUT)
3212                 return PIN_HP;
3213         else
3214                 return PIN_OUT;
3215 }
3216
3217 static void alc880_auto_init_multi_out(struct hda_codec *codec)
3218 {
3219         struct alc_spec *spec = codec->spec;
3220         int i;
3221         
3222         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
3223         for (i = 0; i < spec->autocfg.line_outs; i++) {
3224                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3225                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3226                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
3227         }
3228 }
3229
3230 static void alc880_auto_init_extra_out(struct hda_codec *codec)
3231 {
3232         struct alc_spec *spec = codec->spec;
3233         hda_nid_t pin;
3234
3235         pin = spec->autocfg.speaker_pins[0];
3236         if (pin) /* connect to front */
3237                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
3238         pin = spec->autocfg.hp_pins[0];
3239         if (pin) /* connect to front */
3240                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
3241 }
3242
3243 static void alc880_auto_init_analog_input(struct hda_codec *codec)
3244 {
3245         struct alc_spec *spec = codec->spec;
3246         int i;
3247
3248         for (i = 0; i < AUTO_PIN_LAST; i++) {
3249                 hda_nid_t nid = spec->autocfg.input_pins[i];
3250                 if (alc880_is_input_pin(nid)) {
3251                         snd_hda_codec_write(codec, nid, 0,
3252                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
3253                                             i <= AUTO_PIN_FRONT_MIC ?
3254                                             PIN_VREF80 : PIN_IN);
3255                         if (nid != ALC880_PIN_CD_NID)
3256                                 snd_hda_codec_write(codec, nid, 0,
3257                                                     AC_VERB_SET_AMP_GAIN_MUTE,
3258                                                     AMP_OUT_MUTE);
3259                 }
3260         }
3261 }
3262
3263 /* parse the BIOS configuration and set up the alc_spec */
3264 /* return 1 if successful, 0 if the proper config is not found,
3265  * or a negative error code
3266  */
3267 static int alc880_parse_auto_config(struct hda_codec *codec)
3268 {
3269         struct alc_spec *spec = codec->spec;
3270         int err;
3271         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
3272
3273         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
3274                                            alc880_ignore);
3275         if (err < 0)
3276                 return err;
3277         if (!spec->autocfg.line_outs)
3278                 return 0; /* can't find valid BIOS pin config */
3279
3280         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
3281         if (err < 0)
3282                 return err;
3283         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
3284         if (err < 0)
3285                 return err;
3286         err = alc880_auto_create_extra_out(spec,
3287                                            spec->autocfg.speaker_pins[0],
3288                                            "Speaker");
3289         if (err < 0)
3290                 return err;
3291         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
3292                                            "Headphone");
3293         if (err < 0)
3294                 return err;
3295         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
3296         if (err < 0)
3297                 return err;
3298
3299         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3300
3301         if (spec->autocfg.dig_out_pin)
3302                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
3303         if (spec->autocfg.dig_in_pin)
3304                 spec->dig_in_nid = ALC880_DIGIN_NID;
3305
3306         if (spec->kctl_alloc)
3307                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
3308
3309         spec->init_verbs[spec->num_init_verbs++] = alc880_volume_init_verbs;
3310
3311         spec->num_mux_defs = 1;
3312         spec->input_mux = &spec->private_imux;
3313
3314         return 1;
3315 }
3316
3317 /* additional initialization for auto-configuration model */
3318 static void alc880_auto_init(struct hda_codec *codec)
3319 {
3320         alc880_auto_init_multi_out(codec);
3321         alc880_auto_init_extra_out(codec);
3322         alc880_auto_init_analog_input(codec);
3323 }
3324
3325 /*
3326  * OK, here we have finally the patch for ALC880
3327  */
3328
3329 static int patch_alc880(struct hda_codec *codec)
3330 {
3331         struct alc_spec *spec;
3332         int board_config;
3333         int err;
3334
3335         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3336         if (spec == NULL)
3337                 return -ENOMEM;
3338
3339         codec->spec = spec;
3340
3341         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
3342                                                   alc880_models,
3343                                                   alc880_cfg_tbl);
3344         if (board_config < 0) {
3345                 printk(KERN_INFO "hda_codec: Unknown model for ALC880, "
3346                        "trying auto-probe from BIOS...\n");
3347                 board_config = ALC880_AUTO;
3348         }
3349
3350         if (board_config == ALC880_AUTO) {
3351                 /* automatic parse from the BIOS config */
3352                 err = alc880_parse_auto_config(codec);
3353                 if (err < 0) {
3354                         alc_free(codec);
3355                         return err;
3356                 } else if (!err) {
3357                         printk(KERN_INFO
3358                                "hda_codec: Cannot set up configuration "
3359                                "from BIOS.  Using 3-stack mode...\n");
3360                         board_config = ALC880_3ST;
3361                 }
3362         }
3363
3364         if (board_config != ALC880_AUTO)
3365                 setup_preset(spec, &alc880_presets[board_config]);
3366
3367         spec->stream_name_analog = "ALC880 Analog";
3368         spec->stream_analog_playback = &alc880_pcm_analog_playback;
3369         spec->stream_analog_capture = &alc880_pcm_analog_capture;
3370
3371         spec->stream_name_digital = "ALC880 Digital";
3372         spec->stream_digital_playback = &alc880_pcm_digital_playback;
3373         spec->stream_digital_capture = &alc880_pcm_digital_capture;
3374
3375         if (!spec->adc_nids && spec->input_mux) {
3376                 /* check whether NID 0x07 is valid */
3377                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
3378                 /* get type */
3379                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
3380                 if (wcap != AC_WID_AUD_IN) {
3381                         spec->adc_nids = alc880_adc_nids_alt;
3382                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
3383                         spec->mixers[spec->num_mixers] =
3384                                 alc880_capture_alt_mixer;
3385                         spec->num_mixers++;
3386                 } else {
3387                         spec->adc_nids = alc880_adc_nids;
3388                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
3389                         spec->mixers[spec->num_mixers] = alc880_capture_mixer;
3390                         spec->num_mixers++;
3391                 }
3392         }
3393
3394         codec->patch_ops = alc_patch_ops;
3395         if (board_config == ALC880_AUTO)
3396                 spec->init_hook = alc880_auto_init;
3397 #ifdef CONFIG_SND_HDA_POWER_SAVE
3398         if (!spec->loopback.amplist)
3399                 spec->loopback.amplist = alc880_loopbacks;
3400 #endif
3401
3402         return 0;
3403 }
3404
3405
3406 /*
3407  * ALC260 support
3408  */
3409
3410 static hda_nid_t alc260_dac_nids[1] = {
3411         /* front */
3412         0x02,
3413 };
3414
3415 static hda_nid_t alc260_adc_nids[1] = {
3416         /* ADC0 */
3417         0x04,
3418 };
3419
3420 static hda_nid_t alc260_adc_nids_alt[1] = {
3421         /* ADC1 */
3422         0x05,
3423 };
3424
3425 static hda_nid_t alc260_hp_adc_nids[2] = {
3426         /* ADC1, 0 */
3427         0x05, 0x04
3428 };
3429
3430 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
3431  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
3432  */
3433 static hda_nid_t alc260_dual_adc_nids[2] = {
3434         /* ADC0, ADC1 */
3435         0x04, 0x05
3436 };
3437
3438 #define ALC260_DIGOUT_NID       0x03
3439 #define ALC260_DIGIN_NID        0x06
3440
3441 static struct hda_input_mux alc260_capture_source = {
3442         .num_items = 4,
3443         .items = {
3444                 { "Mic", 0x0 },
3445                 { "Front Mic", 0x1 },
3446                 { "Line", 0x2 },
3447                 { "CD", 0x4 },
3448         },
3449 };
3450
3451 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
3452  * headphone jack and the internal CD lines since these are the only pins at
3453  * which audio can appear.  For flexibility, also allow the option of
3454  * recording the mixer output on the second ADC (ADC0 doesn't have a
3455  * connection to the mixer output).
3456  */
3457 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
3458         {
3459                 .num_items = 3,
3460                 .items = {
3461                         { "Mic/Line", 0x0 },
3462                         { "CD", 0x4 },
3463                         { "Headphone", 0x2 },
3464                 },
3465         },
3466         {
3467                 .num_items = 4,
3468                 .items = {
3469                         { "Mic/Line", 0x0 },
3470                         { "CD", 0x4 },
3471                         { "Headphone", 0x2 },
3472                         { "Mixer", 0x5 },
3473                 },
3474         },
3475
3476 };
3477
3478 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
3479  * the Fujitsu S702x, but jacks are marked differently.
3480  */
3481 static struct hda_input_mux alc260_acer_capture_sources[2] = {
3482         {
3483                 .num_items = 4,
3484                 .items = {
3485                         { "Mic", 0x0 },
3486                         { "Line", 0x2 },
3487                         { "CD", 0x4 },
3488                         { "Headphone", 0x5 },
3489                 },
3490         },
3491         {
3492                 .num_items = 5,
3493                 .items = {
3494                         { "Mic", 0x0 },
3495                         { "Line", 0x2 },
3496                         { "CD", 0x4 },
3497                         { "Headphone", 0x6 },
3498                         { "Mixer", 0x5 },
3499                 },
3500         },
3501 };
3502 /*
3503  * This is just place-holder, so there's something for alc_build_pcms to look
3504  * at when it calculates the maximum number of channels. ALC260 has no mixer
3505  * element which allows changing the channel mode, so the verb list is
3506  * never used.
3507  */
3508 static struct hda_channel_mode alc260_modes[1] = {
3509         { 2, NULL },
3510 };
3511
3512
3513 /* Mixer combinations
3514  *
3515  * basic: base_output + input + pc_beep + capture
3516  * HP: base_output + input + capture_alt
3517  * HP_3013: hp_3013 + input + capture
3518  * fujitsu: fujitsu + capture
3519  * acer: acer + capture
3520  */
3521
3522 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
3523         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3524         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
3525         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
3526         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
3527         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
3528         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
3529         { } /* end */
3530 };
3531
3532 static struct snd_kcontrol_new alc260_input_mixer[] = {
3533         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3534         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3535         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
3536         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
3537         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
3538         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
3539         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
3540         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
3541         { } /* end */
3542 };
3543
3544 static struct snd_kcontrol_new alc260_pc_beep_mixer[] = {
3545         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT),
3546         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT),
3547         { } /* end */
3548 };
3549
3550 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
3551         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
3552         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
3553         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
3554         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
3555         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3556         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
3557         HDA_CODEC_VOLUME_MONO("iSpeaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
3558         HDA_CODEC_MUTE_MONO("iSpeaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
3559         { } /* end */
3560 };
3561
3562 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12, 
3563  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
3564  */
3565 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
3566         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3567         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
3568         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
3569         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3570         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3571         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
3572         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
3573         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
3574         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
3575         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
3576         HDA_CODEC_VOLUME("Internal Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
3577         HDA_BIND_MUTE("Internal Speaker Playback Switch", 0x09, 2, HDA_INPUT),
3578         { } /* end */
3579 };
3580
3581 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
3582  * versions of the ALC260 don't act on requests to enable mic bias from NID
3583  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
3584  * datasheet doesn't mention this restriction.  At this stage it's not clear
3585  * whether this behaviour is intentional or is a hardware bug in chip
3586  * revisions available in early 2006.  Therefore for now allow the
3587  * "Headphone Jack Mode" control to span all choices, but if it turns out
3588  * that the lack of mic bias for this NID is intentional we could change the
3589  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
3590  *
3591  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
3592  * don't appear to make the mic bias available from the "line" jack, even
3593  * though the NID used for this jack (0x14) can supply it.  The theory is
3594  * that perhaps Acer have included blocking capacitors between the ALC260
3595  * and the output jack.  If this turns out to be the case for all such
3596  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
3597  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
3598  *
3599  * The C20x Tablet series have a mono internal speaker which is controlled
3600  * via the chip's Mono sum widget and pin complex, so include the necessary
3601  * controls for such models.  On models without a "mono speaker" the control
3602  * won't do anything.
3603  */
3604 static struct snd_kcontrol_new alc260_acer_mixer[] = {
3605         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3606         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
3607         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
3608         HDA_CODEC_VOLUME_MONO("Mono Speaker Playback Volume", 0x0a, 1, 0x0,
3609                               HDA_OUTPUT),
3610         HDA_BIND_MUTE_MONO("Mono Speaker Playback Switch", 0x0a, 1, 2,
3611                            HDA_INPUT),
3612         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3613         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3614         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
3615         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
3616         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
3617         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
3618         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
3619         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
3620         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
3621         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
3622         { } /* end */
3623 };
3624
3625 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
3626  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
3627  */
3628 static struct snd_kcontrol_new alc260_will_mixer[] = {
3629         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3630         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
3631         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
3632         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
3633         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
3634         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
3635         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
3636         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
3637         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3638         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3639         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
3640         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
3641         { } /* end */
3642 };
3643
3644 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
3645  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
3646  */
3647 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
3648         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3649         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
3650         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
3651         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
3652         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
3653         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
3654         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
3655         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
3656         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
3657         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
3658         { } /* end */
3659 };
3660
3661 /* capture mixer elements */
3662 static struct snd_kcontrol_new alc260_capture_mixer[] = {
3663         HDA_CODEC_VOLUME("Capture Volume", 0x04, 0x0, HDA_INPUT),
3664         HDA_CODEC_MUTE("Capture Switch", 0x04, 0x0, HDA_INPUT),
3665         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x05, 0x0, HDA_INPUT),
3666         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x05, 0x0, HDA_INPUT),
3667         {
3668                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3669                 /* The multiple "Capture Source" controls confuse alsamixer
3670                  * So call somewhat different..
3671                  * FIXME: the controls appear in the "playback" view!
3672                  */
3673                 /* .name = "Capture Source", */
3674                 .name = "Input Source",
3675                 .count = 2,
3676                 .info = alc_mux_enum_info,
3677                 .get = alc_mux_enum_get,
3678                 .put = alc_mux_enum_put,
3679         },
3680         { } /* end */
3681 };
3682
3683 static struct snd_kcontrol_new alc260_capture_alt_mixer[] = {
3684         HDA_CODEC_VOLUME("Capture Volume", 0x05, 0x0, HDA_INPUT),
3685         HDA_CODEC_MUTE("Capture Switch", 0x05, 0x0, HDA_INPUT),
3686         {
3687                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3688                 /* The multiple "Capture Source" controls confuse alsamixer
3689                  * So call somewhat different..
3690                  * FIXME: the controls appear in the "playback" view!
3691                  */
3692                 /* .name = "Capture Source", */
3693                 .name = "Input Source",
3694                 .count = 1,
3695                 .info = alc_mux_enum_info,
3696                 .get = alc_mux_enum_get,
3697                 .put = alc_mux_enum_put,
3698         },
3699         { } /* end */
3700 };
3701
3702 /*
3703  * initialization verbs
3704  */
3705 static struct hda_verb alc260_init_verbs[] = {
3706         /* Line In pin widget for input */
3707         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3708         /* CD pin widget for input */
3709         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3710         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3711         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3712         /* Mic2 (front panel) pin widget for input and vref at 80% */
3713         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3714         /* LINE-2 is used for line-out in rear */
3715         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3716         /* select line-out */
3717         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
3718         /* LINE-OUT pin */
3719         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3720         /* enable HP */
3721         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3722         /* enable Mono */
3723         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3724         /* mute capture amp left and right */
3725         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3726         /* set connection select to line in (default select for this ADC) */
3727         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
3728         /* mute capture amp left and right */
3729         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3730         /* set connection select to line in (default select for this ADC) */
3731         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
3732         /* set vol=0 Line-Out mixer amp left and right */
3733         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3734         /* unmute pin widget amp left and right (no gain on this amp) */
3735         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3736         /* set vol=0 HP mixer amp left and right */
3737         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3738         /* unmute pin widget amp left and right (no gain on this amp) */
3739         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3740         /* set vol=0 Mono mixer amp left and right */
3741         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3742         /* unmute pin widget amp left and right (no gain on this amp) */
3743         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3744         /* unmute LINE-2 out pin */
3745         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3746         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
3747          * Line In 2 = 0x03
3748          */
3749         /* mute analog inputs */
3750         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3751         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3752         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3753         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3754         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3755         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
3756         /* mute Front out path */
3757         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3758         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3759         /* mute Headphone out path */
3760         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3761         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3762         /* mute Mono out path */
3763         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3764         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3765         { }
3766 };
3767
3768 #if 0 /* should be identical with alc260_init_verbs? */
3769 static struct hda_verb alc260_hp_init_verbs[] = {
3770         /* Headphone and output */
3771         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
3772         /* mono output */
3773         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3774         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3775         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
3776         /* Mic2 (front panel) pin widget for input and vref at 80% */
3777         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
3778         /* Line In pin widget for input */
3779         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3780         /* Line-2 pin widget for output */
3781         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3782         /* CD pin widget for input */
3783         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3784         /* unmute amp left and right */
3785         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
3786         /* set connection select to line in (default select for this ADC) */
3787         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
3788         /* unmute Line-Out mixer amp left and right (volume = 0) */
3789         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
3790         /* mute pin widget amp left and right (no gain on this amp) */
3791         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
3792         /* unmute HP mixer amp left and right (volume = 0) */
3793         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
3794         /* mute pin widget amp left and right (no gain on this amp) */
3795         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
3796         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
3797          * Line In 2 = 0x03
3798          */
3799         /* mute analog inputs */
3800         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3801         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3802         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3803         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3804         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3805         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
3806         /* Unmute Front out path */
3807         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3808         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3809         /* Unmute Headphone out path */
3810         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3811         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3812         /* Unmute Mono out path */
3813         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3814         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3815         { }
3816 };
3817 #endif
3818
3819 static struct hda_verb alc260_hp_3013_init_verbs[] = {
3820         /* Line out and output */
3821         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3822         /* mono output */
3823         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3824         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3825         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
3826         /* Mic2 (front panel) pin widget for input and vref at 80% */
3827         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
3828         /* Line In pin widget for input */
3829         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3830         /* Headphone pin widget for output */
3831         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
3832         /* CD pin widget for input */
3833         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3834         /* unmute amp left and right */
3835         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
3836         /* set connection select to line in (default select for this ADC) */
3837         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
3838         /* unmute Line-Out mixer amp left and right (volume = 0) */
3839         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
3840         /* mute pin widget amp left and right (no gain on this amp) */
3841         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
3842         /* unmute HP mixer amp left and right (volume = 0) */
3843         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
3844         /* mute pin widget amp left and right (no gain on this amp) */
3845         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
3846         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
3847          * Line In 2 = 0x03
3848          */
3849         /* mute analog inputs */
3850         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3851         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3852         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3853         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3854         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3855         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
3856         /* Unmute Front out path */
3857         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3858         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3859         /* Unmute Headphone out path */
3860         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3861         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3862         /* Unmute Mono out path */
3863         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3864         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3865         { }
3866 };
3867
3868 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
3869  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
3870  * audio = 0x16, internal speaker = 0x10.
3871  */
3872 static struct hda_verb alc260_fujitsu_init_verbs[] = {
3873         /* Disable all GPIOs */
3874         {0x01, AC_VERB_SET_GPIO_MASK, 0},
3875         /* Internal speaker is connected to headphone pin */
3876         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3877         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
3878         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3879         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
3880         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3881         /* Ensure all other unused pins are disabled and muted. */
3882         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3883         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3884         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3885         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3886         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3887         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3888         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3889         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3890
3891         /* Disable digital (SPDIF) pins */
3892         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
3893         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
3894
3895         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus 
3896          * when acting as an output.
3897          */
3898         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
3899
3900         /* Start with output sum widgets muted and their output gains at min */
3901         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3902         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3903         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3904         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3905         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3906         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3907         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3908         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3909         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3910
3911         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
3912         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3913         /* Unmute Line1 pin widget output buffer since it starts as an output.
3914          * If the pin mode is changed by the user the pin mode control will
3915          * take care of enabling the pin's input/output buffers as needed.
3916          * Therefore there's no need to enable the input buffer at this
3917          * stage.
3918          */
3919         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3920         /* Unmute input buffer of pin widget used for Line-in (no equiv 
3921          * mixer ctrl)
3922          */
3923         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3924
3925         /* Mute capture amp left and right */
3926         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3927         /* Set ADC connection select to match default mixer setting - line 
3928          * in (on mic1 pin)
3929          */
3930         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
3931
3932         /* Do the same for the second ADC: mute capture input amp and
3933          * set ADC connection to line in (on mic1 pin)
3934          */
3935         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3936         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
3937
3938         /* Mute all inputs to mixer widget (even unconnected ones) */
3939         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
3940         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
3941         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
3942         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
3943         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
3944         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
3945         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
3946         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
3947
3948         { }
3949 };
3950
3951 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
3952  * similar laptops (adapted from Fujitsu init verbs).
3953  */
3954 static struct hda_verb alc260_acer_init_verbs[] = {
3955         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
3956          * the headphone jack.  Turn this on and rely on the standard mute
3957          * methods whenever the user wants to turn these outputs off.
3958          */
3959         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
3960         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
3961         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
3962         /* Internal speaker/Headphone jack is connected to Line-out pin */
3963         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3964         /* Internal microphone/Mic jack is connected to Mic1 pin */
3965         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
3966         /* Line In jack is connected to Line1 pin */
3967         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3968         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
3969         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3970         /* Ensure all other unused pins are disabled and muted. */
3971         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3972         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3973         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3974         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3975         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3976         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3977         /* Disable digital (SPDIF) pins */
3978         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
3979         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
3980
3981         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum 
3982          * bus when acting as outputs.
3983          */
3984         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
3985         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
3986
3987         /* Start with output sum widgets muted and their output gains at min */
3988         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3989         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3990         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3991         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3992         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3993         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3994         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3995         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3996         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3997
3998         /* Unmute Line-out pin widget amp left and right
3999          * (no equiv mixer ctrl)
4000          */
4001         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4002         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
4003         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4004         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
4005          * inputs. If the pin mode is changed by the user the pin mode control
4006          * will take care of enabling the pin's input/output buffers as needed.
4007          * Therefore there's no need to enable the input buffer at this
4008          * stage.
4009          */
4010         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4011         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4012
4013         /* Mute capture amp left and right */
4014         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4015         /* Set ADC connection select to match default mixer setting - mic
4016          * (on mic1 pin)
4017          */
4018         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4019
4020         /* Do similar with the second ADC: mute capture input amp and
4021          * set ADC connection to mic to match ALSA's default state.
4022          */
4023         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4024         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4025
4026         /* Mute all inputs to mixer widget (even unconnected ones) */
4027         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4028         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4029         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4030         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4031         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4032         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4033         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4034         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4035
4036         { }
4037 };
4038
4039 static struct hda_verb alc260_will_verbs[] = {
4040         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4041         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
4042         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
4043         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4044         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
4045         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
4046         {}
4047 };
4048
4049 static struct hda_verb alc260_replacer_672v_verbs[] = {
4050         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4051         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
4052         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
4053
4054         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
4055         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4056         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4057
4058         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4059         {}
4060 };
4061
4062 /* toggle speaker-output according to the hp-jack state */
4063 static void alc260_replacer_672v_automute(struct hda_codec *codec)
4064 {
4065         unsigned int present;
4066
4067         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
4068         present = snd_hda_codec_read(codec, 0x0f, 0,
4069                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
4070         if (present) {
4071                 snd_hda_codec_write_cache(codec, 0x01, 0,
4072                                           AC_VERB_SET_GPIO_DATA, 1);
4073                 snd_hda_codec_write_cache(codec, 0x0f, 0,
4074                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4075                                           PIN_HP);
4076         } else {
4077                 snd_hda_codec_write_cache(codec, 0x01, 0,
4078                                           AC_VERB_SET_GPIO_DATA, 0);
4079                 snd_hda_codec_write_cache(codec, 0x0f, 0,
4080                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4081                                           PIN_OUT);
4082         }
4083 }
4084
4085 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
4086                                        unsigned int res)
4087 {
4088         if ((res >> 26) == ALC880_HP_EVENT)
4089                 alc260_replacer_672v_automute(codec);
4090 }
4091
4092 /* Test configuration for debugging, modelled after the ALC880 test
4093  * configuration.
4094  */
4095 #ifdef CONFIG_SND_DEBUG
4096 static hda_nid_t alc260_test_dac_nids[1] = {
4097         0x02,
4098 };
4099 static hda_nid_t alc260_test_adc_nids[2] = {
4100         0x04, 0x05,
4101 };
4102 /* For testing the ALC260, each input MUX needs its own definition since
4103  * the signal assignments are different.  This assumes that the first ADC 
4104  * is NID 0x04.
4105  */
4106 static struct hda_input_mux alc260_test_capture_sources[2] = {
4107         {
4108                 .num_items = 7,
4109                 .items = {
4110                         { "MIC1 pin", 0x0 },
4111                         { "MIC2 pin", 0x1 },
4112                         { "LINE1 pin", 0x2 },
4113                         { "LINE2 pin", 0x3 },
4114                         { "CD pin", 0x4 },
4115                         { "LINE-OUT pin", 0x5 },
4116                         { "HP-OUT pin", 0x6 },
4117                 },
4118         },
4119         {
4120                 .num_items = 8,
4121                 .items = {
4122                         { "MIC1 pin", 0x0 },
4123                         { "MIC2 pin", 0x1 },
4124                         { "LINE1 pin", 0x2 },
4125                         { "LINE2 pin", 0x3 },
4126                         { "CD pin", 0x4 },
4127                         { "Mixer", 0x5 },
4128                         { "LINE-OUT pin", 0x6 },
4129                         { "HP-OUT pin", 0x7 },
4130                 },
4131         },
4132 };
4133 static struct snd_kcontrol_new alc260_test_mixer[] = {
4134         /* Output driver widgets */
4135         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4136         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4137         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4138         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
4139         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4140         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
4141
4142         /* Modes for retasking pin widgets
4143          * Note: the ALC260 doesn't seem to act on requests to enable mic
4144          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
4145          * mention this restriction.  At this stage it's not clear whether
4146          * this behaviour is intentional or is a hardware bug in chip
4147          * revisions available at least up until early 2006.  Therefore for
4148          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
4149          * choices, but if it turns out that the lack of mic bias for these
4150          * NIDs is intentional we could change their modes from
4151          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4152          */
4153         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
4154         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
4155         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
4156         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
4157         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
4158         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
4159
4160         /* Loopback mixer controls */
4161         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
4162         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
4163         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
4164         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
4165         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
4166         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
4167         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
4168         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
4169         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4170         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4171         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4172         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4173         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
4174         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
4175         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
4176         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
4177
4178         /* Controls for GPIO pins, assuming they are configured as outputs */
4179         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
4180         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
4181         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
4182         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
4183
4184         /* Switches to allow the digital IO pins to be enabled.  The datasheet
4185          * is ambigious as to which NID is which; testing on laptops which
4186          * make this output available should provide clarification. 
4187          */
4188         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
4189         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
4190
4191         { } /* end */
4192 };
4193 static struct hda_verb alc260_test_init_verbs[] = {
4194         /* Enable all GPIOs as outputs with an initial value of 0 */
4195         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
4196         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4197         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
4198
4199         /* Enable retasking pins as output, initially without power amp */
4200         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4201         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4202         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4203         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4204         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4205         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4206
4207         /* Disable digital (SPDIF) pins initially, but users can enable
4208          * them via a mixer switch.  In the case of SPDIF-out, this initverb
4209          * payload also sets the generation to 0, output to be in "consumer"
4210          * PCM format, copyright asserted, no pre-emphasis and no validity
4211          * control.
4212          */
4213         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4214         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4215
4216         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the 
4217          * OUT1 sum bus when acting as an output.
4218          */
4219         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
4220         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
4221         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4222         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
4223
4224         /* Start with output sum widgets muted and their output gains at min */
4225         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4226         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4227         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4228         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4229         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4230         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4231         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4232         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4233         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4234
4235         /* Unmute retasking pin widget output buffers since the default
4236          * state appears to be output.  As the pin mode is changed by the
4237          * user the pin mode control will take care of enabling the pin's
4238          * input/output buffers as needed.
4239          */
4240         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4241         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4242         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4243         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4244         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4245         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4246         /* Also unmute the mono-out pin widget */
4247         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4248
4249         /* Mute capture amp left and right */
4250         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4251         /* Set ADC connection select to match default mixer setting (mic1
4252          * pin)
4253          */
4254         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4255
4256         /* Do the same for the second ADC: mute capture input amp and
4257          * set ADC connection to mic1 pin
4258          */
4259         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4260         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4261
4262         /* Mute all inputs to mixer widget (even unconnected ones) */
4263         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4264         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4265         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4266         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4267         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4268         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4269         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4270         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4271
4272         { }
4273 };
4274 #endif
4275
4276 static struct hda_pcm_stream alc260_pcm_analog_playback = {
4277         .substreams = 1,
4278         .channels_min = 2,
4279         .channels_max = 2,
4280 };
4281
4282 static struct hda_pcm_stream alc260_pcm_analog_capture = {
4283         .substreams = 1,
4284         .channels_min = 2,
4285         .channels_max = 2,
4286 };
4287
4288 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
4289 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
4290
4291 /*
4292  * for BIOS auto-configuration
4293  */
4294
4295 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
4296                                         const char *pfx)
4297 {
4298         hda_nid_t nid_vol;
4299         unsigned long vol_val, sw_val;
4300         char name[32];
4301         int err;
4302
4303         if (nid >= 0x0f && nid < 0x11) {
4304                 nid_vol = nid - 0x7;
4305                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
4306                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
4307         } else if (nid == 0x11) {
4308                 nid_vol = nid - 0x7;
4309                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
4310                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
4311         } else if (nid >= 0x12 && nid <= 0x15) {
4312                 nid_vol = 0x08;
4313                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
4314                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
4315         } else
4316                 return 0; /* N/A */
4317         
4318         snprintf(name, sizeof(name), "%s Playback Volume", pfx);
4319         err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val);
4320         if (err < 0)
4321                 return err;
4322         snprintf(name, sizeof(name), "%s Playback Switch", pfx);
4323         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val);
4324         if (err < 0)
4325                 return err;
4326         return 1;
4327 }
4328
4329 /* add playback controls from the parsed DAC table */
4330 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
4331                                              const struct auto_pin_cfg *cfg)
4332 {
4333         hda_nid_t nid;
4334         int err;
4335
4336         spec->multiout.num_dacs = 1;
4337         spec->multiout.dac_nids = spec->private_dac_nids;
4338         spec->multiout.dac_nids[0] = 0x02;
4339
4340         nid = cfg->line_out_pins[0];
4341         if (nid) {
4342                 err = alc260_add_playback_controls(spec, nid, "Front");
4343                 if (err < 0)
4344                         return err;
4345         }
4346
4347         nid = cfg->speaker_pins[0];
4348         if (nid) {
4349                 err = alc260_add_playback_controls(spec, nid, "Speaker");
4350                 if (err < 0)
4351                         return err;
4352         }
4353
4354         nid = cfg->hp_pins[0];
4355         if (nid) {
4356                 err = alc260_add_playback_controls(spec, nid, "Headphone");
4357                 if (err < 0)
4358                         return err;
4359         }
4360         return 0;
4361 }
4362
4363 /* create playback/capture controls for input pins */
4364 static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec,
4365                                                 const struct auto_pin_cfg *cfg)
4366 {
4367         struct hda_input_mux *imux = &spec->private_imux;
4368         int i, err, idx;
4369
4370         for (i = 0; i < AUTO_PIN_LAST; i++) {
4371                 if (cfg->input_pins[i] >= 0x12) {
4372                         idx = cfg->input_pins[i] - 0x12;
4373                         err = new_analog_input(spec, cfg->input_pins[i],
4374                                                auto_pin_cfg_labels[i], idx,
4375                                                0x07);
4376                         if (err < 0)
4377                                 return err;
4378                         imux->items[imux->num_items].label =
4379                                 auto_pin_cfg_labels[i];
4380                         imux->items[imux->num_items].index = idx;
4381                         imux->num_items++;
4382                 }
4383                 if (cfg->input_pins[i] >= 0x0f && cfg->input_pins[i] <= 0x10){
4384                         idx = cfg->input_pins[i] - 0x09;
4385                         err = new_analog_input(spec, cfg->input_pins[i],
4386                                                auto_pin_cfg_labels[i], idx,
4387                                                0x07);
4388                         if (err < 0)
4389                                 return err;
4390                         imux->items[imux->num_items].label =
4391                                 auto_pin_cfg_labels[i];
4392                         imux->items[imux->num_items].index = idx;
4393                         imux->num_items++;
4394                 }
4395         }
4396         return 0;
4397 }
4398
4399 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
4400                                               hda_nid_t nid, int pin_type,
4401                                               int sel_idx)
4402 {
4403         /* set as output */
4404         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4405                             pin_type);
4406         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4407                             AMP_OUT_UNMUTE);
4408         /* need the manual connection? */
4409         if (nid >= 0x12) {
4410                 int idx = nid - 0x12;
4411                 snd_hda_codec_write(codec, idx + 0x0b, 0,
4412                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
4413         }
4414 }
4415
4416 static void alc260_auto_init_multi_out(struct hda_codec *codec)
4417 {
4418         struct alc_spec *spec = codec->spec;
4419         hda_nid_t nid;
4420
4421         alc_subsystem_id(codec, 0x10, 0x15, 0x0f);
4422         nid = spec->autocfg.line_out_pins[0];
4423         if (nid) {
4424                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
4425                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
4426         }
4427         
4428         nid = spec->autocfg.speaker_pins[0];
4429         if (nid)
4430                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
4431
4432         nid = spec->autocfg.hp_pins[0];
4433         if (nid)
4434                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
4435 }
4436
4437 #define ALC260_PIN_CD_NID               0x16
4438 static void alc260_auto_init_analog_input(struct hda_codec *codec)
4439 {
4440         struct alc_spec *spec = codec->spec;
4441         int i;
4442
4443         for (i = 0; i < AUTO_PIN_LAST; i++) {
4444                 hda_nid_t nid = spec->autocfg.input_pins[i];
4445                 if (nid >= 0x12) {
4446                         snd_hda_codec_write(codec, nid, 0,
4447                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
4448                                             i <= AUTO_PIN_FRONT_MIC ?
4449                                             PIN_VREF80 : PIN_IN);
4450                         if (nid != ALC260_PIN_CD_NID)
4451                                 snd_hda_codec_write(codec, nid, 0,
4452                                                     AC_VERB_SET_AMP_GAIN_MUTE,
4453                                                     AMP_OUT_MUTE);
4454                 }
4455         }
4456 }
4457
4458 /*
4459  * generic initialization of ADC, input mixers and output mixers
4460  */
4461 static struct hda_verb alc260_volume_init_verbs[] = {
4462         /*
4463          * Unmute ADC0-1 and set the default input to mic-in
4464          */
4465         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4466         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4467         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4468         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4469         
4470         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4471          * mixer widget
4472          * Note: PASD motherboards uses the Line In 2 as the input for
4473          * front panel mic (mic 2)
4474          */
4475         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
4476         /* mute analog inputs */
4477         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4478         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4479         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4480         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4481         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4482
4483         /*
4484          * Set up output mixers (0x08 - 0x0a)
4485          */
4486         /* set vol=0 to output mixers */
4487         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4488         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4489         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4490         /* set up input amps for analog loopback */
4491         /* Amp Indices: DAC = 0, mixer = 1 */
4492         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4493         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4494         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4495         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4496         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4497         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4498         
4499         { }
4500 };
4501
4502 static int alc260_parse_auto_config(struct hda_codec *codec)
4503 {
4504         struct alc_spec *spec = codec->spec;
4505         unsigned int wcap;
4506         int err;
4507         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
4508
4509         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
4510                                            alc260_ignore);
4511         if (err < 0)
4512                 return err;
4513         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
4514         if (err < 0)
4515                 return err;
4516         if (!spec->kctl_alloc)
4517                 return 0; /* can't find valid BIOS pin config */
4518         err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg);
4519         if (err < 0)
4520                 return err;
4521
4522         spec->multiout.max_channels = 2;
4523
4524         if (spec->autocfg.dig_out_pin)
4525                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
4526         if (spec->kctl_alloc)
4527                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
4528
4529         spec->init_verbs[spec->num_init_verbs++] = alc260_volume_init_verbs;
4530
4531         spec->num_mux_defs = 1;
4532         spec->input_mux = &spec->private_imux;
4533
4534         /* check whether NID 0x04 is valid */
4535         wcap = get_wcaps(codec, 0x04);
4536         wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */
4537         if (wcap != AC_WID_AUD_IN) {
4538                 spec->adc_nids = alc260_adc_nids_alt;
4539                 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
4540                 spec->mixers[spec->num_mixers] = alc260_capture_alt_mixer;
4541         } else {
4542                 spec->adc_nids = alc260_adc_nids;
4543                 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
4544                 spec->mixers[spec->num_mixers] = alc260_capture_mixer;
4545         }
4546         spec->num_mixers++;
4547
4548         return 1;
4549 }
4550
4551 /* additional initialization for auto-configuration model */
4552 static void alc260_auto_init(struct hda_codec *codec)
4553 {
4554         alc260_auto_init_multi_out(codec);
4555         alc260_auto_init_analog_input(codec);
4556 }
4557
4558 #ifdef CONFIG_SND_HDA_POWER_SAVE
4559 static struct hda_amp_list alc260_loopbacks[] = {
4560         { 0x07, HDA_INPUT, 0 },
4561         { 0x07, HDA_INPUT, 1 },
4562         { 0x07, HDA_INPUT, 2 },
4563         { 0x07, HDA_INPUT, 3 },
4564         { 0x07, HDA_INPUT, 4 },
4565         { } /* end */
4566 };
4567 #endif
4568
4569 /*
4570  * ALC260 configurations
4571  */
4572 static const char *alc260_models[ALC260_MODEL_LAST] = {
4573         [ALC260_BASIC]          = "basic",
4574         [ALC260_HP]             = "hp",
4575         [ALC260_HP_3013]        = "hp-3013",
4576         [ALC260_FUJITSU_S702X]  = "fujitsu",
4577         [ALC260_ACER]           = "acer",
4578         [ALC260_WILL]           = "will",
4579         [ALC260_REPLACER_672V]  = "replacer",
4580 #ifdef CONFIG_SND_DEBUG
4581         [ALC260_TEST]           = "test",
4582 #endif
4583         [ALC260_AUTO]           = "auto",
4584 };
4585
4586 static struct snd_pci_quirk alc260_cfg_tbl[] = {
4587         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
4588         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
4589         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
4590         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013),
4591         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
4592         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP),
4593         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_3013),
4594         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
4595         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
4596         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
4597         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
4598         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
4599         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
4600         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
4601         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
4602         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
4603         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
4604         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
4605         {}
4606 };
4607
4608 static struct alc_config_preset alc260_presets[] = {
4609         [ALC260_BASIC] = {
4610                 .mixers = { alc260_base_output_mixer,
4611                             alc260_input_mixer,
4612                             alc260_pc_beep_mixer,
4613                             alc260_capture_mixer },
4614                 .init_verbs = { alc260_init_verbs },
4615                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4616                 .dac_nids = alc260_dac_nids,
4617                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
4618                 .adc_nids = alc260_adc_nids,
4619                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4620                 .channel_mode = alc260_modes,
4621                 .input_mux = &alc260_capture_source,
4622         },
4623         [ALC260_HP] = {
4624                 .mixers = { alc260_base_output_mixer,
4625                             alc260_input_mixer,
4626                             alc260_capture_alt_mixer },
4627                 .init_verbs = { alc260_init_verbs },
4628                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4629                 .dac_nids = alc260_dac_nids,
4630                 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
4631                 .adc_nids = alc260_hp_adc_nids,
4632                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4633                 .channel_mode = alc260_modes,
4634                 .input_mux = &alc260_capture_source,
4635         },
4636         [ALC260_HP_3013] = {
4637                 .mixers = { alc260_hp_3013_mixer,
4638                             alc260_input_mixer,
4639                             alc260_capture_alt_mixer },
4640                 .init_verbs = { alc260_hp_3013_init_verbs },
4641                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4642                 .dac_nids = alc260_dac_nids,
4643                 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
4644                 .adc_nids = alc260_hp_adc_nids,
4645                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4646                 .channel_mode = alc260_modes,
4647                 .input_mux = &alc260_capture_source,
4648         },
4649         [ALC260_FUJITSU_S702X] = {
4650                 .mixers = { alc260_fujitsu_mixer,
4651                             alc260_capture_mixer },
4652                 .init_verbs = { alc260_fujitsu_init_verbs },
4653                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4654                 .dac_nids = alc260_dac_nids,
4655                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
4656                 .adc_nids = alc260_dual_adc_nids,
4657                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4658                 .channel_mode = alc260_modes,
4659                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
4660                 .input_mux = alc260_fujitsu_capture_sources,
4661         },
4662         [ALC260_ACER] = {
4663                 .mixers = { alc260_acer_mixer,
4664                             alc260_capture_mixer },
4665                 .init_verbs = { alc260_acer_init_verbs },
4666                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4667                 .dac_nids = alc260_dac_nids,
4668                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
4669                 .adc_nids = alc260_dual_adc_nids,
4670                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4671                 .channel_mode = alc260_modes,
4672                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
4673                 .input_mux = alc260_acer_capture_sources,
4674         },
4675         [ALC260_WILL] = {
4676                 .mixers = { alc260_will_mixer,
4677                             alc260_capture_mixer },
4678                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
4679                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4680                 .dac_nids = alc260_dac_nids,
4681                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
4682                 .adc_nids = alc260_adc_nids,
4683                 .dig_out_nid = ALC260_DIGOUT_NID,
4684                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4685                 .channel_mode = alc260_modes,
4686                 .input_mux = &alc260_capture_source,
4687         },
4688         [ALC260_REPLACER_672V] = {
4689                 .mixers = { alc260_replacer_672v_mixer,
4690                             alc260_capture_mixer },
4691                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
4692                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4693                 .dac_nids = alc260_dac_nids,
4694                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
4695                 .adc_nids = alc260_adc_nids,
4696                 .dig_out_nid = ALC260_DIGOUT_NID,
4697                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4698                 .channel_mode = alc260_modes,
4699                 .input_mux = &alc260_capture_source,
4700                 .unsol_event = alc260_replacer_672v_unsol_event,
4701                 .init_hook = alc260_replacer_672v_automute,
4702         },
4703 #ifdef CONFIG_SND_DEBUG
4704         [ALC260_TEST] = {
4705                 .mixers = { alc260_test_mixer,
4706                             alc260_capture_mixer },
4707                 .init_verbs = { alc260_test_init_verbs },
4708                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
4709                 .dac_nids = alc260_test_dac_nids,
4710                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
4711                 .adc_nids = alc260_test_adc_nids,
4712                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4713                 .channel_mode = alc260_modes,
4714                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
4715                 .input_mux = alc260_test_capture_sources,
4716         },
4717 #endif
4718 };
4719
4720 static int patch_alc260(struct hda_codec *codec)
4721 {
4722         struct alc_spec *spec;
4723         int err, board_config;
4724
4725         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4726         if (spec == NULL)
4727                 return -ENOMEM;
4728
4729         codec->spec = spec;
4730
4731         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
4732                                                   alc260_models,
4733                                                   alc260_cfg_tbl);
4734         if (board_config < 0) {
4735                 snd_printd(KERN_INFO "hda_codec: Unknown model for ALC260, "
4736                            "trying auto-probe from BIOS...\n");
4737                 board_config = ALC260_AUTO;
4738         }
4739
4740         if (board_config == ALC260_AUTO) {
4741                 /* automatic parse from the BIOS config */
4742                 err = alc260_parse_auto_config(codec);
4743                 if (err < 0) {
4744                         alc_free(codec);
4745                         return err;
4746                 } else if (!err) {
4747                         printk(KERN_INFO
4748                                "hda_codec: Cannot set up configuration "
4749                                "from BIOS.  Using base mode...\n");
4750                         board_config = ALC260_BASIC;
4751                 }
4752         }
4753
4754         if (board_config != ALC260_AUTO)
4755                 setup_preset(spec, &alc260_presets[board_config]);
4756
4757         spec->stream_name_analog = "ALC260 Analog";
4758         spec->stream_analog_playback = &alc260_pcm_analog_playback;
4759         spec->stream_analog_capture = &alc260_pcm_analog_capture;
4760
4761         spec->stream_name_digital = "ALC260 Digital";
4762         spec->stream_digital_playback = &alc260_pcm_digital_playback;
4763         spec->stream_digital_capture = &alc260_pcm_digital_capture;
4764
4765         codec->patch_ops = alc_patch_ops;
4766         if (board_config == ALC260_AUTO)
4767                 spec->init_hook = alc260_auto_init;
4768 #ifdef CONFIG_SND_HDA_POWER_SAVE
4769         if (!spec->loopback.amplist)
4770                 spec->loopback.amplist = alc260_loopbacks;
4771 #endif
4772
4773         return 0;
4774 }
4775
4776
4777 /*
4778  * ALC882 support
4779  *
4780  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4781  * configuration.  Each pin widget can choose any input DACs and a mixer.
4782  * Each ADC is connected from a mixer of all inputs.  This makes possible
4783  * 6-channel independent captures.
4784  *
4785  * In addition, an independent DAC for the multi-playback (not used in this
4786  * driver yet).
4787  */
4788 #define ALC882_DIGOUT_NID       0x06
4789 #define ALC882_DIGIN_NID        0x0a
4790
4791 static struct hda_channel_mode alc882_ch_modes[1] = {
4792         { 8, NULL }
4793 };
4794
4795 static hda_nid_t alc882_dac_nids[4] = {
4796         /* front, rear, clfe, rear_surr */
4797         0x02, 0x03, 0x04, 0x05
4798 };
4799
4800 /* identical with ALC880 */
4801 #define alc882_adc_nids         alc880_adc_nids
4802 #define alc882_adc_nids_alt     alc880_adc_nids_alt
4803
4804 /* input MUX */
4805 /* FIXME: should be a matrix-type input source selection */
4806
4807 static struct hda_input_mux alc882_capture_source = {
4808         .num_items = 4,
4809         .items = {
4810                 { "Mic", 0x0 },
4811                 { "Front Mic", 0x1 },
4812                 { "Line", 0x2 },
4813                 { "CD", 0x4 },
4814         },
4815 };
4816 #define alc882_mux_enum_info alc_mux_enum_info
4817 #define alc882_mux_enum_get alc_mux_enum_get
4818
4819 static int alc882_mux_enum_put(struct snd_kcontrol *kcontrol,
4820                                struct snd_ctl_elem_value *ucontrol)
4821 {
4822         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4823         struct alc_spec *spec = codec->spec;
4824         const struct hda_input_mux *imux = spec->input_mux;
4825         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
4826         static hda_nid_t capture_mixers[3] = { 0x24, 0x23, 0x22 };
4827         hda_nid_t nid = capture_mixers[adc_idx];
4828         unsigned int *cur_val = &spec->cur_mux[adc_idx];
4829         unsigned int i, idx;
4830
4831         idx = ucontrol->value.enumerated.item[0];
4832         if (idx >= imux->num_items)
4833                 idx = imux->num_items - 1;
4834         if (*cur_val == idx)
4835                 return 0;
4836         for (i = 0; i < imux->num_items; i++) {
4837                 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
4838                 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
4839                                          imux->items[i].index,
4840                                          HDA_AMP_MUTE, v);
4841         }
4842         *cur_val = idx;
4843         return 1;
4844 }
4845
4846 /*
4847  * 2ch mode
4848  */
4849 static struct hda_verb alc882_3ST_ch2_init[] = {
4850         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
4851         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
4852         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
4853         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
4854         { } /* end */
4855 };
4856
4857 /*
4858  * 6ch mode
4859  */
4860 static struct hda_verb alc882_3ST_ch6_init[] = {
4861         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4862         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
4863         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
4864         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4865         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
4866         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
4867         { } /* end */
4868 };
4869
4870 static struct hda_channel_mode alc882_3ST_6ch_modes[2] = {
4871         { 2, alc882_3ST_ch2_init },
4872         { 6, alc882_3ST_ch6_init },
4873 };
4874
4875 /*
4876  * 6ch mode
4877  */
4878 static struct hda_verb alc882_sixstack_ch6_init[] = {
4879         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
4880         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4881         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4882         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4883         { } /* end */
4884 };
4885
4886 /*
4887  * 8ch mode
4888  */
4889 static struct hda_verb alc882_sixstack_ch8_init[] = {
4890         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4891         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4892         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4893         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4894         { } /* end */
4895 };
4896
4897 static struct hda_channel_mode alc882_sixstack_modes[2] = {
4898         { 6, alc882_sixstack_ch6_init },
4899         { 8, alc882_sixstack_ch8_init },
4900 };
4901
4902 /*
4903  * macbook pro ALC885 can switch LineIn to LineOut without loosing Mic
4904  */
4905
4906 /*
4907  * 2ch mode
4908  */
4909 static struct hda_verb alc885_mbp_ch2_init[] = {
4910         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
4911         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4912         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4913         { } /* end */
4914 };
4915
4916 /*
4917  * 6ch mode
4918  */
4919 static struct hda_verb alc885_mbp_ch6_init[] = {
4920         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4921         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4922         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
4923         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4924         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4925         { } /* end */
4926 };
4927
4928 static struct hda_channel_mode alc885_mbp_6ch_modes[2] = {
4929         { 2, alc885_mbp_ch2_init },
4930         { 6, alc885_mbp_ch6_init },
4931 };
4932
4933
4934 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
4935  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
4936  */
4937 static struct snd_kcontrol_new alc882_base_mixer[] = {
4938         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
4939         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
4940         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
4941         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
4942         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
4943         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
4944         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
4945         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
4946         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
4947         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
4948         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
4949         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
4950         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
4951         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
4952         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
4953         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
4954         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
4955         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
4956         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
4957         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
4958         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
4959         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
4960         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
4961         { } /* end */
4962 };
4963
4964 static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
4965         HDA_CODEC_VOLUME("Master Volume", 0x0c, 0x00, HDA_OUTPUT),
4966         HDA_BIND_MUTE   ("Master Switch", 0x0c, 0x02, HDA_INPUT),
4967         HDA_CODEC_MUTE  ("Speaker Switch", 0x14, 0x00, HDA_OUTPUT),
4968         HDA_CODEC_VOLUME("Line Out Volume", 0x0d,0x00, HDA_OUTPUT),
4969         HDA_CODEC_VOLUME("Line In Playback Volume", 0x0b, 0x02, HDA_INPUT),
4970         HDA_CODEC_MUTE  ("Line In Playback Switch", 0x0b, 0x02, HDA_INPUT),
4971         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
4972         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
4973         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0x00, HDA_INPUT),
4974         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
4975         { } /* end */
4976 };
4977 static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
4978         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
4979         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
4980         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
4981         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
4982         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
4983         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
4984         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
4985         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
4986         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
4987         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
4988         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
4989         { } /* end */
4990 };
4991
4992 static struct snd_kcontrol_new alc882_targa_mixer[] = {
4993         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
4994         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
4995         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
4996         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
4997         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
4998         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
4999         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5000         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5001         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5002         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5003         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5004         { } /* end */
5005 };
5006
5007 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
5008  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
5009  */
5010 static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
5011         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5012         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
5013         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5014         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
5015         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5016         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5017         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5018         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5019         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
5020         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
5021         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5022         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5023         { } /* end */
5024 };
5025
5026 static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
5027         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5028         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5029         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5030         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5031         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5032         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5033         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5034         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5035         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5036         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5037         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5038         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5039         { } /* end */
5040 };
5041
5042 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
5043         {
5044                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5045                 .name = "Channel Mode",
5046                 .info = alc_ch_mode_info,
5047                 .get = alc_ch_mode_get,
5048                 .put = alc_ch_mode_put,
5049         },
5050         { } /* end */
5051 };
5052
5053 static struct hda_verb alc882_init_verbs[] = {
5054         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5055         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5056         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5057         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5058         /* Rear mixer */
5059         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5060         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5061         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5062         /* CLFE mixer */
5063         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5064         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5065         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5066         /* Side mixer */
5067         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5068         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5069         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5070
5071         /* Front Pin: output 0 (0x0c) */
5072         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5073         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5074         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5075         /* Rear Pin: output 1 (0x0d) */
5076         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5077         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5078         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5079         /* CLFE Pin: output 2 (0x0e) */
5080         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5081         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5082         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
5083         /* Side Pin: output 3 (0x0f) */
5084         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5085         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5086         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
5087         /* Mic (rear) pin: input vref at 80% */
5088         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5089         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5090         /* Front Mic pin: input vref at 80% */
5091         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5092         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5093         /* Line In pin: input */
5094         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5095         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5096         /* Line-2 In: Headphone output (output 0 - 0x0c) */
5097         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5098         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5099         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
5100         /* CD pin widget for input */
5101         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5102
5103         /* FIXME: use matrix-type input source selection */
5104         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5105         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5106         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5107         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5108         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5109         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5110         /* Input mixer2 */
5111         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5112         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5113         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5114         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5115         /* Input mixer3 */
5116         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5117         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5118         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5119         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5120         /* ADC1: mute amp left and right */
5121         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5122         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5123         /* ADC2: mute amp left and right */
5124         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5125         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5126         /* ADC3: mute amp left and right */
5127         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5128         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5129
5130         { }
5131 };
5132
5133 static struct hda_verb alc882_eapd_verbs[] = {
5134         /* change to EAPD mode */
5135         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
5136         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
5137         { }
5138 };
5139
5140 /* Mac Pro test */
5141 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
5142         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5143         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5144         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
5145         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
5146         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
5147         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT),
5148         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT),
5149         { } /* end */
5150 };
5151
5152 static struct hda_verb alc882_macpro_init_verbs[] = {
5153         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5154         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5155         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5156         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5157         /* Front Pin: output 0 (0x0c) */
5158         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5159         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5160         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
5161         /* Front Mic pin: input vref at 80% */
5162         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5163         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5164         /* Speaker:  output */
5165         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5166         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5167         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
5168         /* Headphone output (output 0 - 0x0c) */
5169         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5170         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5171         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
5172
5173         /* FIXME: use matrix-type input source selection */
5174         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5175         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5176         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5177         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5178         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5179         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5180         /* Input mixer2 */
5181         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5182         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5183         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5184         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5185         /* Input mixer3 */
5186         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5187         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5188         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5189         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5190         /* ADC1: mute amp left and right */
5191         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5192         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5193         /* ADC2: mute amp left and right */
5194         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5195         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5196         /* ADC3: mute amp left and right */
5197         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5198         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5199
5200         { }
5201 };
5202
5203 /* Macbook Pro rev3 */
5204 static struct hda_verb alc885_mbp3_init_verbs[] = {
5205         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5206         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5207         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5208         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5209         /* Rear mixer */
5210         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5211         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5212         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5213         /* Front Pin: output 0 (0x0c) */
5214         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5215         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5216         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5217         /* HP Pin: output 0 (0x0d) */
5218         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
5219         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5220         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
5221         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5222         /* Mic (rear) pin: input vref at 80% */
5223         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5224         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5225         /* Front Mic pin: input vref at 80% */
5226         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5227         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5228         /* Line In pin: use output 1 when in LineOut mode */
5229         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5230         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5231         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
5232
5233         /* FIXME: use matrix-type input source selection */
5234         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5235         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5236         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5237         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5238         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5239         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5240         /* Input mixer2 */
5241         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5242         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5243         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5244         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5245         /* Input mixer3 */
5246         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5247         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5248         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5249         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5250         /* ADC1: mute amp left and right */
5251         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5252         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5253         /* ADC2: mute amp left and right */
5254         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5255         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5256         /* ADC3: mute amp left and right */
5257         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5258         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5259
5260         { }
5261 };
5262
5263 /* iMac 24 mixer. */
5264 static struct snd_kcontrol_new alc885_imac24_mixer[] = {
5265         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
5266         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
5267         { } /* end */
5268 };
5269
5270 /* iMac 24 init verbs. */
5271 static struct hda_verb alc885_imac24_init_verbs[] = {
5272         /* Internal speakers: output 0 (0x0c) */
5273         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5274         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5275         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
5276         /* Internal speakers: output 0 (0x0c) */
5277         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5278         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5279         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
5280         /* Headphone: output 0 (0x0c) */
5281         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5282         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5283         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5284         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5285         /* Front Mic: input vref at 80% */
5286         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5287         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5288         { }
5289 };
5290
5291 /* Toggle speaker-output according to the hp-jack state */
5292 static void alc885_imac24_automute(struct hda_codec *codec)
5293 {
5294         unsigned int present;
5295
5296         present = snd_hda_codec_read(codec, 0x14, 0,
5297                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5298         snd_hda_codec_amp_stereo(codec, 0x18, HDA_OUTPUT, 0,
5299                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5300         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
5301                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5302 }
5303
5304 /* Processes unsolicited events. */
5305 static void alc885_imac24_unsol_event(struct hda_codec *codec,
5306                                       unsigned int res)
5307 {
5308         /* Headphone insertion or removal. */
5309         if ((res >> 26) == ALC880_HP_EVENT)
5310                 alc885_imac24_automute(codec);
5311 }
5312
5313 static void alc885_mbp3_automute(struct hda_codec *codec)
5314 {
5315         unsigned int present;
5316
5317         present = snd_hda_codec_read(codec, 0x15, 0,
5318                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5319         snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
5320                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5321         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
5322                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
5323
5324 }
5325 static void alc885_mbp3_unsol_event(struct hda_codec *codec,
5326                                     unsigned int res)
5327 {
5328         /* Headphone insertion or removal. */
5329         if ((res >> 26) == ALC880_HP_EVENT)
5330                 alc885_mbp3_automute(codec);
5331 }
5332
5333
5334 static struct hda_verb alc882_targa_verbs[] = {
5335         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5336         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5337
5338         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5339         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5340         
5341         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
5342         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
5343         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5344
5345         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5346         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5347         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
5348         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
5349         { } /* end */
5350 };
5351
5352 /* toggle speaker-output according to the hp-jack state */
5353 static void alc882_targa_automute(struct hda_codec *codec)
5354 {
5355         unsigned int present;
5356  
5357         present = snd_hda_codec_read(codec, 0x14, 0,
5358                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5359         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
5360                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5361         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
5362                                   present ? 1 : 3);
5363 }
5364
5365 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
5366 {
5367         /* Looks like the unsol event is incompatible with the standard
5368          * definition.  4bit tag is placed at 26 bit!
5369          */
5370         if (((res >> 26) == ALC880_HP_EVENT)) {
5371                 alc882_targa_automute(codec);
5372         }
5373 }
5374
5375 static struct hda_verb alc882_asus_a7j_verbs[] = {
5376         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5377         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5378
5379         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5380         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5381         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5382         
5383         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5384         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5385         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5386
5387         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
5388         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
5389         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5390         { } /* end */
5391 };
5392
5393 static struct hda_verb alc882_asus_a7m_verbs[] = {
5394         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5395         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5396
5397         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5398         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5399         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5400         
5401         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5402         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5403         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5404
5405         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
5406         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
5407         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5408         { } /* end */
5409 };
5410
5411 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5412 {
5413         unsigned int gpiostate, gpiomask, gpiodir;
5414
5415         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5416                                        AC_VERB_GET_GPIO_DATA, 0);
5417
5418         if (!muted)
5419                 gpiostate |= (1 << pin);
5420         else
5421                 gpiostate &= ~(1 << pin);
5422
5423         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5424                                       AC_VERB_GET_GPIO_MASK, 0);
5425         gpiomask |= (1 << pin);
5426
5427         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5428                                      AC_VERB_GET_GPIO_DIRECTION, 0);
5429         gpiodir |= (1 << pin);
5430
5431
5432         snd_hda_codec_write(codec, codec->afg, 0,
5433                             AC_VERB_SET_GPIO_MASK, gpiomask);
5434         snd_hda_codec_write(codec, codec->afg, 0,
5435                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5436
5437         msleep(1);
5438
5439         snd_hda_codec_write(codec, codec->afg, 0,
5440                             AC_VERB_SET_GPIO_DATA, gpiostate);
5441 }
5442
5443 /* set up GPIO at initialization */
5444 static void alc885_macpro_init_hook(struct hda_codec *codec)
5445 {
5446         alc882_gpio_mute(codec, 0, 0);
5447         alc882_gpio_mute(codec, 1, 0);
5448 }
5449
5450 /* set up GPIO and update auto-muting at initialization */
5451 static void alc885_imac24_init_hook(struct hda_codec *codec)
5452 {
5453         alc885_macpro_init_hook(codec);
5454         alc885_imac24_automute(codec);
5455 }
5456
5457 /*
5458  * generic initialization of ADC, input mixers and output mixers
5459  */
5460 static struct hda_verb alc882_auto_init_verbs[] = {
5461         /*
5462          * Unmute ADC0-2 and set the default input to mic-in
5463          */
5464         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5465         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5466         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5467         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5468         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5469         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5470
5471         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5472          * mixer widget
5473          * Note: PASD motherboards uses the Line In 2 as the input for
5474          * front panel mic (mic 2)
5475          */
5476         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
5477         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5478         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5479         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5480         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5481         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5482
5483         /*
5484          * Set up output mixers (0x0c - 0x0f)
5485          */
5486         /* set vol=0 to output mixers */
5487         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5488         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5489         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5490         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5491         /* set up input amps for analog loopback */
5492         /* Amp Indices: DAC = 0, mixer = 1 */
5493         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5494         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5495         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5496         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5497         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5498         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5499         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5500         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5501         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5502         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5503
5504         /* FIXME: use matrix-type input source selection */
5505         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5506         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5507         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5508         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
5509         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
5510         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
5511         /* Input mixer2 */
5512         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5513         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
5514         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
5515         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
5516         /* Input mixer3 */
5517         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5518         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
5519         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
5520         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
5521
5522         { }
5523 };
5524
5525 /* capture mixer elements */
5526 static struct snd_kcontrol_new alc882_capture_alt_mixer[] = {
5527         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
5528         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
5529         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
5530         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
5531         {
5532                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5533                 /* The multiple "Capture Source" controls confuse alsamixer
5534                  * So call somewhat different..
5535                  * FIXME: the controls appear in the "playback" view!
5536                  */
5537                 /* .name = "Capture Source", */
5538                 .name = "Input Source",
5539                 .count = 2,
5540                 .info = alc882_mux_enum_info,
5541                 .get = alc882_mux_enum_get,
5542                 .put = alc882_mux_enum_put,
5543         },
5544         { } /* end */
5545 };
5546
5547 static struct snd_kcontrol_new alc882_capture_mixer[] = {
5548         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
5549         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
5550         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
5551         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
5552         HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
5553         HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
5554         {
5555                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5556                 /* The multiple "Capture Source" controls confuse alsamixer
5557                  * So call somewhat different..
5558                  * FIXME: the controls appear in the "playback" view!
5559                  */
5560                 /* .name = "Capture Source", */
5561                 .name = "Input Source",
5562                 .count = 3,
5563                 .info = alc882_mux_enum_info,
5564                 .get = alc882_mux_enum_get,
5565                 .put = alc882_mux_enum_put,
5566         },
5567         { } /* end */
5568 };
5569
5570 #ifdef CONFIG_SND_HDA_POWER_SAVE
5571 #define alc882_loopbacks        alc880_loopbacks
5572 #endif
5573
5574 /* pcm configuration: identiacal with ALC880 */
5575 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
5576 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
5577 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
5578 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
5579
5580 /*
5581  * configuration and preset
5582  */
5583 static const char *alc882_models[ALC882_MODEL_LAST] = {
5584         [ALC882_3ST_DIG]        = "3stack-dig",
5585         [ALC882_6ST_DIG]        = "6stack-dig",
5586         [ALC882_ARIMA]          = "arima",
5587         [ALC882_W2JC]           = "w2jc",
5588         [ALC885_MACPRO]         = "macpro",
5589         [ALC885_MBP3]           = "mbp3",
5590         [ALC885_IMAC24]         = "imac24",
5591         [ALC882_AUTO]           = "auto",
5592 };
5593
5594 static struct snd_pci_quirk alc882_cfg_tbl[] = {
5595         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
5596         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
5597         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
5598         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
5599         SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA),
5600         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
5601         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
5602         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
5603         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
5604         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
5605         {}
5606 };
5607
5608 static struct alc_config_preset alc882_presets[] = {
5609         [ALC882_3ST_DIG] = {
5610                 .mixers = { alc882_base_mixer },
5611                 .init_verbs = { alc882_init_verbs },
5612                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5613                 .dac_nids = alc882_dac_nids,
5614                 .dig_out_nid = ALC882_DIGOUT_NID,
5615                 .dig_in_nid = ALC882_DIGIN_NID,
5616                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
5617                 .channel_mode = alc882_ch_modes,
5618                 .need_dac_fix = 1,
5619                 .input_mux = &alc882_capture_source,
5620         },
5621         [ALC882_6ST_DIG] = {
5622                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
5623                 .init_verbs = { alc882_init_verbs },
5624                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5625                 .dac_nids = alc882_dac_nids,
5626                 .dig_out_nid = ALC882_DIGOUT_NID,
5627                 .dig_in_nid = ALC882_DIGIN_NID,
5628                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
5629                 .channel_mode = alc882_sixstack_modes,
5630                 .input_mux = &alc882_capture_source,
5631         },
5632         [ALC882_ARIMA] = {
5633                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
5634                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs },
5635                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5636                 .dac_nids = alc882_dac_nids,
5637                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
5638                 .channel_mode = alc882_sixstack_modes,
5639                 .input_mux = &alc882_capture_source,
5640         },
5641         [ALC882_W2JC] = {
5642                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
5643                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
5644                                 alc880_gpio1_init_verbs },
5645                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5646                 .dac_nids = alc882_dac_nids,
5647                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
5648                 .channel_mode = alc880_threestack_modes,
5649                 .need_dac_fix = 1,
5650                 .input_mux = &alc882_capture_source,
5651                 .dig_out_nid = ALC882_DIGOUT_NID,
5652         },
5653         [ALC885_MBP3] = {
5654                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
5655                 .init_verbs = { alc885_mbp3_init_verbs,
5656                                 alc880_gpio1_init_verbs },
5657                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5658                 .dac_nids = alc882_dac_nids,
5659                 .channel_mode = alc885_mbp_6ch_modes,
5660                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_6ch_modes),
5661                 .input_mux = &alc882_capture_source,
5662                 .dig_out_nid = ALC882_DIGOUT_NID,
5663                 .dig_in_nid = ALC882_DIGIN_NID,
5664                 .unsol_event = alc885_mbp3_unsol_event,
5665                 .init_hook = alc885_mbp3_automute,
5666         },
5667         [ALC885_MACPRO] = {
5668                 .mixers = { alc882_macpro_mixer },
5669                 .init_verbs = { alc882_macpro_init_verbs },
5670                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5671                 .dac_nids = alc882_dac_nids,
5672                 .dig_out_nid = ALC882_DIGOUT_NID,
5673                 .dig_in_nid = ALC882_DIGIN_NID,
5674                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
5675                 .channel_mode = alc882_ch_modes,
5676                 .input_mux = &alc882_capture_source,
5677                 .init_hook = alc885_macpro_init_hook,
5678         },
5679         [ALC885_IMAC24] = {
5680                 .mixers = { alc885_imac24_mixer },
5681                 .init_verbs = { alc885_imac24_init_verbs },
5682                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5683                 .dac_nids = alc882_dac_nids,
5684                 .dig_out_nid = ALC882_DIGOUT_NID,
5685                 .dig_in_nid = ALC882_DIGIN_NID,
5686                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
5687                 .channel_mode = alc882_ch_modes,
5688                 .input_mux = &alc882_capture_source,
5689                 .unsol_event = alc885_imac24_unsol_event,
5690                 .init_hook = alc885_imac24_init_hook,
5691         },
5692         [ALC882_TARGA] = {
5693                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer,
5694                             alc882_capture_mixer },
5695                 .init_verbs = { alc882_init_verbs, alc882_targa_verbs},
5696                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5697                 .dac_nids = alc882_dac_nids,
5698                 .dig_out_nid = ALC882_DIGOUT_NID,
5699                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
5700                 .adc_nids = alc882_adc_nids,
5701                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
5702                 .channel_mode = alc882_3ST_6ch_modes,
5703                 .need_dac_fix = 1,
5704                 .input_mux = &alc882_capture_source,
5705                 .unsol_event = alc882_targa_unsol_event,
5706                 .init_hook = alc882_targa_automute,
5707         },
5708         [ALC882_ASUS_A7J] = {
5709                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer,
5710                             alc882_capture_mixer },
5711                 .init_verbs = { alc882_init_verbs, alc882_asus_a7j_verbs},
5712                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5713                 .dac_nids = alc882_dac_nids,
5714                 .dig_out_nid = ALC882_DIGOUT_NID,
5715                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
5716                 .adc_nids = alc882_adc_nids,
5717                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
5718                 .channel_mode = alc882_3ST_6ch_modes,
5719                 .need_dac_fix = 1,
5720                 .input_mux = &alc882_capture_source,
5721         },      
5722         [ALC882_ASUS_A7M] = {
5723                 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
5724                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
5725                                 alc880_gpio1_init_verbs,
5726                                 alc882_asus_a7m_verbs },
5727                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5728                 .dac_nids = alc882_dac_nids,
5729                 .dig_out_nid = ALC882_DIGOUT_NID,
5730                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
5731                 .channel_mode = alc880_threestack_modes,
5732                 .need_dac_fix = 1,
5733                 .input_mux = &alc882_capture_source,
5734         },      
5735 };
5736
5737
5738 /*
5739  * Pin config fixes
5740  */
5741 enum { 
5742         PINFIX_ABIT_AW9D_MAX
5743 };
5744
5745 static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
5746         { 0x15, 0x01080104 }, /* side */
5747         { 0x16, 0x01011012 }, /* rear */
5748         { 0x17, 0x01016011 }, /* clfe */
5749         { }
5750 };
5751
5752 static const struct alc_pincfg *alc882_pin_fixes[] = {
5753         [PINFIX_ABIT_AW9D_MAX] = alc882_abit_aw9d_pinfix,
5754 };
5755
5756 static struct snd_pci_quirk alc882_pinfix_tbl[] = {
5757         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
5758         {}
5759 };
5760
5761 /*
5762  * BIOS auto configuration
5763  */
5764 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
5765                                               hda_nid_t nid, int pin_type,
5766                                               int dac_idx)
5767 {
5768         /* set as output */
5769         struct alc_spec *spec = codec->spec;
5770         int idx;
5771
5772         if (spec->multiout.dac_nids[dac_idx] == 0x25)
5773                 idx = 4;
5774         else
5775                 idx = spec->multiout.dac_nids[dac_idx] - 2;
5776
5777         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5778                             pin_type);
5779         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
5780                             AMP_OUT_UNMUTE);
5781         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
5782
5783 }
5784
5785 static void alc882_auto_init_multi_out(struct hda_codec *codec)
5786 {
5787         struct alc_spec *spec = codec->spec;
5788         int i;
5789
5790         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
5791         for (i = 0; i <= HDA_SIDE; i++) {
5792                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
5793                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
5794                 if (nid)
5795                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
5796                                                           i);
5797         }
5798 }
5799
5800 static void alc882_auto_init_hp_out(struct hda_codec *codec)
5801 {
5802         struct alc_spec *spec = codec->spec;
5803         hda_nid_t pin;
5804
5805         pin = spec->autocfg.hp_pins[0];
5806         if (pin) /* connect to front */
5807                 /* use dac 0 */
5808                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
5809 }
5810
5811 #define alc882_is_input_pin(nid)        alc880_is_input_pin(nid)
5812 #define ALC882_PIN_CD_NID               ALC880_PIN_CD_NID
5813
5814 static void alc882_auto_init_analog_input(struct hda_codec *codec)
5815 {
5816         struct alc_spec *spec = codec->spec;
5817         int i;
5818
5819         for (i = 0; i < AUTO_PIN_LAST; i++) {
5820                 hda_nid_t nid = spec->autocfg.input_pins[i];
5821                 if (alc882_is_input_pin(nid)) {
5822                         snd_hda_codec_write(codec, nid, 0,
5823                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
5824                                             i <= AUTO_PIN_FRONT_MIC ?
5825                                             PIN_VREF80 : PIN_IN);
5826                         if (nid != ALC882_PIN_CD_NID)
5827                                 snd_hda_codec_write(codec, nid, 0,
5828                                                     AC_VERB_SET_AMP_GAIN_MUTE,
5829                                                     AMP_OUT_MUTE);
5830                 }
5831         }
5832 }
5833
5834 /* add mic boosts if needed */
5835 static int alc_auto_add_mic_boost(struct hda_codec *codec)
5836 {
5837         struct alc_spec *spec = codec->spec;
5838         int err;
5839         hda_nid_t nid;
5840
5841         nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
5842         if (nid) {
5843                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
5844                                   "Mic Boost",
5845                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
5846                 if (err < 0)
5847                         return err;
5848         }
5849         nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
5850         if (nid) {
5851                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
5852                                   "Front Mic Boost",
5853                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
5854                 if (err < 0)
5855                         return err;
5856         }
5857         return 0;
5858 }
5859
5860 /* almost identical with ALC880 parser... */
5861 static int alc882_parse_auto_config(struct hda_codec *codec)
5862 {
5863         struct alc_spec *spec = codec->spec;
5864         int err = alc880_parse_auto_config(codec);
5865
5866         if (err < 0)
5867                 return err;
5868         else if (!err)
5869                 return 0; /* no config found */
5870
5871         err = alc_auto_add_mic_boost(codec);
5872         if (err < 0)
5873                 return err;
5874
5875         /* hack - override the init verbs */
5876         spec->init_verbs[0] = alc882_auto_init_verbs;
5877
5878         return 1; /* config found */
5879 }
5880
5881 /* additional initialization for auto-configuration model */
5882 static void alc882_auto_init(struct hda_codec *codec)
5883 {
5884         alc882_auto_init_multi_out(codec);
5885         alc882_auto_init_hp_out(codec);
5886         alc882_auto_init_analog_input(codec);
5887 }
5888
5889 static int patch_alc882(struct hda_codec *codec)
5890 {
5891         struct alc_spec *spec;
5892         int err, board_config;
5893
5894         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5895         if (spec == NULL)
5896                 return -ENOMEM;
5897
5898         codec->spec = spec;
5899
5900         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
5901                                                   alc882_models,
5902                                                   alc882_cfg_tbl);
5903
5904         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
5905                 /* Pick up systems that don't supply PCI SSID */
5906                 switch (codec->subsystem_id) {
5907                 case 0x106b0c00: /* Mac Pro */
5908                         board_config = ALC885_MACPRO;
5909                         break;
5910                 case 0x106b1000: /* iMac 24 */
5911                         board_config = ALC885_IMAC24;
5912                         break;
5913                 case 0x106b2c00: /* Macbook Pro rev3 */
5914                         board_config = ALC885_MBP3;
5915                         break;
5916                 default:
5917                         printk(KERN_INFO "hda_codec: Unknown model for ALC882, "
5918                                          "trying auto-probe from BIOS...\n");
5919                         board_config = ALC882_AUTO;
5920                 }
5921         }
5922
5923         alc_fix_pincfg(codec, alc882_pinfix_tbl, alc882_pin_fixes);
5924
5925         if (board_config == ALC882_AUTO) {
5926                 /* automatic parse from the BIOS config */
5927                 err = alc882_parse_auto_config(codec);
5928                 if (err < 0) {
5929                         alc_free(codec);
5930                         return err;
5931                 } else if (!err) {
5932                         printk(KERN_INFO
5933                                "hda_codec: Cannot set up configuration "
5934                                "from BIOS.  Using base mode...\n");
5935                         board_config = ALC882_3ST_DIG;
5936                 }
5937         }
5938
5939         if (board_config != ALC882_AUTO)
5940                 setup_preset(spec, &alc882_presets[board_config]);
5941
5942         spec->stream_name_analog = "ALC882 Analog";
5943         spec->stream_analog_playback = &alc882_pcm_analog_playback;
5944         spec->stream_analog_capture = &alc882_pcm_analog_capture;
5945
5946         spec->stream_name_digital = "ALC882 Digital";
5947         spec->stream_digital_playback = &alc882_pcm_digital_playback;
5948         spec->stream_digital_capture = &alc882_pcm_digital_capture;
5949
5950         if (!spec->adc_nids && spec->input_mux) {
5951                 /* check whether NID 0x07 is valid */
5952                 unsigned int wcap = get_wcaps(codec, 0x07);
5953                 /* get type */
5954                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
5955                 if (wcap != AC_WID_AUD_IN) {
5956                         spec->adc_nids = alc882_adc_nids_alt;
5957                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
5958                         spec->mixers[spec->num_mixers] =
5959                                 alc882_capture_alt_mixer;
5960                         spec->num_mixers++;
5961                 } else {
5962                         spec->adc_nids = alc882_adc_nids;
5963                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
5964                         spec->mixers[spec->num_mixers] = alc882_capture_mixer;
5965                         spec->num_mixers++;
5966                 }
5967         }
5968
5969         codec->patch_ops = alc_patch_ops;
5970         if (board_config == ALC882_AUTO)
5971                 spec->init_hook = alc882_auto_init;
5972 #ifdef CONFIG_SND_HDA_POWER_SAVE
5973         if (!spec->loopback.amplist)
5974                 spec->loopback.amplist = alc882_loopbacks;
5975 #endif
5976
5977         return 0;
5978 }
5979
5980 /*
5981  * ALC883 support
5982  *
5983  * ALC883 is almost identical with ALC880 but has cleaner and more flexible
5984  * configuration.  Each pin widget can choose any input DACs and a mixer.
5985  * Each ADC is connected from a mixer of all inputs.  This makes possible
5986  * 6-channel independent captures.
5987  *
5988  * In addition, an independent DAC for the multi-playback (not used in this
5989  * driver yet).
5990  */
5991 #define ALC883_DIGOUT_NID       0x06
5992 #define ALC883_DIGIN_NID        0x0a
5993
5994 static hda_nid_t alc883_dac_nids[4] = {
5995         /* front, rear, clfe, rear_surr */
5996         0x02, 0x04, 0x03, 0x05
5997 };
5998
5999 static hda_nid_t alc883_adc_nids[2] = {
6000         /* ADC1-2 */
6001         0x08, 0x09,
6002 };
6003
6004 /* input MUX */
6005 /* FIXME: should be a matrix-type input source selection */
6006
6007 static struct hda_input_mux alc883_capture_source = {
6008         .num_items = 4,
6009         .items = {
6010                 { "Mic", 0x0 },
6011                 { "Front Mic", 0x1 },
6012                 { "Line", 0x2 },
6013                 { "CD", 0x4 },
6014         },
6015 };
6016
6017 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
6018         .num_items = 2,
6019         .items = {
6020                 { "Mic", 0x1 },
6021                 { "Line", 0x2 },
6022         },
6023 };
6024
6025 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
6026         .num_items = 4,
6027         .items = {
6028                 { "Mic", 0x0 },
6029                 { "iMic", 0x1 },
6030                 { "Line", 0x2 },
6031                 { "CD", 0x4 },
6032         },
6033 };
6034
6035 #define alc883_mux_enum_info alc_mux_enum_info
6036 #define alc883_mux_enum_get alc_mux_enum_get
6037
6038 static int alc883_mux_enum_put(struct snd_kcontrol *kcontrol,
6039                                struct snd_ctl_elem_value *ucontrol)
6040 {
6041         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6042         struct alc_spec *spec = codec->spec;
6043         const struct hda_input_mux *imux = spec->input_mux;
6044         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
6045         static hda_nid_t capture_mixers[3] = { 0x24, 0x23, 0x22 };
6046         hda_nid_t nid = capture_mixers[adc_idx];
6047         unsigned int *cur_val = &spec->cur_mux[adc_idx];
6048         unsigned int i, idx;
6049
6050         idx = ucontrol->value.enumerated.item[0];
6051         if (idx >= imux->num_items)
6052                 idx = imux->num_items - 1;
6053         if (*cur_val == idx)
6054                 return 0;
6055         for (i = 0; i < imux->num_items; i++) {
6056                 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
6057                 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
6058                                          imux->items[i].index,
6059                                          HDA_AMP_MUTE, v);
6060         }
6061         *cur_val = idx;
6062         return 1;
6063 }
6064
6065 /*
6066  * 2ch mode
6067  */
6068 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
6069         { 2, NULL }
6070 };
6071
6072 /*
6073  * 2ch mode
6074  */
6075 static struct hda_verb alc883_3ST_ch2_init[] = {
6076         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6077         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6078         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6079         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6080         { } /* end */
6081 };
6082
6083 /*
6084  * 6ch mode
6085  */
6086 static struct hda_verb alc883_3ST_ch6_init[] = {
6087         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6088         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6089         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6090         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6091         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6092         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6093         { } /* end */
6094 };
6095
6096 static struct hda_channel_mode alc883_3ST_6ch_modes[2] = {
6097         { 2, alc883_3ST_ch2_init },
6098         { 6, alc883_3ST_ch6_init },
6099 };
6100
6101 /*
6102  * 6ch mode
6103  */
6104 static struct hda_verb alc883_sixstack_ch6_init[] = {
6105         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6106         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6107         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6108         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6109         { } /* end */
6110 };
6111
6112 /*
6113  * 8ch mode
6114  */
6115 static struct hda_verb alc883_sixstack_ch8_init[] = {
6116         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6117         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6118         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6119         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6120         { } /* end */
6121 };
6122
6123 static struct hda_channel_mode alc883_sixstack_modes[2] = {
6124         { 6, alc883_sixstack_ch6_init },
6125         { 8, alc883_sixstack_ch8_init },
6126 };
6127
6128 static struct hda_verb alc883_medion_eapd_verbs[] = {
6129         /* eanable EAPD on medion laptop */
6130         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
6131         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
6132         { }
6133 };
6134
6135 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
6136  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
6137  */
6138
6139 static struct snd_kcontrol_new alc883_base_mixer[] = {
6140         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6141         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6142         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6143         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6144         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6145         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6146         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6147         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6148         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6149         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6150         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6151         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6152         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6153         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6154         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6155         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6156         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6157         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6158         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6159         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6160         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6161         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6162         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6163         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6164         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6165         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6166         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6167         {
6168                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6169                 /* .name = "Capture Source", */
6170                 .name = "Input Source",
6171                 .count = 2,
6172                 .info = alc883_mux_enum_info,
6173                 .get = alc883_mux_enum_get,
6174                 .put = alc883_mux_enum_put,
6175         },
6176         { } /* end */
6177 };
6178
6179 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
6180         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6181         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6182         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6183         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6184         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6185         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6186         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6187         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6188         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6189         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6190         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6191         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6192         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6193         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6194         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6195         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6196         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6197         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6198         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6199         {
6200                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6201                 /* .name = "Capture Source", */
6202                 .name = "Input Source",
6203                 .count = 2,
6204                 .info = alc883_mux_enum_info,
6205                 .get = alc883_mux_enum_get,
6206                 .put = alc883_mux_enum_put,
6207         },
6208         { } /* end */
6209 };
6210
6211 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
6212         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6213         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6214         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6215         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6216         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6217         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6218         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6219         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6220         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6221         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6222         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6223         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6224         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6225         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6226         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6227         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6228         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6229         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6230         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6231         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6232         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6233         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6234         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6235         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6236         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6237         {
6238                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6239                 /* .name = "Capture Source", */
6240                 .name = "Input Source",
6241                 .count = 2,
6242                 .info = alc883_mux_enum_info,
6243                 .get = alc883_mux_enum_get,
6244                 .put = alc883_mux_enum_put,
6245         },
6246         { } /* end */
6247 };
6248
6249 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
6250         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6251         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6252         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6253         HDA_CODEC_MUTE("Surround Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6254         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6255         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6256         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x16, 1, 0x0, HDA_OUTPUT),
6257         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
6258         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6259         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6260         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6261         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6262         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6263         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6264         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6265         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6266         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6267         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6268         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6269         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6270         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6271         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6272         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6273
6274         {
6275                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6276                 /* .name = "Capture Source", */
6277                 .name = "Input Source",
6278                 .count = 1,
6279                 .info = alc883_mux_enum_info,
6280                 .get = alc883_mux_enum_get,
6281                 .put = alc883_mux_enum_put,
6282         },
6283         { } /* end */
6284 };
6285
6286 static struct snd_kcontrol_new alc883_tagra_mixer[] = {
6287         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6288         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6289         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6290         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6291         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6292         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6293         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6294         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6295         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6296         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6297         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6298         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6299         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6300         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6301         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6302         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6303         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6304         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6305         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6306         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6307         {
6308                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6309                 /* .name = "Capture Source", */
6310                 .name = "Input Source",
6311                 .count = 2,
6312                 .info = alc883_mux_enum_info,
6313                 .get = alc883_mux_enum_get,
6314                 .put = alc883_mux_enum_put,
6315         },
6316         { } /* end */
6317 };
6318
6319 static struct snd_kcontrol_new alc883_tagra_2ch_mixer[] = {
6320         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6321         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6322         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6323         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6324         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6325         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6326         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6327         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6328         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6329         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6330         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6331         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6332         {
6333                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6334                 /* .name = "Capture Source", */
6335                 .name = "Input Source",
6336                 .count = 2,
6337                 .info = alc883_mux_enum_info,
6338                 .get = alc883_mux_enum_get,
6339                 .put = alc883_mux_enum_put,
6340         },
6341         { } /* end */
6342 };
6343
6344 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
6345         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6346         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6347         HDA_CODEC_VOLUME("iSpeaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6348         HDA_BIND_MUTE("iSpeaker Playback Switch", 0x0d, 2, HDA_INPUT),
6349         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6350         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6351         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6352         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6353         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6354         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6355         {
6356                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6357                 /* .name = "Capture Source", */
6358                 .name = "Input Source",
6359                 .count = 1,
6360                 .info = alc883_mux_enum_info,
6361                 .get = alc883_mux_enum_get,
6362                 .put = alc883_mux_enum_put,
6363         },
6364         { } /* end */
6365 };
6366
6367 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
6368         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6369         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
6370         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6371         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6372         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6373         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6374         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6375         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6376         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6377         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6378         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6379         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6380         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6381         {
6382                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6383                 /* .name = "Capture Source", */
6384                 .name = "Input Source",
6385                 .count = 2,
6386                 .info = alc883_mux_enum_info,
6387                 .get = alc883_mux_enum_get,
6388                 .put = alc883_mux_enum_put,
6389         },
6390         { } /* end */
6391 };
6392
6393 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
6394         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6395         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6396         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6397         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6398         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6399         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6400         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6401         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6402         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6403         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6404         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6405         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6406         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6407         {
6408                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6409                 /* .name = "Capture Source", */
6410                 .name = "Input Source",
6411                 .count = 2,
6412                 .info = alc883_mux_enum_info,
6413                 .get = alc883_mux_enum_get,
6414                 .put = alc883_mux_enum_put,
6415         },
6416         { } /* end */
6417 };      
6418
6419 static struct snd_kcontrol_new alc888_6st_hp_mixer[] = {
6420         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6421         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6422         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
6423         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
6424         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
6425         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
6426         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
6427         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
6428         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6429         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6430         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6431         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6432         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6433         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6434         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6435         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6436         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6437         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6438         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6439         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6440         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6441         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6442         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6443         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6444         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6445         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6446         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6447         {
6448                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6449                 /* .name = "Capture Source", */
6450                 .name = "Input Source",
6451                 .count = 2,
6452                 .info = alc883_mux_enum_info,
6453                 .get = alc883_mux_enum_get,
6454                 .put = alc883_mux_enum_put,
6455         },
6456         { } /* end */
6457 };
6458
6459 static struct snd_kcontrol_new alc888_3st_hp_mixer[] = {
6460         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6461         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6462         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
6463         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
6464         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
6465         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
6466         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
6467         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
6468         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6469         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6470         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6471         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6472         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6473         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6474         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6475         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6476         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6477         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6478         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6479         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6480         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6481         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6482         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6483         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6484         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6485         {
6486                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6487                 /* .name = "Capture Source", */
6488                 .name = "Input Source",
6489                 .count = 2,
6490                 .info = alc883_mux_enum_info,
6491                 .get = alc883_mux_enum_get,
6492                 .put = alc883_mux_enum_put,
6493         },
6494         { } /* end */
6495 };
6496
6497 static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
6498         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6499         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6500         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6501         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6502         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6503         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6504         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6505         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6506         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6507         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6508         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6509         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6510         {
6511                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6512                 /* .name = "Capture Source", */
6513                 .name = "Input Source",
6514                 .count = 2,
6515                 .info = alc883_mux_enum_info,
6516                 .get = alc883_mux_enum_get,
6517                 .put = alc883_mux_enum_put,
6518         },
6519         { } /* end */
6520 };
6521
6522 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
6523         {
6524                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6525                 .name = "Channel Mode",
6526                 .info = alc_ch_mode_info,
6527                 .get = alc_ch_mode_get,
6528                 .put = alc_ch_mode_put,
6529         },
6530         { } /* end */
6531 };
6532
6533 static struct hda_verb alc883_init_verbs[] = {
6534         /* ADC1: mute amp left and right */
6535         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6536         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6537         /* ADC2: mute amp left and right */
6538         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6539         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6540         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6541         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6542         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6543         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6544         /* Rear mixer */
6545         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6546         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6547         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6548         /* CLFE mixer */
6549         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6550         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6551         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6552         /* Side mixer */
6553         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6554         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6555         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6556
6557         /* mute analog input loopbacks */
6558         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6559         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6560         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6561         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6562         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6563
6564         /* Front Pin: output 0 (0x0c) */
6565         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6566         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6567         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6568         /* Rear Pin: output 1 (0x0d) */
6569         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6570         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6571         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
6572         /* CLFE Pin: output 2 (0x0e) */
6573         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6574         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6575         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
6576         /* Side Pin: output 3 (0x0f) */
6577         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6578         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6579         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
6580         /* Mic (rear) pin: input vref at 80% */
6581         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6582         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6583         /* Front Mic pin: input vref at 80% */
6584         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6585         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6586         /* Line In pin: input */
6587         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6588         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6589         /* Line-2 In: Headphone output (output 0 - 0x0c) */
6590         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6591         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6592         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
6593         /* CD pin widget for input */
6594         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6595
6596         /* FIXME: use matrix-type input source selection */
6597         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6598         /* Input mixer2 */
6599         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6600         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6601         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6602         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
6603         /* Input mixer3 */
6604         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6605         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6606         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6607         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
6608         { }
6609 };
6610
6611 static struct hda_verb alc883_tagra_verbs[] = {
6612         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6613         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6614
6615         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6616         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6617         
6618         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6619         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6620         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6621
6622         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6623         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6624         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
6625         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
6626
6627         { } /* end */
6628 };
6629
6630 static struct hda_verb alc883_lenovo_101e_verbs[] = {
6631         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6632         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
6633         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
6634         { } /* end */
6635 };
6636
6637 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
6638         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6639         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6640         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6641         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6642         { } /* end */
6643 };
6644
6645 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
6646         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6647         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6648         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6649         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
6650         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
6651         { } /* end */
6652 };
6653
6654 static struct hda_verb alc883_haier_w66_verbs[] = {
6655         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6656         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6657
6658         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6659
6660         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
6661         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6662         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6663         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6664         { } /* end */
6665 };
6666
6667 static struct hda_verb alc888_6st_hp_verbs[] = {
6668         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
6669         {0x15, AC_VERB_SET_CONNECT_SEL, 0x02},  /* Rear : output 2 (0x0e) */
6670         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* CLFE : output 1 (0x0d) */
6671         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},  /* Side : output 3 (0x0f) */
6672         { }
6673 };
6674
6675 static struct hda_verb alc888_3st_hp_verbs[] = {
6676         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
6677         {0x18, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
6678         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
6679         { }
6680 };
6681
6682 static struct hda_verb alc888_3st_hp_2ch_init[] = {
6683         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6684         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6685         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6686         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6687         { }
6688 };
6689
6690 static struct hda_verb alc888_3st_hp_6ch_init[] = {
6691         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6692         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6693         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6694         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6695         { }
6696 };
6697
6698 static struct hda_channel_mode alc888_3st_hp_modes[2] = {
6699         { 2, alc888_3st_hp_2ch_init },
6700         { 6, alc888_3st_hp_6ch_init },
6701 };
6702
6703 /* toggle front-jack and RCA according to the hp-jack state */
6704 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
6705 {
6706         unsigned int present;
6707  
6708         present = snd_hda_codec_read(codec, 0x1b, 0,
6709                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6710         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
6711                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6712         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
6713                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6714 }
6715
6716 /* toggle RCA according to the front-jack state */
6717 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
6718 {
6719         unsigned int present;
6720  
6721         present = snd_hda_codec_read(codec, 0x14, 0,
6722                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6723         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
6724                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6725 }
6726
6727 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
6728                                              unsigned int res)
6729 {
6730         if ((res >> 26) == ALC880_HP_EVENT)
6731                 alc888_lenovo_ms7195_front_automute(codec);
6732         if ((res >> 26) == ALC880_FRONT_EVENT)
6733                 alc888_lenovo_ms7195_rca_automute(codec);
6734 }
6735
6736 static struct hda_verb alc883_medion_md2_verbs[] = {
6737         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6738         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6739
6740         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6741
6742         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6743         { } /* end */
6744 };
6745
6746 /* toggle speaker-output according to the hp-jack state */
6747 static void alc883_medion_md2_automute(struct hda_codec *codec)
6748 {
6749         unsigned int present;
6750  
6751         present = snd_hda_codec_read(codec, 0x14, 0,
6752                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6753         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
6754                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6755 }
6756
6757 static void alc883_medion_md2_unsol_event(struct hda_codec *codec,
6758                                           unsigned int res)
6759 {
6760         if ((res >> 26) == ALC880_HP_EVENT)
6761                 alc883_medion_md2_automute(codec);
6762 }
6763
6764 /* toggle speaker-output according to the hp-jack state */
6765 static void alc883_tagra_automute(struct hda_codec *codec)
6766 {
6767         unsigned int present;
6768         unsigned char bits;
6769
6770         present = snd_hda_codec_read(codec, 0x14, 0,
6771                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6772         bits = present ? HDA_AMP_MUTE : 0;
6773         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
6774                                  HDA_AMP_MUTE, bits);
6775         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
6776                                   present ? 1 : 3);
6777 }
6778
6779 static void alc883_tagra_unsol_event(struct hda_codec *codec, unsigned int res)
6780 {
6781         if ((res >> 26) == ALC880_HP_EVENT)
6782                 alc883_tagra_automute(codec);
6783 }
6784
6785 static void alc883_haier_w66_automute(struct hda_codec *codec)
6786 {
6787         unsigned int present;
6788         unsigned char bits;
6789
6790         present = snd_hda_codec_read(codec, 0x1b, 0,
6791                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6792         bits = present ? 0x80 : 0;
6793         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
6794                                  0x80, bits);
6795 }
6796
6797 static void alc883_haier_w66_unsol_event(struct hda_codec *codec,
6798                                          unsigned int res)
6799 {
6800         if ((res >> 26) == ALC880_HP_EVENT)
6801                 alc883_haier_w66_automute(codec);
6802 }
6803
6804 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
6805 {
6806         unsigned int present;
6807         unsigned char bits;
6808
6809         present = snd_hda_codec_read(codec, 0x14, 0,
6810                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6811         bits = present ? HDA_AMP_MUTE : 0;
6812         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
6813                                  HDA_AMP_MUTE, bits);
6814 }
6815
6816 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
6817 {
6818         unsigned int present;
6819         unsigned char bits;
6820
6821         present = snd_hda_codec_read(codec, 0x1b, 0,
6822                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6823         bits = present ? HDA_AMP_MUTE : 0;
6824         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
6825                                  HDA_AMP_MUTE, bits);
6826         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
6827                                  HDA_AMP_MUTE, bits);
6828 }
6829
6830 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
6831                                            unsigned int res)
6832 {
6833         if ((res >> 26) == ALC880_HP_EVENT)
6834                 alc883_lenovo_101e_all_automute(codec);
6835         if ((res >> 26) == ALC880_FRONT_EVENT)
6836                 alc883_lenovo_101e_ispeaker_automute(codec);
6837 }
6838
6839 /* toggle speaker-output according to the hp-jack state */
6840 static void alc883_acer_aspire_automute(struct hda_codec *codec)
6841 {
6842         unsigned int present;
6843  
6844         present = snd_hda_codec_read(codec, 0x14, 0,
6845                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6846         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
6847                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6848         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
6849                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6850 }
6851
6852 static void alc883_acer_aspire_unsol_event(struct hda_codec *codec,
6853                                            unsigned int res)
6854 {
6855         if ((res >> 26) == ALC880_HP_EVENT)
6856                 alc883_acer_aspire_automute(codec);
6857 }
6858
6859 static struct hda_verb alc883_acer_eapd_verbs[] = {
6860         /* HP Pin: output 0 (0x0c) */
6861         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6862         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6863         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6864         /* Front Pin: output 0 (0x0c) */
6865         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6866         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6867         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6868         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
6869         /* eanable EAPD on medion laptop */
6870         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
6871         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
6872         /* enable unsolicited event */
6873         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6874         { }
6875 };
6876
6877 /*
6878  * generic initialization of ADC, input mixers and output mixers
6879  */
6880 static struct hda_verb alc883_auto_init_verbs[] = {
6881         /*
6882          * Unmute ADC0-2 and set the default input to mic-in
6883          */
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         /* Mute 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_MUTE(0)},
6896         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6897         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6898         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6899         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6900
6901         /*
6902          * Set up output mixers (0x0c - 0x0f)
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         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6909         /* set up input amps for analog loopback */
6910         /* Amp Indices: DAC = 0, mixer = 1 */
6911         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6912         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6913         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6914         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6915         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6916         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6917         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6918         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6919         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6920         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6921
6922         /* FIXME: use matrix-type input source selection */
6923         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6924         /* Input mixer1 */
6925         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6926         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6927         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6928         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
6929         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
6930         /* Input mixer2 */
6931         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6932         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6933         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6934         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
6935         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
6936
6937         { }
6938 };
6939
6940 /* capture mixer elements */
6941 static struct snd_kcontrol_new alc883_capture_mixer[] = {
6942         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6943         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6944         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6945         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6946         {
6947                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6948                 /* The multiple "Capture Source" controls confuse alsamixer
6949                  * So call somewhat different..
6950                  * FIXME: the controls appear in the "playback" view!
6951                  */
6952                 /* .name = "Capture Source", */
6953                 .name = "Input Source",
6954                 .count = 2,
6955                 .info = alc882_mux_enum_info,
6956                 .get = alc882_mux_enum_get,
6957                 .put = alc882_mux_enum_put,
6958         },
6959         { } /* end */
6960 };
6961
6962 #ifdef CONFIG_SND_HDA_POWER_SAVE
6963 #define alc883_loopbacks        alc880_loopbacks
6964 #endif
6965
6966 /* pcm configuration: identiacal with ALC880 */
6967 #define alc883_pcm_analog_playback      alc880_pcm_analog_playback
6968 #define alc883_pcm_analog_capture       alc880_pcm_analog_capture
6969 #define alc883_pcm_digital_playback     alc880_pcm_digital_playback
6970 #define alc883_pcm_digital_capture      alc880_pcm_digital_capture
6971
6972 /*
6973  * configuration and preset
6974  */
6975 static const char *alc883_models[ALC883_MODEL_LAST] = {
6976         [ALC883_3ST_2ch_DIG]    = "3stack-dig",
6977         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
6978         [ALC883_3ST_6ch]        = "3stack-6ch",
6979         [ALC883_6ST_DIG]        = "6stack-dig",
6980         [ALC883_TARGA_DIG]      = "targa-dig",
6981         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
6982         [ALC883_ACER]           = "acer",
6983         [ALC883_ACER_ASPIRE]    = "acer-aspire",
6984         [ALC883_MEDION]         = "medion",
6985         [ALC883_MEDION_MD2]     = "medion-md2",
6986         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
6987         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
6988         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
6989         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
6990         [ALC883_HAIER_W66]      = "haier-w66",
6991         [ALC888_6ST_HP]         = "6stack-hp",
6992         [ALC888_3ST_HP]         = "3stack-hp",
6993         [ALC883_AUTO]           = "auto",
6994 };
6995
6996 static struct snd_pci_quirk alc883_cfg_tbl[] = {
6997         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG),
6998         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
6999         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
7000         SND_PCI_QUIRK(0x1558, 0, "Clevo laptop", ALC883_LAPTOP_EAPD),
7001         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
7002         SND_PCI_QUIRK(0x1458, 0xa002, "MSI", ALC883_6ST_DIG),
7003         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
7004         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
7005         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
7006         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
7007         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
7008         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
7009         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
7010         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
7011         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
7012         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
7013         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
7014         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
7015         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
7016         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
7017         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
7018         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
7019         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
7020         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
7021         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
7022         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
7023         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
7024         SND_PCI_QUIRK(0x1025, 0, "Acer laptop", ALC883_ACER),
7025         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
7026         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
7027         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
7028         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
7029         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
7030         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
7031         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
7032         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC888_6ST_HP),
7033         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
7034         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
7035         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
7036         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
7037         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
7038         {}
7039 };
7040
7041 static struct alc_config_preset alc883_presets[] = {
7042         [ALC883_3ST_2ch_DIG] = {
7043                 .mixers = { alc883_3ST_2ch_mixer },
7044                 .init_verbs = { alc883_init_verbs },
7045                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7046                 .dac_nids = alc883_dac_nids,
7047                 .dig_out_nid = ALC883_DIGOUT_NID,
7048                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7049                 .adc_nids = alc883_adc_nids,
7050                 .dig_in_nid = ALC883_DIGIN_NID,
7051                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7052                 .channel_mode = alc883_3ST_2ch_modes,
7053                 .input_mux = &alc883_capture_source,
7054         },
7055         [ALC883_3ST_6ch_DIG] = {
7056                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
7057                 .init_verbs = { alc883_init_verbs },
7058                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7059                 .dac_nids = alc883_dac_nids,
7060                 .dig_out_nid = ALC883_DIGOUT_NID,
7061                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7062                 .adc_nids = alc883_adc_nids,
7063                 .dig_in_nid = ALC883_DIGIN_NID,
7064                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7065                 .channel_mode = alc883_3ST_6ch_modes,
7066                 .need_dac_fix = 1,
7067                 .input_mux = &alc883_capture_source,
7068         },
7069         [ALC883_3ST_6ch] = {
7070                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
7071                 .init_verbs = { alc883_init_verbs },
7072                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7073                 .dac_nids = alc883_dac_nids,
7074                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7075                 .adc_nids = alc883_adc_nids,
7076                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7077                 .channel_mode = alc883_3ST_6ch_modes,
7078                 .need_dac_fix = 1,
7079                 .input_mux = &alc883_capture_source,
7080         },
7081         [ALC883_6ST_DIG] = {
7082                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
7083                 .init_verbs = { alc883_init_verbs },
7084                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7085                 .dac_nids = alc883_dac_nids,
7086                 .dig_out_nid = ALC883_DIGOUT_NID,
7087                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7088                 .adc_nids = alc883_adc_nids,
7089                 .dig_in_nid = ALC883_DIGIN_NID,
7090                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7091                 .channel_mode = alc883_sixstack_modes,
7092                 .input_mux = &alc883_capture_source,
7093         },
7094         [ALC883_TARGA_DIG] = {
7095                 .mixers = { alc883_tagra_mixer, alc883_chmode_mixer },
7096                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
7097                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7098                 .dac_nids = alc883_dac_nids,
7099                 .dig_out_nid = ALC883_DIGOUT_NID,
7100                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7101                 .adc_nids = alc883_adc_nids,
7102                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7103                 .channel_mode = alc883_3ST_6ch_modes,
7104                 .need_dac_fix = 1,
7105                 .input_mux = &alc883_capture_source,
7106                 .unsol_event = alc883_tagra_unsol_event,
7107                 .init_hook = alc883_tagra_automute,
7108         },
7109         [ALC883_TARGA_2ch_DIG] = {
7110                 .mixers = { alc883_tagra_2ch_mixer},
7111                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
7112                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7113                 .dac_nids = alc883_dac_nids,
7114                 .dig_out_nid = ALC883_DIGOUT_NID,
7115                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7116                 .adc_nids = alc883_adc_nids,
7117                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7118                 .channel_mode = alc883_3ST_2ch_modes,
7119                 .input_mux = &alc883_capture_source,
7120                 .unsol_event = alc883_tagra_unsol_event,
7121                 .init_hook = alc883_tagra_automute,
7122         },
7123         [ALC883_ACER] = {
7124                 .mixers = { alc883_base_mixer },
7125                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
7126                  * and the headphone jack.  Turn this on and rely on the
7127                  * standard mute methods whenever the user wants to turn
7128                  * these outputs off.
7129                  */
7130                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
7131                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7132                 .dac_nids = alc883_dac_nids,
7133                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7134                 .adc_nids = alc883_adc_nids,
7135                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7136                 .channel_mode = alc883_3ST_2ch_modes,
7137                 .input_mux = &alc883_capture_source,
7138         },
7139         [ALC883_ACER_ASPIRE] = {
7140                 .mixers = { alc883_acer_aspire_mixer },
7141                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
7142                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7143                 .dac_nids = alc883_dac_nids,
7144                 .dig_out_nid = ALC883_DIGOUT_NID,
7145                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7146                 .adc_nids = alc883_adc_nids,
7147                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7148                 .channel_mode = alc883_3ST_2ch_modes,
7149                 .input_mux = &alc883_capture_source,
7150                 .unsol_event = alc883_acer_aspire_unsol_event,
7151                 .init_hook = alc883_acer_aspire_automute,
7152         },
7153         [ALC883_MEDION] = {
7154                 .mixers = { alc883_fivestack_mixer,
7155                             alc883_chmode_mixer },
7156                 .init_verbs = { alc883_init_verbs,
7157                                 alc883_medion_eapd_verbs },
7158                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7159                 .dac_nids = alc883_dac_nids,
7160                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7161                 .adc_nids = alc883_adc_nids,
7162                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7163                 .channel_mode = alc883_sixstack_modes,
7164                 .input_mux = &alc883_capture_source,
7165         },
7166         [ALC883_MEDION_MD2] = {
7167                 .mixers = { alc883_medion_md2_mixer},
7168                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
7169                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7170                 .dac_nids = alc883_dac_nids,
7171                 .dig_out_nid = ALC883_DIGOUT_NID,
7172                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7173                 .adc_nids = alc883_adc_nids,
7174                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7175                 .channel_mode = alc883_3ST_2ch_modes,
7176                 .input_mux = &alc883_capture_source,
7177                 .unsol_event = alc883_medion_md2_unsol_event,
7178                 .init_hook = alc883_medion_md2_automute,
7179         },      
7180         [ALC883_LAPTOP_EAPD] = {
7181                 .mixers = { alc883_base_mixer },
7182                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
7183                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7184                 .dac_nids = alc883_dac_nids,
7185                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7186                 .adc_nids = alc883_adc_nids,
7187                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7188                 .channel_mode = alc883_3ST_2ch_modes,
7189                 .input_mux = &alc883_capture_source,
7190         },
7191         [ALC883_LENOVO_101E_2ch] = {
7192                 .mixers = { alc883_lenovo_101e_2ch_mixer},
7193                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
7194                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7195                 .dac_nids = alc883_dac_nids,
7196                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7197                 .adc_nids = alc883_adc_nids,
7198                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7199                 .channel_mode = alc883_3ST_2ch_modes,
7200                 .input_mux = &alc883_lenovo_101e_capture_source,
7201                 .unsol_event = alc883_lenovo_101e_unsol_event,
7202                 .init_hook = alc883_lenovo_101e_all_automute,
7203         },
7204         [ALC883_LENOVO_NB0763] = {
7205                 .mixers = { alc883_lenovo_nb0763_mixer },
7206                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
7207                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7208                 .dac_nids = alc883_dac_nids,
7209                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7210                 .adc_nids = alc883_adc_nids,
7211                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7212                 .channel_mode = alc883_3ST_2ch_modes,
7213                 .need_dac_fix = 1,
7214                 .input_mux = &alc883_lenovo_nb0763_capture_source,
7215                 .unsol_event = alc883_medion_md2_unsol_event,
7216                 .init_hook = alc883_medion_md2_automute,
7217         },
7218         [ALC888_LENOVO_MS7195_DIG] = {
7219                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
7220                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
7221                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7222                 .dac_nids = alc883_dac_nids,
7223                 .dig_out_nid = ALC883_DIGOUT_NID,
7224                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7225                 .adc_nids = alc883_adc_nids,
7226                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7227                 .channel_mode = alc883_3ST_6ch_modes,
7228                 .need_dac_fix = 1,
7229                 .input_mux = &alc883_capture_source,
7230                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
7231                 .init_hook = alc888_lenovo_ms7195_front_automute,
7232         },
7233         [ALC883_HAIER_W66] = {
7234                 .mixers = { alc883_tagra_2ch_mixer},
7235                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
7236                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7237                 .dac_nids = alc883_dac_nids,
7238                 .dig_out_nid = ALC883_DIGOUT_NID,
7239                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7240                 .adc_nids = alc883_adc_nids,
7241                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7242                 .channel_mode = alc883_3ST_2ch_modes,
7243                 .input_mux = &alc883_capture_source,
7244                 .unsol_event = alc883_haier_w66_unsol_event,
7245                 .init_hook = alc883_haier_w66_automute,
7246         },      
7247         [ALC888_6ST_HP] = {
7248                 .mixers = { alc888_6st_hp_mixer, alc883_chmode_mixer },
7249                 .init_verbs = { alc883_init_verbs, alc888_6st_hp_verbs },
7250                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7251                 .dac_nids = alc883_dac_nids,
7252                 .dig_out_nid = ALC883_DIGOUT_NID,
7253                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7254                 .adc_nids = alc883_adc_nids,
7255                 .dig_in_nid = ALC883_DIGIN_NID,
7256                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7257                 .channel_mode = alc883_sixstack_modes,
7258                 .input_mux = &alc883_capture_source,
7259         },
7260         [ALC888_3ST_HP] = {
7261                 .mixers = { alc888_3st_hp_mixer, alc883_chmode_mixer },
7262                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
7263                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7264                 .dac_nids = alc883_dac_nids,
7265                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7266                 .adc_nids = alc883_adc_nids,
7267                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
7268                 .channel_mode = alc888_3st_hp_modes,
7269                 .need_dac_fix = 1,
7270                 .input_mux = &alc883_capture_source,
7271         },
7272 };
7273
7274
7275 /*
7276  * BIOS auto configuration
7277  */
7278 static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
7279                                               hda_nid_t nid, int pin_type,
7280                                               int dac_idx)
7281 {
7282         /* set as output */
7283         struct alc_spec *spec = codec->spec;
7284         int idx;
7285
7286         if (spec->multiout.dac_nids[dac_idx] == 0x25)
7287                 idx = 4;
7288         else
7289                 idx = spec->multiout.dac_nids[dac_idx] - 2;
7290
7291         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
7292                             pin_type);
7293         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
7294                             AMP_OUT_UNMUTE);
7295         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
7296
7297 }
7298
7299 static void alc883_auto_init_multi_out(struct hda_codec *codec)
7300 {
7301         struct alc_spec *spec = codec->spec;
7302         int i;
7303
7304         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
7305         for (i = 0; i <= HDA_SIDE; i++) {
7306                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
7307                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
7308                 if (nid)
7309                         alc883_auto_set_output_and_unmute(codec, nid, pin_type,
7310                                                           i);
7311         }
7312 }
7313
7314 static void alc883_auto_init_hp_out(struct hda_codec *codec)
7315 {
7316         struct alc_spec *spec = codec->spec;
7317         hda_nid_t pin;
7318
7319         pin = spec->autocfg.hp_pins[0];
7320         if (pin) /* connect to front */
7321                 /* use dac 0 */
7322                 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
7323 }
7324
7325 #define alc883_is_input_pin(nid)        alc880_is_input_pin(nid)
7326 #define ALC883_PIN_CD_NID               ALC880_PIN_CD_NID
7327
7328 static void alc883_auto_init_analog_input(struct hda_codec *codec)
7329 {
7330         struct alc_spec *spec = codec->spec;
7331         int i;
7332
7333         for (i = 0; i < AUTO_PIN_LAST; i++) {
7334                 hda_nid_t nid = spec->autocfg.input_pins[i];
7335                 if (alc883_is_input_pin(nid)) {
7336                         snd_hda_codec_write(codec, nid, 0,
7337                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
7338                                             (i <= AUTO_PIN_FRONT_MIC ?
7339                                              PIN_VREF80 : PIN_IN));
7340                         if (nid != ALC883_PIN_CD_NID)
7341                                 snd_hda_codec_write(codec, nid, 0,
7342                                                     AC_VERB_SET_AMP_GAIN_MUTE,
7343                                                     AMP_OUT_MUTE);
7344                 }
7345         }
7346 }
7347
7348 /* almost identical with ALC880 parser... */
7349 static int alc883_parse_auto_config(struct hda_codec *codec)
7350 {
7351         struct alc_spec *spec = codec->spec;
7352         int err = alc880_parse_auto_config(codec);
7353
7354         if (err < 0)
7355                 return err;
7356         else if (!err)
7357                 return 0; /* no config found */
7358
7359         err = alc_auto_add_mic_boost(codec);
7360         if (err < 0)
7361                 return err;
7362
7363         /* hack - override the init verbs */
7364         spec->init_verbs[0] = alc883_auto_init_verbs;
7365         spec->mixers[spec->num_mixers] = alc883_capture_mixer;
7366         spec->num_mixers++;
7367
7368         return 1; /* config found */
7369 }
7370
7371 /* additional initialization for auto-configuration model */
7372 static void alc883_auto_init(struct hda_codec *codec)
7373 {
7374         alc883_auto_init_multi_out(codec);
7375         alc883_auto_init_hp_out(codec);
7376         alc883_auto_init_analog_input(codec);
7377 }
7378
7379 static int patch_alc883(struct hda_codec *codec)
7380 {
7381         struct alc_spec *spec;
7382         int err, board_config;
7383
7384         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
7385         if (spec == NULL)
7386                 return -ENOMEM;
7387
7388         codec->spec = spec;
7389
7390         board_config = snd_hda_check_board_config(codec, ALC883_MODEL_LAST,
7391                                                   alc883_models,
7392                                                   alc883_cfg_tbl);
7393         if (board_config < 0) {
7394                 printk(KERN_INFO "hda_codec: Unknown model for ALC883, "
7395                        "trying auto-probe from BIOS...\n");
7396                 board_config = ALC883_AUTO;
7397         }
7398
7399         if (board_config == ALC883_AUTO) {
7400                 /* automatic parse from the BIOS config */
7401                 err = alc883_parse_auto_config(codec);
7402                 if (err < 0) {
7403                         alc_free(codec);
7404                         return err;
7405                 } else if (!err) {
7406                         printk(KERN_INFO
7407                                "hda_codec: Cannot set up configuration "
7408                                "from BIOS.  Using base mode...\n");
7409                         board_config = ALC883_3ST_2ch_DIG;
7410                 }
7411         }
7412
7413         if (board_config != ALC883_AUTO)
7414                 setup_preset(spec, &alc883_presets[board_config]);
7415
7416         spec->stream_name_analog = "ALC883 Analog";
7417         spec->stream_analog_playback = &alc883_pcm_analog_playback;
7418         spec->stream_analog_capture = &alc883_pcm_analog_capture;
7419
7420         spec->stream_name_digital = "ALC883 Digital";
7421         spec->stream_digital_playback = &alc883_pcm_digital_playback;
7422         spec->stream_digital_capture = &alc883_pcm_digital_capture;
7423
7424         if (!spec->adc_nids && spec->input_mux) {
7425                 spec->adc_nids = alc883_adc_nids;
7426                 spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
7427         }
7428
7429         codec->patch_ops = alc_patch_ops;
7430         if (board_config == ALC883_AUTO)
7431                 spec->init_hook = alc883_auto_init;
7432 #ifdef CONFIG_SND_HDA_POWER_SAVE
7433         if (!spec->loopback.amplist)
7434                 spec->loopback.amplist = alc883_loopbacks;
7435 #endif
7436
7437         return 0;
7438 }
7439
7440 /*
7441  * ALC262 support
7442  */
7443
7444 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
7445 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
7446
7447 #define alc262_dac_nids         alc260_dac_nids
7448 #define alc262_adc_nids         alc882_adc_nids
7449 #define alc262_adc_nids_alt     alc882_adc_nids_alt
7450
7451 #define alc262_modes            alc260_modes
7452 #define alc262_capture_source   alc882_capture_source
7453
7454 static struct snd_kcontrol_new alc262_base_mixer[] = {
7455         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7456         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7457         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7458         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7459         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7460         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7461         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7462         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7463         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7464         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
7465         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
7466         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7467         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
7468            HDA_CODEC_MUTE("PC Beelp Playback Switch", 0x0b, 0x05, HDA_INPUT), */
7469         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
7470         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7471         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7472         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
7473         { } /* end */
7474 };
7475
7476 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
7477         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7478         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7479         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7480         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7481         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7482         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7483         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7484         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7485         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7486         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
7487         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
7488         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7489         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
7490            HDA_CODEC_MUTE("PC Beelp Playback Switch", 0x0b, 0x05, HDA_INPUT), */
7491         /*HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),*/
7492         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7493         { } /* end */
7494 };
7495
7496 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
7497         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7498         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7499         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7500         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7501         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
7502
7503         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7504         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7505         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7506         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
7507         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
7508         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7509         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7510         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7511         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7512         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7513         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
7514         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
7515         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
7516         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
7517         { } /* end */
7518 };
7519
7520 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
7521         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7522         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7523         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7524         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7525         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7526         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
7527         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
7528         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
7529         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
7530         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
7531         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
7532         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7533         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7534         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
7535         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
7536         { } /* end */
7537 };
7538
7539 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
7540         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7541         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7542         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
7543         { } /* end */
7544 };
7545
7546 /* bind hp and internal speaker mute (with plug check) */
7547 static int alc262_sony_master_sw_put(struct snd_kcontrol *kcontrol,
7548                                      struct snd_ctl_elem_value *ucontrol)
7549 {
7550         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
7551         long *valp = ucontrol->value.integer.value;
7552         int change;
7553
7554         /* change hp mute */
7555         change = snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
7556                                           HDA_AMP_MUTE,
7557                                           valp[0] ? 0 : HDA_AMP_MUTE);
7558         change |= snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
7559                                            HDA_AMP_MUTE,
7560                                            valp[1] ? 0 : HDA_AMP_MUTE);
7561         if (change) {
7562                 /* change speaker according to HP jack state */
7563                 struct alc_spec *spec = codec->spec;
7564                 unsigned int mute;
7565                 if (spec->jack_present)
7566                         mute = HDA_AMP_MUTE;
7567                 else
7568                         mute = snd_hda_codec_amp_read(codec, 0x15, 0,
7569                                                       HDA_OUTPUT, 0);
7570                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7571                                          HDA_AMP_MUTE, mute);
7572         }
7573         return change;
7574 }
7575
7576 static struct snd_kcontrol_new alc262_sony_mixer[] = {
7577         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7578         {
7579                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7580                 .name = "Master Playback Switch",
7581                 .info = snd_hda_mixer_amp_switch_info,
7582                 .get = snd_hda_mixer_amp_switch_get,
7583                 .put = alc262_sony_master_sw_put,
7584                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
7585         },
7586         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7587         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7588         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
7589         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
7590         { } /* end */
7591 };
7592
7593 static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
7594         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7595         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7596         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7597         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7598         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7599         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
7600         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
7601         { } /* end */
7602 };
7603
7604 #define alc262_capture_mixer            alc882_capture_mixer
7605 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
7606
7607 /*
7608  * generic initialization of ADC, input mixers and output mixers
7609  */
7610 static struct hda_verb alc262_init_verbs[] = {
7611         /*
7612          * Unmute ADC0-2 and set the default input to mic-in
7613          */
7614         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
7615         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7616         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7617         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7618         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7619         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7620
7621         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
7622          * mixer widget
7623          * Note: PASD motherboards uses the Line In 2 as the input for
7624          * front panel mic (mic 2)
7625          */
7626         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
7627         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7628         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7629         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7630         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7631         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7632
7633         /*
7634          * Set up output mixers (0x0c - 0x0e)
7635          */
7636         /* set vol=0 to output mixers */
7637         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7638         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7639         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7640         /* set up input amps for analog loopback */
7641         /* Amp Indices: DAC = 0, mixer = 1 */
7642         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7643         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7644         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7645         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7646         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7647         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7648
7649         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
7650         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
7651         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
7652         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
7653         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
7654         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
7655
7656         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
7657         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
7658         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
7659         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
7660         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
7661         
7662         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7663         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7664         
7665         /* FIXME: use matrix-type input source selection */
7666         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7667         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
7668         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7669         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7670         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7671         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7672         /* Input mixer2 */
7673         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7674         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7675         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7676         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7677         /* Input mixer3 */
7678         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7679         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7680         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7681         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7682
7683         { }
7684 };
7685
7686 static struct hda_verb alc262_hippo_unsol_verbs[] = {
7687         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
7688         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7689         {}
7690 };
7691
7692 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
7693         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
7694         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7695         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
7696
7697         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
7698         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7699         {}
7700 };
7701
7702 static struct hda_verb alc262_sony_unsol_verbs[] = {
7703         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
7704         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7705         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
7706
7707         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
7708         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7709 };
7710
7711 /* mute/unmute internal speaker according to the hp jack and mute state */
7712 static void alc262_hippo_automute(struct hda_codec *codec)
7713 {
7714         struct alc_spec *spec = codec->spec;
7715         unsigned int mute;
7716         unsigned int present;
7717
7718         /* need to execute and sync at first */
7719         snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
7720         present = snd_hda_codec_read(codec, 0x15, 0,
7721                                      AC_VERB_GET_PIN_SENSE, 0);
7722         spec->jack_present = (present & 0x80000000) != 0;
7723         if (spec->jack_present) {
7724                 /* mute internal speaker */
7725                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7726                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
7727         } else {
7728                 /* unmute internal speaker if necessary */
7729                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
7730                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7731                                          HDA_AMP_MUTE, mute);
7732         }
7733 }
7734
7735 /* unsolicited event for HP jack sensing */
7736 static void alc262_hippo_unsol_event(struct hda_codec *codec,
7737                                        unsigned int res)
7738 {
7739         if ((res >> 26) != ALC880_HP_EVENT)
7740                 return;
7741         alc262_hippo_automute(codec);
7742 }
7743
7744 static void alc262_hippo1_automute(struct hda_codec *codec)
7745 {
7746         unsigned int mute;
7747         unsigned int present;
7748
7749         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
7750         present = snd_hda_codec_read(codec, 0x1b, 0,
7751                                      AC_VERB_GET_PIN_SENSE, 0);
7752         present = (present & 0x80000000) != 0;
7753         if (present) {
7754                 /* mute internal speaker */
7755                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7756                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
7757         } else {
7758                 /* unmute internal speaker if necessary */
7759                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
7760                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7761                                          HDA_AMP_MUTE, mute);
7762         }
7763 }
7764
7765 /* unsolicited event for HP jack sensing */
7766 static void alc262_hippo1_unsol_event(struct hda_codec *codec,
7767                                        unsigned int res)
7768 {
7769         if ((res >> 26) != ALC880_HP_EVENT)
7770                 return;
7771         alc262_hippo1_automute(codec);
7772 }
7773
7774 /*
7775  * fujitsu model
7776  *  0x14 = headphone/spdif-out, 0x15 = internal speaker
7777  */
7778
7779 #define ALC_HP_EVENT    0x37
7780
7781 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
7782         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
7783         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7784         {}
7785 };
7786
7787 static struct hda_input_mux alc262_fujitsu_capture_source = {
7788         .num_items = 2,
7789         .items = {
7790                 { "Mic", 0x0 },
7791                 { "CD", 0x4 },
7792         },
7793 };
7794
7795 static struct hda_input_mux alc262_HP_capture_source = {
7796         .num_items = 5,
7797         .items = {
7798                 { "Mic", 0x0 },
7799                 { "Front Mic", 0x1 },
7800                 { "Line", 0x2 },
7801                 { "CD", 0x4 },
7802                 { "AUX IN", 0x6 },
7803         },
7804 };
7805
7806 static struct hda_input_mux alc262_HP_D7000_capture_source = {
7807         .num_items = 4,
7808         .items = {
7809                 { "Mic", 0x0 },
7810                 { "Front Mic", 0x2 },
7811                 { "Line", 0x1 },
7812                 { "CD", 0x4 },
7813         },
7814 };
7815
7816 /* mute/unmute internal speaker according to the hp jack and mute state */
7817 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
7818 {
7819         struct alc_spec *spec = codec->spec;
7820         unsigned int mute;
7821
7822         if (force || !spec->sense_updated) {
7823                 unsigned int present;
7824                 /* need to execute and sync at first */
7825                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
7826                 present = snd_hda_codec_read(codec, 0x14, 0,
7827                                          AC_VERB_GET_PIN_SENSE, 0);
7828                 spec->jack_present = (present & 0x80000000) != 0;
7829                 spec->sense_updated = 1;
7830         }
7831         if (spec->jack_present) {
7832                 /* mute internal speaker */
7833                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7834                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
7835         } else {
7836                 /* unmute internal speaker if necessary */
7837                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
7838                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7839                                          HDA_AMP_MUTE, mute);
7840         }
7841 }
7842
7843 /* unsolicited event for HP jack sensing */
7844 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
7845                                        unsigned int res)
7846 {
7847         if ((res >> 26) != ALC_HP_EVENT)
7848                 return;
7849         alc262_fujitsu_automute(codec, 1);
7850 }
7851
7852 /* bind volumes of both NID 0x0c and 0x0d */
7853 static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
7854         .ops = &snd_hda_bind_vol,
7855         .values = {
7856                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
7857                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
7858                 0
7859         },
7860 };
7861
7862 /* bind hp and internal speaker mute (with plug check) */
7863 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
7864                                          struct snd_ctl_elem_value *ucontrol)
7865 {
7866         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
7867         long *valp = ucontrol->value.integer.value;
7868         int change;
7869
7870         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
7871                                           HDA_AMP_MUTE,
7872                                           valp[0] ? 0 : HDA_AMP_MUTE);
7873         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
7874                                            HDA_AMP_MUTE,
7875                                            valp[1] ? 0 : HDA_AMP_MUTE);
7876         if (change)
7877                 alc262_fujitsu_automute(codec, 0);
7878         return change;
7879 }
7880
7881 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
7882         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
7883         {
7884                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7885                 .name = "Master Playback Switch",
7886                 .info = snd_hda_mixer_amp_switch_info,
7887                 .get = snd_hda_mixer_amp_switch_get,
7888                 .put = alc262_fujitsu_master_sw_put,
7889                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
7890         },
7891         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7892         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7893         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7894         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7895         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7896         { } /* end */
7897 };
7898
7899 /* additional init verbs for Benq laptops */
7900 static struct hda_verb alc262_EAPD_verbs[] = {
7901         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7902         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
7903         {}
7904 };
7905
7906 static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
7907         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7908         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
7909
7910         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7911         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
7912         {}
7913 };
7914
7915 /* add playback controls from the parsed DAC table */
7916 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
7917                                              const struct auto_pin_cfg *cfg)
7918 {
7919         hda_nid_t nid;
7920         int err;
7921
7922         spec->multiout.num_dacs = 1;    /* only use one dac */
7923         spec->multiout.dac_nids = spec->private_dac_nids;
7924         spec->multiout.dac_nids[0] = 2;
7925
7926         nid = cfg->line_out_pins[0];
7927         if (nid) {
7928                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
7929                                   "Front Playback Volume",
7930                                   HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT));
7931                 if (err < 0)
7932                         return err;
7933                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
7934                                   "Front Playback Switch",
7935                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
7936                 if (err < 0)
7937                         return err;
7938         }
7939
7940         nid = cfg->speaker_pins[0];
7941         if (nid) {
7942                 if (nid == 0x16) {
7943                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
7944                                           "Speaker Playback Volume",
7945                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
7946                                                               HDA_OUTPUT));
7947                         if (err < 0)
7948                                 return err;
7949                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
7950                                           "Speaker Playback Switch",
7951                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
7952                                                               HDA_OUTPUT));
7953                         if (err < 0)
7954                                 return err;
7955                 } else {
7956                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
7957                                           "Speaker Playback Switch",
7958                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
7959                                                               HDA_OUTPUT));
7960                         if (err < 0)
7961                                 return err;
7962                 }
7963         }
7964         nid = cfg->hp_pins[0];
7965         if (nid) {
7966                 /* spec->multiout.hp_nid = 2; */
7967                 if (nid == 0x16) {
7968                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
7969                                           "Headphone Playback Volume",
7970                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
7971                                                               HDA_OUTPUT));
7972                         if (err < 0)
7973                                 return err;
7974                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
7975                                           "Headphone Playback Switch",
7976                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
7977                                                               HDA_OUTPUT));
7978                         if (err < 0)
7979                                 return err;
7980                 } else {
7981                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
7982                                           "Headphone Playback Switch",
7983                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
7984                                                               HDA_OUTPUT));
7985                         if (err < 0)
7986                                 return err;
7987                 }
7988         }
7989         return 0;
7990 }
7991
7992 /* identical with ALC880 */
7993 #define alc262_auto_create_analog_input_ctls \
7994         alc880_auto_create_analog_input_ctls
7995
7996 /*
7997  * generic initialization of ADC, input mixers and output mixers
7998  */
7999 static struct hda_verb alc262_volume_init_verbs[] = {
8000         /*
8001          * Unmute ADC0-2 and set the default input to mic-in
8002          */
8003         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
8004         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8005         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8006         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8007         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8008         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8009
8010         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8011          * mixer widget
8012          * Note: PASD motherboards uses the Line In 2 as the input for
8013          * front panel mic (mic 2)
8014          */
8015         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8016         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8017         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8018         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8019         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8020         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8021
8022         /*
8023          * Set up output mixers (0x0c - 0x0f)
8024          */
8025         /* set vol=0 to output mixers */
8026         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8027         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8028         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8029         
8030         /* set up input amps for analog loopback */
8031         /* Amp Indices: DAC = 0, mixer = 1 */
8032         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8033         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8034         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8035         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8036         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8037         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8038
8039         /* FIXME: use matrix-type input source selection */
8040         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8041         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
8042         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8043         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8044         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8045         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8046         /* Input mixer2 */
8047         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8048         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8049         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8050         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8051         /* Input mixer3 */
8052         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8053         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8054         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8055         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8056
8057         { }
8058 };
8059
8060 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
8061         /*
8062          * Unmute ADC0-2 and set the default input to mic-in
8063          */
8064         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
8065         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8066         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8067         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8068         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8069         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8070
8071         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8072          * mixer widget
8073          * Note: PASD motherboards uses the Line In 2 as the input for
8074          * front panel mic (mic 2)
8075          */
8076         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8077         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8078         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8079         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8080         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8081         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8082         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
8083         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
8084         
8085         /*
8086          * Set up output mixers (0x0c - 0x0e)
8087          */
8088         /* set vol=0 to output mixers */
8089         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8090         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8091         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8092
8093         /* set up input amps for analog loopback */
8094         /* Amp Indices: DAC = 0, mixer = 1 */
8095         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8096         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8097         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8098         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8099         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8100         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8101
8102         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8103         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8104         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8105
8106         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8107         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8108
8109         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8110         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8111
8112         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8113         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8114         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8115         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8116         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8117
8118         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
8119         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8120         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8121         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
8122         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8123         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8124
8125
8126         /* FIXME: use matrix-type input source selection */
8127         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8128         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
8129         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8130         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
8131         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
8132         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
8133         /* Input mixer2 */
8134         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8135         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
8136         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
8137         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
8138         /* Input mixer3 */
8139         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8140         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
8141         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
8142         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
8143
8144         { }
8145 };
8146
8147 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
8148         /*
8149          * Unmute ADC0-2 and set the default input to mic-in
8150          */
8151         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
8152         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8153         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8154         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8155         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8156         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8157
8158         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8159          * mixer widget
8160          * Note: PASD motherboards uses the Line In 2 as the input for front
8161          * panel mic (mic 2)
8162          */
8163         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8164         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8165         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8166         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8167         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8168         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8169         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
8170         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
8171         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
8172         /*
8173          * Set up output mixers (0x0c - 0x0e)
8174          */
8175         /* set vol=0 to output mixers */
8176         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8177         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8178         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8179
8180         /* set up input amps for analog loopback */
8181         /* Amp Indices: DAC = 0, mixer = 1 */
8182         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8183         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8184         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8185         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8186         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8187         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8188
8189
8190         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
8191         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
8192         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
8193         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
8194         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
8195         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
8196         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
8197
8198         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8199         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8200
8201         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8202         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
8203
8204         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
8205         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8206         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8207         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
8208         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8209         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8210
8211         /* FIXME: use matrix-type input source selection */
8212         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8213         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
8214         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
8215         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
8216         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
8217         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
8218         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
8219         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
8220         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
8221         /* Input mixer2 */
8222         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8223         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8224         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
8225         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
8226         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
8227         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
8228         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
8229         /* Input mixer3 */
8230         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8231         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8232         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
8233         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
8234         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
8235         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
8236         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
8237
8238         { }
8239 };
8240
8241 #ifdef CONFIG_SND_HDA_POWER_SAVE
8242 #define alc262_loopbacks        alc880_loopbacks
8243 #endif
8244
8245 /* pcm configuration: identiacal with ALC880 */
8246 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
8247 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
8248 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
8249 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
8250
8251 /*
8252  * BIOS auto configuration
8253  */
8254 static int alc262_parse_auto_config(struct hda_codec *codec)
8255 {
8256         struct alc_spec *spec = codec->spec;
8257         int err;
8258         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
8259
8260         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
8261                                            alc262_ignore);
8262         if (err < 0)
8263                 return err;
8264         if (!spec->autocfg.line_outs)
8265                 return 0; /* can't find valid BIOS pin config */
8266         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
8267         if (err < 0)
8268                 return err;
8269         err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg);
8270         if (err < 0)
8271                 return err;
8272
8273         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
8274
8275         if (spec->autocfg.dig_out_pin)
8276                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
8277         if (spec->autocfg.dig_in_pin)
8278                 spec->dig_in_nid = ALC262_DIGIN_NID;
8279
8280         if (spec->kctl_alloc)
8281                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
8282
8283         spec->init_verbs[spec->num_init_verbs++] = alc262_volume_init_verbs;
8284         spec->num_mux_defs = 1;
8285         spec->input_mux = &spec->private_imux;
8286
8287         err = alc_auto_add_mic_boost(codec);
8288         if (err < 0)
8289                 return err;
8290
8291         return 1;
8292 }
8293
8294 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
8295 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
8296 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
8297
8298
8299 /* init callback for auto-configuration model -- overriding the default init */
8300 static void alc262_auto_init(struct hda_codec *codec)
8301 {
8302         alc262_auto_init_multi_out(codec);
8303         alc262_auto_init_hp_out(codec);
8304         alc262_auto_init_analog_input(codec);
8305 }
8306
8307 /*
8308  * configuration and preset
8309  */
8310 static const char *alc262_models[ALC262_MODEL_LAST] = {
8311         [ALC262_BASIC]          = "basic",
8312         [ALC262_HIPPO]          = "hippo",
8313         [ALC262_HIPPO_1]        = "hippo_1",
8314         [ALC262_FUJITSU]        = "fujitsu",
8315         [ALC262_HP_BPC]         = "hp-bpc",
8316         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
8317         [ALC262_BENQ_ED8]       = "benq",
8318         [ALC262_BENQ_T31]       = "benq-t31",
8319         [ALC262_SONY_ASSAMD]    = "sony-assamd",
8320         [ALC262_AUTO]           = "auto",
8321 };
8322
8323 static struct snd_pci_quirk alc262_cfg_tbl[] = {
8324         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
8325         SND_PCI_QUIRK(0x103c, 0x12fe, "HP xw9400", ALC262_HP_BPC),
8326         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
8327         SND_PCI_QUIRK(0x103c, 0x12ff, "HP xw4550", ALC262_HP_BPC),
8328         SND_PCI_QUIRK(0x103c, 0x1308, "HP xw4600", ALC262_HP_BPC),
8329         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
8330         SND_PCI_QUIRK(0x103c, 0x1307, "HP xw6600", ALC262_HP_BPC),
8331         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
8332         SND_PCI_QUIRK(0x103c, 0x1306, "HP xw8600", ALC262_HP_BPC),
8333         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
8334         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
8335         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
8336         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
8337         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
8338         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
8339         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
8340         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
8341         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
8342         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
8343         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
8344         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
8345         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
8346         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
8347         SND_PCI_QUIRK(0x104d, 0x9015, "Sony 0x9015", ALC262_SONY_ASSAMD),
8348         SND_PCI_QUIRK(0x104d, 0x900e, "Sony ASSAMD", ALC262_SONY_ASSAMD),
8349         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
8350         {}
8351 };
8352
8353 static struct alc_config_preset alc262_presets[] = {
8354         [ALC262_BASIC] = {
8355                 .mixers = { alc262_base_mixer },
8356                 .init_verbs = { alc262_init_verbs },
8357                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8358                 .dac_nids = alc262_dac_nids,
8359                 .hp_nid = 0x03,
8360                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8361                 .channel_mode = alc262_modes,
8362                 .input_mux = &alc262_capture_source,
8363         },
8364         [ALC262_HIPPO] = {
8365                 .mixers = { alc262_base_mixer },
8366                 .init_verbs = { alc262_init_verbs, alc262_hippo_unsol_verbs},
8367                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8368                 .dac_nids = alc262_dac_nids,
8369                 .hp_nid = 0x03,
8370                 .dig_out_nid = ALC262_DIGOUT_NID,
8371                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8372                 .channel_mode = alc262_modes,
8373                 .input_mux = &alc262_capture_source,
8374                 .unsol_event = alc262_hippo_unsol_event,
8375                 .init_hook = alc262_hippo_automute,
8376         },
8377         [ALC262_HIPPO_1] = {
8378                 .mixers = { alc262_hippo1_mixer },
8379                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
8380                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8381                 .dac_nids = alc262_dac_nids,
8382                 .hp_nid = 0x02,
8383                 .dig_out_nid = ALC262_DIGOUT_NID,
8384                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8385                 .channel_mode = alc262_modes,
8386                 .input_mux = &alc262_capture_source,
8387                 .unsol_event = alc262_hippo1_unsol_event,
8388                 .init_hook = alc262_hippo1_automute,
8389         },
8390         [ALC262_FUJITSU] = {
8391                 .mixers = { alc262_fujitsu_mixer },
8392                 .init_verbs = { alc262_init_verbs, alc262_fujitsu_unsol_verbs },
8393                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8394                 .dac_nids = alc262_dac_nids,
8395                 .hp_nid = 0x03,
8396                 .dig_out_nid = ALC262_DIGOUT_NID,
8397                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8398                 .channel_mode = alc262_modes,
8399                 .input_mux = &alc262_fujitsu_capture_source,
8400                 .unsol_event = alc262_fujitsu_unsol_event,
8401         },
8402         [ALC262_HP_BPC] = {
8403                 .mixers = { alc262_HP_BPC_mixer },
8404                 .init_verbs = { alc262_HP_BPC_init_verbs },
8405                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8406                 .dac_nids = alc262_dac_nids,
8407                 .hp_nid = 0x03,
8408                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8409                 .channel_mode = alc262_modes,
8410                 .input_mux = &alc262_HP_capture_source,
8411         },
8412         [ALC262_HP_BPC_D7000_WF] = {
8413                 .mixers = { alc262_HP_BPC_WildWest_mixer },
8414                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
8415                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8416                 .dac_nids = alc262_dac_nids,
8417                 .hp_nid = 0x03,
8418                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8419                 .channel_mode = alc262_modes,
8420                 .input_mux = &alc262_HP_D7000_capture_source,
8421         },
8422         [ALC262_HP_BPC_D7000_WL] = {
8423                 .mixers = { alc262_HP_BPC_WildWest_mixer,
8424                             alc262_HP_BPC_WildWest_option_mixer },
8425                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
8426                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8427                 .dac_nids = alc262_dac_nids,
8428                 .hp_nid = 0x03,
8429                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8430                 .channel_mode = alc262_modes,
8431                 .input_mux = &alc262_HP_D7000_capture_source,
8432         },
8433         [ALC262_BENQ_ED8] = {
8434                 .mixers = { alc262_base_mixer },
8435                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
8436                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8437                 .dac_nids = alc262_dac_nids,
8438                 .hp_nid = 0x03,
8439                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8440                 .channel_mode = alc262_modes,
8441                 .input_mux = &alc262_capture_source,
8442         },
8443         [ALC262_SONY_ASSAMD] = {
8444                 .mixers = { alc262_sony_mixer },
8445                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
8446                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8447                 .dac_nids = alc262_dac_nids,
8448                 .hp_nid = 0x02,
8449                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8450                 .channel_mode = alc262_modes,
8451                 .input_mux = &alc262_capture_source,
8452                 .unsol_event = alc262_hippo_unsol_event,
8453                 .init_hook = alc262_hippo_automute,
8454         },
8455         [ALC262_BENQ_T31] = {
8456                 .mixers = { alc262_benq_t31_mixer },
8457                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs, alc262_hippo_unsol_verbs },
8458                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8459                 .dac_nids = alc262_dac_nids,
8460                 .hp_nid = 0x03,
8461                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8462                 .channel_mode = alc262_modes,
8463                 .input_mux = &alc262_capture_source,
8464                 .unsol_event = alc262_hippo_unsol_event,
8465                 .init_hook = alc262_hippo_automute,
8466         },      
8467 };
8468
8469 static int patch_alc262(struct hda_codec *codec)
8470 {
8471         struct alc_spec *spec;
8472         int board_config;
8473         int err;
8474
8475         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
8476         if (spec == NULL)
8477                 return -ENOMEM;
8478
8479         codec->spec = spec;
8480 #if 0
8481         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
8482          * under-run
8483          */
8484         {
8485         int tmp;
8486         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
8487         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
8488         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
8489         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
8490         }
8491 #endif
8492
8493         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
8494                                                   alc262_models,
8495                                                   alc262_cfg_tbl);
8496
8497         if (board_config < 0) {
8498                 printk(KERN_INFO "hda_codec: Unknown model for ALC262, "
8499                        "trying auto-probe from BIOS...\n");
8500                 board_config = ALC262_AUTO;
8501         }
8502
8503         if (board_config == ALC262_AUTO) {
8504                 /* automatic parse from the BIOS config */
8505                 err = alc262_parse_auto_config(codec);
8506                 if (err < 0) {
8507                         alc_free(codec);
8508                         return err;
8509                 } else if (!err) {
8510                         printk(KERN_INFO
8511                                "hda_codec: Cannot set up configuration "
8512                                "from BIOS.  Using base mode...\n");
8513                         board_config = ALC262_BASIC;
8514                 }
8515         }
8516
8517         if (board_config != ALC262_AUTO)
8518                 setup_preset(spec, &alc262_presets[board_config]);
8519
8520         spec->stream_name_analog = "ALC262 Analog";
8521         spec->stream_analog_playback = &alc262_pcm_analog_playback;
8522         spec->stream_analog_capture = &alc262_pcm_analog_capture;
8523                 
8524         spec->stream_name_digital = "ALC262 Digital";
8525         spec->stream_digital_playback = &alc262_pcm_digital_playback;
8526         spec->stream_digital_capture = &alc262_pcm_digital_capture;
8527
8528         if (!spec->adc_nids && spec->input_mux) {
8529                 /* check whether NID 0x07 is valid */
8530                 unsigned int wcap = get_wcaps(codec, 0x07);
8531
8532                 /* get type */
8533                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
8534                 if (wcap != AC_WID_AUD_IN) {
8535                         spec->adc_nids = alc262_adc_nids_alt;
8536                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
8537                         spec->mixers[spec->num_mixers] =
8538                                 alc262_capture_alt_mixer;
8539                         spec->num_mixers++;
8540                 } else {
8541                         spec->adc_nids = alc262_adc_nids;
8542                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
8543                         spec->mixers[spec->num_mixers] = alc262_capture_mixer;
8544                         spec->num_mixers++;
8545                 }
8546         }
8547
8548         codec->patch_ops = alc_patch_ops;
8549         if (board_config == ALC262_AUTO)
8550                 spec->init_hook = alc262_auto_init;
8551 #ifdef CONFIG_SND_HDA_POWER_SAVE
8552         if (!spec->loopback.amplist)
8553                 spec->loopback.amplist = alc262_loopbacks;
8554 #endif
8555                 
8556         return 0;
8557 }
8558
8559 /*
8560  *  ALC268 channel source setting (2 channel)
8561  */
8562 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
8563 #define alc268_modes            alc260_modes
8564         
8565 static hda_nid_t alc268_dac_nids[2] = {
8566         /* front, hp */
8567         0x02, 0x03
8568 };
8569
8570 static hda_nid_t alc268_adc_nids[2] = {
8571         /* ADC0-1 */
8572         0x08, 0x07
8573 };
8574
8575 static hda_nid_t alc268_adc_nids_alt[1] = {
8576         /* ADC0 */
8577         0x08
8578 };
8579
8580 static struct snd_kcontrol_new alc268_base_mixer[] = {
8581         /* output mixer control */
8582         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
8583         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8584         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
8585         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8586         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8587         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8588         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
8589         { }
8590 };
8591
8592 static struct hda_verb alc268_eapd_verbs[] = {
8593         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
8594         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
8595         { }
8596 };
8597
8598 /* Toshiba specific */
8599 #define alc268_toshiba_automute alc262_hippo_automute
8600
8601 static struct hda_verb alc268_toshiba_verbs[] = {
8602         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8603         { } /* end */
8604 };
8605
8606 /* Acer specific */
8607 /* bind volumes of both NID 0x02 and 0x03 */
8608 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
8609         .ops = &snd_hda_bind_vol,
8610         .values = {
8611                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
8612                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
8613                 0
8614         },
8615 };
8616
8617 /* mute/unmute internal speaker according to the hp jack and mute state */
8618 static void alc268_acer_automute(struct hda_codec *codec, int force)
8619 {
8620         struct alc_spec *spec = codec->spec;
8621         unsigned int mute;
8622
8623         if (force || !spec->sense_updated) {
8624                 unsigned int present;
8625                 present = snd_hda_codec_read(codec, 0x14, 0,
8626                                          AC_VERB_GET_PIN_SENSE, 0);
8627                 spec->jack_present = (present & 0x80000000) != 0;
8628                 spec->sense_updated = 1;
8629         }
8630         if (spec->jack_present)
8631                 mute = HDA_AMP_MUTE; /* mute internal speaker */
8632         else /* unmute internal speaker if necessary */
8633                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
8634         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8635                                  HDA_AMP_MUTE, mute);
8636 }
8637
8638
8639 /* bind hp and internal speaker mute (with plug check) */
8640 static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
8641                                      struct snd_ctl_elem_value *ucontrol)
8642 {
8643         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8644         long *valp = ucontrol->value.integer.value;
8645         int change;
8646
8647         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
8648                                           HDA_AMP_MUTE,
8649                                           valp[0] ? 0 : HDA_AMP_MUTE);
8650         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
8651                                            HDA_AMP_MUTE,
8652                                            valp[1] ? 0 : HDA_AMP_MUTE);
8653         if (change)
8654                 alc268_acer_automute(codec, 0);
8655         return change;
8656 }
8657
8658 static struct snd_kcontrol_new alc268_acer_mixer[] = {
8659         /* output mixer control */
8660         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
8661         {
8662                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8663                 .name = "Master Playback Switch",
8664                 .info = snd_hda_mixer_amp_switch_info,
8665                 .get = snd_hda_mixer_amp_switch_get,
8666                 .put = alc268_acer_master_sw_put,
8667                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
8668         },
8669         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8670         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
8671         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
8672         { }
8673 };
8674
8675 static struct hda_verb alc268_acer_verbs[] = {
8676         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8677         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8678
8679         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8680         { }
8681 };
8682
8683 /* unsolicited event for HP jack sensing */
8684 static void alc268_toshiba_unsol_event(struct hda_codec *codec,
8685                                        unsigned int res)
8686 {
8687         if ((res >> 26) != ALC880_HP_EVENT)
8688                 return;
8689         alc268_toshiba_automute(codec);
8690 }
8691
8692 static void alc268_acer_unsol_event(struct hda_codec *codec,
8693                                        unsigned int res)
8694 {
8695         if ((res >> 26) != ALC880_HP_EVENT)
8696                 return;
8697         alc268_acer_automute(codec, 1);
8698 }
8699
8700 static void alc268_acer_init_hook(struct hda_codec *codec)
8701 {
8702         alc268_acer_automute(codec, 1);
8703 }
8704
8705 /*
8706  * generic initialization of ADC, input mixers and output mixers
8707  */
8708 static struct hda_verb alc268_base_init_verbs[] = {
8709         /* Unmute DAC0-1 and set vol = 0 */
8710         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8711         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8712         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8713         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8714         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8715         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8716
8717         /*
8718          * Set up output mixers (0x0c - 0x0e)
8719          */
8720         /* set vol=0 to output mixers */
8721         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8722         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8723         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8724         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
8725
8726         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8727         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8728
8729         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
8730         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8731         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
8732         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8733         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8734         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8735         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8736         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8737
8738         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8739         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8740         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8741         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8742         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8743         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8744         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8745         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8746
8747         /* FIXME: use matrix-type input source selection */
8748         /* Mixer elements: 0x18, 19, 1a, 1c, 14, 15, 0b */
8749         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
8750         /* Input mixer2 */
8751         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8752         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8753         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
8754         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
8755
8756         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8757         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8758         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
8759         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
8760         { }
8761 };
8762
8763 /*
8764  * generic initialization of ADC, input mixers and output mixers
8765  */
8766 static struct hda_verb alc268_volume_init_verbs[] = {
8767         /* set output DAC */
8768         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8769         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8770         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8771         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8772
8773         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8774         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8775         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8776         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8777         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8778
8779         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8780         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8781         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8782         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8783         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8784
8785         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8786         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8787         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8788         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8789
8790         /* set PCBEEP vol = 0 */
8791         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, (0xb000 | (0x00 << 8))},
8792
8793         { }
8794 };
8795
8796 #define alc268_mux_enum_info alc_mux_enum_info
8797 #define alc268_mux_enum_get alc_mux_enum_get
8798
8799 static int alc268_mux_enum_put(struct snd_kcontrol *kcontrol,
8800                                struct snd_ctl_elem_value *ucontrol)
8801 {
8802         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8803         struct alc_spec *spec = codec->spec;
8804         const struct hda_input_mux *imux = spec->input_mux;
8805         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
8806         static hda_nid_t capture_mixers[3] = { 0x23, 0x24 };
8807         hda_nid_t nid = capture_mixers[adc_idx];
8808         unsigned int *cur_val = &spec->cur_mux[adc_idx];
8809         unsigned int i, idx;
8810
8811         idx = ucontrol->value.enumerated.item[0];
8812         if (idx >= imux->num_items)
8813                 idx = imux->num_items - 1;
8814         if (*cur_val == idx)
8815                 return 0;
8816         for (i = 0; i < imux->num_items; i++) {
8817                 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
8818                 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
8819                                          imux->items[i].index,
8820                                          HDA_AMP_MUTE, v);
8821                 snd_hda_codec_write_cache(codec, nid, 0,
8822                                           AC_VERB_SET_CONNECT_SEL,
8823                                           idx );
8824         }
8825         *cur_val = idx;
8826         return 1;
8827 }
8828
8829 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
8830         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
8831         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
8832         {
8833                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8834                 /* The multiple "Capture Source" controls confuse alsamixer
8835                  * So call somewhat different..
8836                  * FIXME: the controls appear in the "playback" view!
8837                  */
8838                 /* .name = "Capture Source", */
8839                 .name = "Input Source",
8840                 .count = 1,
8841                 .info = alc268_mux_enum_info,
8842                 .get = alc268_mux_enum_get,
8843                 .put = alc268_mux_enum_put,
8844         },
8845         { } /* end */
8846 };
8847
8848 static struct snd_kcontrol_new alc268_capture_mixer[] = {
8849         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
8850         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
8851         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
8852         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
8853         {
8854                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8855                 /* The multiple "Capture Source" controls confuse alsamixer
8856                  * So call somewhat different..
8857                  * FIXME: the controls appear in the "playback" view!
8858                  */
8859                 /* .name = "Capture Source", */
8860                 .name = "Input Source",
8861                 .count = 2,
8862                 .info = alc268_mux_enum_info,
8863                 .get = alc268_mux_enum_get,
8864                 .put = alc268_mux_enum_put,
8865         },
8866         { } /* end */
8867 };
8868
8869 static struct hda_input_mux alc268_capture_source = {
8870         .num_items = 4,
8871         .items = {
8872                 { "Mic", 0x0 },
8873                 { "Front Mic", 0x1 },
8874                 { "Line", 0x2 },
8875                 { "CD", 0x3 },
8876         },
8877 };
8878
8879 /* create input playback/capture controls for the given pin */
8880 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
8881                                     const char *ctlname, int idx)
8882 {
8883         char name[32];
8884         int err;
8885
8886         sprintf(name, "%s Playback Volume", ctlname);
8887         if (nid == 0x14) {
8888                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
8889                                   HDA_COMPOSE_AMP_VAL(0x02, 3, idx,
8890                                                       HDA_OUTPUT));
8891                 if (err < 0)
8892                         return err;
8893         } else if (nid == 0x15) {
8894                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
8895                                   HDA_COMPOSE_AMP_VAL(0x03, 3, idx,
8896                                                       HDA_OUTPUT));
8897                 if (err < 0)
8898                         return err;
8899         } else
8900                 return -1;
8901         sprintf(name, "%s Playback Switch", ctlname);
8902         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
8903                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
8904         if (err < 0)
8905                 return err;
8906         return 0;
8907 }
8908
8909 /* add playback controls from the parsed DAC table */
8910 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
8911                                              const struct auto_pin_cfg *cfg)
8912 {
8913         hda_nid_t nid;
8914         int err;
8915
8916         spec->multiout.num_dacs = 2;    /* only use one dac */
8917         spec->multiout.dac_nids = spec->private_dac_nids;
8918         spec->multiout.dac_nids[0] = 2;
8919         spec->multiout.dac_nids[1] = 3;
8920
8921         nid = cfg->line_out_pins[0];
8922         if (nid)
8923                 alc268_new_analog_output(spec, nid, "Front", 0);        
8924
8925         nid = cfg->speaker_pins[0];
8926         if (nid == 0x1d) {
8927                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
8928                                   "Speaker Playback Volume",
8929                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
8930                 if (err < 0)
8931                         return err;
8932         }
8933         nid = cfg->hp_pins[0];
8934         if (nid)
8935                 alc268_new_analog_output(spec, nid, "Headphone", 0);
8936
8937         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
8938         if (nid == 0x16) {
8939                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
8940                                   "Mono Playback Switch",
8941                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_INPUT));
8942                 if (err < 0)
8943                         return err;
8944         }
8945         return 0;       
8946 }
8947
8948 /* create playback/capture controls for input pins */
8949 static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
8950                                                 const struct auto_pin_cfg *cfg)
8951 {
8952         struct hda_input_mux *imux = &spec->private_imux;
8953         int i, idx1;
8954
8955         for (i = 0; i < AUTO_PIN_LAST; i++) {
8956                 switch(cfg->input_pins[i]) {
8957                 case 0x18:
8958                         idx1 = 0;       /* Mic 1 */
8959                         break;
8960                 case 0x19:
8961                         idx1 = 1;       /* Mic 2 */
8962                         break;
8963                 case 0x1a:
8964                         idx1 = 2;       /* Line In */
8965                         break;
8966                 case 0x1c:      
8967                         idx1 = 3;       /* CD */
8968                         break;
8969                 default:
8970                         continue;
8971                 }
8972                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
8973                 imux->items[imux->num_items].index = idx1;
8974                 imux->num_items++;      
8975         }
8976         return 0;
8977 }
8978
8979 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
8980 {
8981         struct alc_spec *spec = codec->spec;
8982         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
8983         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
8984         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
8985         unsigned int    dac_vol1, dac_vol2;
8986
8987         if (speaker_nid) {
8988                 snd_hda_codec_write(codec, speaker_nid, 0,
8989                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
8990                 snd_hda_codec_write(codec, 0x0f, 0,
8991                                     AC_VERB_SET_AMP_GAIN_MUTE,
8992                                     AMP_IN_UNMUTE(1));
8993                 snd_hda_codec_write(codec, 0x10, 0,
8994                                     AC_VERB_SET_AMP_GAIN_MUTE,
8995                                     AMP_IN_UNMUTE(1));
8996         } else {
8997                 snd_hda_codec_write(codec, 0x0f, 0,
8998                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
8999                 snd_hda_codec_write(codec, 0x10, 0,
9000                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
9001         }
9002
9003         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
9004         if (line_nid == 0x14)   
9005                 dac_vol2 = AMP_OUT_ZERO;
9006         else if (line_nid == 0x15)
9007                 dac_vol1 = AMP_OUT_ZERO;
9008         if (hp_nid == 0x14)     
9009                 dac_vol2 = AMP_OUT_ZERO;
9010         else if (hp_nid == 0x15)
9011                 dac_vol1 = AMP_OUT_ZERO;
9012         if (line_nid != 0x16 || hp_nid != 0x16 ||
9013             spec->autocfg.line_out_pins[1] != 0x16 ||
9014             spec->autocfg.line_out_pins[2] != 0x16)
9015                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
9016
9017         snd_hda_codec_write(codec, 0x02, 0,
9018                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
9019         snd_hda_codec_write(codec, 0x03, 0,
9020                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
9021 }
9022
9023 /* pcm configuration: identiacal with ALC880 */
9024 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
9025 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
9026 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
9027
9028 /*
9029  * BIOS auto configuration
9030  */
9031 static int alc268_parse_auto_config(struct hda_codec *codec)
9032 {
9033         struct alc_spec *spec = codec->spec;
9034         int err;
9035         static hda_nid_t alc268_ignore[] = { 0 };
9036
9037         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
9038                                            alc268_ignore);
9039         if (err < 0)
9040                 return err;
9041         if (!spec->autocfg.line_outs)
9042                 return 0; /* can't find valid BIOS pin config */
9043
9044         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
9045         if (err < 0)
9046                 return err;
9047         err = alc268_auto_create_analog_input_ctls(spec, &spec->autocfg);
9048         if (err < 0)
9049                 return err;
9050
9051         spec->multiout.max_channels = 2;
9052
9053         /* digital only support output */
9054         if (spec->autocfg.dig_out_pin)
9055                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
9056
9057         if (spec->kctl_alloc)
9058                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
9059
9060         spec->init_verbs[spec->num_init_verbs++] = alc268_volume_init_verbs;
9061         spec->num_mux_defs = 1;
9062         spec->input_mux = &spec->private_imux;
9063
9064         err = alc_auto_add_mic_boost(codec);
9065         if (err < 0)
9066                 return err;
9067
9068         return 1;
9069 }
9070
9071 #define alc268_auto_init_multi_out      alc882_auto_init_multi_out
9072 #define alc268_auto_init_hp_out         alc882_auto_init_hp_out
9073 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
9074
9075 /* init callback for auto-configuration model -- overriding the default init */
9076 static void alc268_auto_init(struct hda_codec *codec)
9077 {
9078         alc268_auto_init_multi_out(codec);
9079         alc268_auto_init_hp_out(codec);
9080         alc268_auto_init_mono_speaker_out(codec);
9081         alc268_auto_init_analog_input(codec);
9082 }
9083
9084 /*
9085  * configuration and preset
9086  */
9087 static const char *alc268_models[ALC268_MODEL_LAST] = {
9088         [ALC268_3ST]            = "3stack",
9089         [ALC268_TOSHIBA]        = "toshiba",
9090         [ALC268_ACER]           = "acer",
9091         [ALC268_AUTO]           = "auto",
9092 };
9093
9094 static struct snd_pci_quirk alc268_cfg_tbl[] = {
9095         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
9096         SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA),
9097         SND_PCI_QUIRK(0x103c, 0x30cc, "TOSHIBA", ALC268_TOSHIBA),
9098         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
9099         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
9100         {}
9101 };
9102
9103 static struct alc_config_preset alc268_presets[] = {
9104         [ALC268_3ST] = {
9105                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer },
9106                 .init_verbs = { alc268_base_init_verbs },
9107                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
9108                 .dac_nids = alc268_dac_nids,
9109                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
9110                 .adc_nids = alc268_adc_nids_alt,
9111                 .hp_nid = 0x03,
9112                 .dig_out_nid = ALC268_DIGOUT_NID,
9113                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
9114                 .channel_mode = alc268_modes,
9115                 .input_mux = &alc268_capture_source,
9116         },
9117         [ALC268_TOSHIBA] = {
9118                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer },
9119                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
9120                                 alc268_toshiba_verbs },
9121                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
9122                 .dac_nids = alc268_dac_nids,
9123                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
9124                 .adc_nids = alc268_adc_nids_alt,
9125                 .hp_nid = 0x03,
9126                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
9127                 .channel_mode = alc268_modes,
9128                 .input_mux = &alc268_capture_source,
9129                 .input_mux = &alc268_capture_source,
9130                 .unsol_event = alc268_toshiba_unsol_event,
9131                 .init_hook = alc268_toshiba_automute,
9132         },
9133         [ALC268_ACER] = {
9134                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer },
9135                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
9136                                 alc268_acer_verbs },
9137                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
9138                 .dac_nids = alc268_dac_nids,
9139                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
9140                 .adc_nids = alc268_adc_nids_alt,
9141                 .hp_nid = 0x02,
9142                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
9143                 .channel_mode = alc268_modes,
9144                 .input_mux = &alc268_capture_source,
9145                 .unsol_event = alc268_acer_unsol_event,
9146                 .init_hook = alc268_acer_init_hook,
9147         },
9148 };
9149
9150 static int patch_alc268(struct hda_codec *codec)
9151 {
9152         struct alc_spec *spec;
9153         int board_config;
9154         int err;
9155
9156         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
9157         if (spec == NULL)
9158                 return -ENOMEM;
9159
9160         codec->spec = spec;
9161
9162         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
9163                                                   alc268_models,
9164                                                   alc268_cfg_tbl);
9165
9166         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
9167                 printk(KERN_INFO "hda_codec: Unknown model for ALC268, "
9168                        "trying auto-probe from BIOS...\n");
9169                 board_config = ALC268_AUTO;
9170         }
9171
9172         if (board_config == ALC268_AUTO) {
9173                 /* automatic parse from the BIOS config */
9174                 err = alc268_parse_auto_config(codec);
9175                 if (err < 0) {
9176                         alc_free(codec);
9177                         return err;
9178                 } else if (!err) {
9179                         printk(KERN_INFO
9180                                "hda_codec: Cannot set up configuration "
9181                                "from BIOS.  Using base mode...\n");
9182                         board_config = ALC268_3ST;
9183                 }
9184         }
9185
9186         if (board_config != ALC268_AUTO)
9187                 setup_preset(spec, &alc268_presets[board_config]);
9188
9189         spec->stream_name_analog = "ALC268 Analog";
9190         spec->stream_analog_playback = &alc268_pcm_analog_playback;
9191         spec->stream_analog_capture = &alc268_pcm_analog_capture;
9192
9193         spec->stream_name_digital = "ALC268 Digital";
9194         spec->stream_digital_playback = &alc268_pcm_digital_playback;
9195
9196         if (board_config == ALC268_AUTO) {
9197                 if (!spec->adc_nids && spec->input_mux) {
9198                         /* check whether NID 0x07 is valid */
9199                         unsigned int wcap = get_wcaps(codec, 0x07);
9200
9201                         /* get type */
9202                         wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
9203                         if (wcap != AC_WID_AUD_IN) {
9204                                 spec->adc_nids = alc268_adc_nids_alt;
9205                                 spec->num_adc_nids =
9206                                         ARRAY_SIZE(alc268_adc_nids_alt);
9207                                 spec->mixers[spec->num_mixers] =
9208                                         alc268_capture_alt_mixer;
9209                                 spec->num_mixers++;
9210                         } else {
9211                                 spec->adc_nids = alc268_adc_nids;
9212                                 spec->num_adc_nids =
9213                                         ARRAY_SIZE(alc268_adc_nids);
9214                                 spec->mixers[spec->num_mixers] =
9215                                         alc268_capture_mixer;
9216                                 spec->num_mixers++;
9217                         }
9218                 }
9219         }
9220         codec->patch_ops = alc_patch_ops;
9221         if (board_config == ALC268_AUTO)
9222                 spec->init_hook = alc268_auto_init;
9223                 
9224         return 0;
9225 }
9226
9227 /*
9228  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
9229  */
9230
9231 /*
9232  * set the path ways for 2 channel output
9233  * need to set the codec line out and mic 1 pin widgets to inputs
9234  */
9235 static struct hda_verb alc861_threestack_ch2_init[] = {
9236         /* set pin widget 1Ah (line in) for input */
9237         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
9238         /* set pin widget 18h (mic1/2) for input, for mic also enable
9239          * the vref
9240          */
9241         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9242
9243         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
9244 #if 0
9245         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
9246         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
9247 #endif
9248         { } /* end */
9249 };
9250 /*
9251  * 6ch mode
9252  * need to set the codec line out and mic 1 pin widgets to outputs
9253  */
9254 static struct hda_verb alc861_threestack_ch6_init[] = {
9255         /* set pin widget 1Ah (line in) for output (Back Surround)*/
9256         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9257         /* set pin widget 18h (mic1) for output (CLFE)*/
9258         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9259
9260         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
9261         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
9262
9263         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
9264 #if 0
9265         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
9266         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
9267 #endif
9268         { } /* end */
9269 };
9270
9271 static struct hda_channel_mode alc861_threestack_modes[2] = {
9272         { 2, alc861_threestack_ch2_init },
9273         { 6, alc861_threestack_ch6_init },
9274 };
9275 /* Set mic1 as input and unmute the mixer */
9276 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
9277         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9278         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
9279         { } /* end */
9280 };
9281 /* Set mic1 as output and mute mixer */
9282 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
9283         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9284         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
9285         { } /* end */
9286 };
9287
9288 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
9289         { 2, alc861_uniwill_m31_ch2_init },
9290         { 4, alc861_uniwill_m31_ch4_init },
9291 };
9292
9293 /* Set mic1 and line-in as input and unmute the mixer */
9294 static struct hda_verb alc861_asus_ch2_init[] = {
9295         /* set pin widget 1Ah (line in) for input */
9296         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
9297         /* set pin widget 18h (mic1/2) for input, for mic also enable
9298          * the vref
9299          */
9300         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9301
9302         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
9303 #if 0
9304         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
9305         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
9306 #endif
9307         { } /* end */
9308 };
9309 /* Set mic1 nad line-in as output and mute mixer */
9310 static struct hda_verb alc861_asus_ch6_init[] = {
9311         /* set pin widget 1Ah (line in) for output (Back Surround)*/
9312         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9313         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
9314         /* set pin widget 18h (mic1) for output (CLFE)*/
9315         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9316         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
9317         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
9318         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
9319
9320         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
9321 #if 0
9322         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
9323         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
9324 #endif
9325         { } /* end */
9326 };
9327
9328 static struct hda_channel_mode alc861_asus_modes[2] = {
9329         { 2, alc861_asus_ch2_init },
9330         { 6, alc861_asus_ch6_init },
9331 };
9332
9333 /* patch-ALC861 */
9334
9335 static struct snd_kcontrol_new alc861_base_mixer[] = {
9336         /* output mixer control */
9337         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
9338         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
9339         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
9340         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
9341         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
9342
9343         /*Input mixer control */
9344         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
9345            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
9346         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
9347         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
9348         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
9349         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
9350         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
9351         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
9352         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
9353         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
9354
9355         /* Capture mixer control */
9356         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
9357         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
9358         {
9359                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9360                 .name = "Capture Source",
9361                 .count = 1,
9362                 .info = alc_mux_enum_info,
9363                 .get = alc_mux_enum_get,
9364                 .put = alc_mux_enum_put,
9365         },
9366         { } /* end */
9367 };
9368
9369 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
9370         /* output mixer control */
9371         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
9372         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
9373         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
9374         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
9375         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
9376
9377         /* Input mixer control */
9378         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
9379            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
9380         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
9381         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
9382         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
9383         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
9384         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
9385         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
9386         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
9387         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
9388
9389         /* Capture mixer control */
9390         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
9391         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
9392         {
9393                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9394                 .name = "Capture Source",
9395                 .count = 1,
9396                 .info = alc_mux_enum_info,
9397                 .get = alc_mux_enum_get,
9398                 .put = alc_mux_enum_put,
9399         },
9400         {
9401                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9402                 .name = "Channel Mode",
9403                 .info = alc_ch_mode_info,
9404                 .get = alc_ch_mode_get,
9405                 .put = alc_ch_mode_put,
9406                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
9407         },
9408         { } /* end */
9409 };
9410
9411 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
9412         /* output mixer control */
9413         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
9414         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
9415         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
9416         
9417         /*Capture mixer control */
9418         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
9419         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
9420         {
9421                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9422                 .name = "Capture Source",
9423                 .count = 1,
9424                 .info = alc_mux_enum_info,
9425                 .get = alc_mux_enum_get,
9426                 .put = alc_mux_enum_put,
9427         },
9428
9429         { } /* end */
9430 };
9431
9432 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
9433         /* output mixer control */
9434         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
9435         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
9436         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
9437         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
9438         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
9439
9440         /* Input mixer control */
9441         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
9442            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
9443         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
9444         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
9445         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
9446         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
9447         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
9448         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
9449         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
9450         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
9451
9452         /* Capture mixer control */
9453         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
9454         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
9455         {
9456                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9457                 .name = "Capture Source",
9458                 .count = 1,
9459                 .info = alc_mux_enum_info,
9460                 .get = alc_mux_enum_get,
9461                 .put = alc_mux_enum_put,
9462         },
9463         {
9464                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9465                 .name = "Channel Mode",
9466                 .info = alc_ch_mode_info,
9467                 .get = alc_ch_mode_get,
9468                 .put = alc_ch_mode_put,
9469                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
9470         },
9471         { } /* end */
9472 };
9473
9474 static struct snd_kcontrol_new alc861_asus_mixer[] = {
9475         /* output mixer control */
9476         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
9477         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
9478         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
9479         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
9480         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
9481
9482         /* Input mixer control */
9483         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
9484         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9485         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
9486         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
9487         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
9488         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
9489         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
9490         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
9491         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
9492         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
9493
9494         /* Capture mixer control */
9495         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
9496         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
9497         {
9498                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9499                 .name = "Capture Source",
9500                 .count = 1,
9501                 .info = alc_mux_enum_info,
9502                 .get = alc_mux_enum_get,
9503                 .put = alc_mux_enum_put,
9504         },
9505         {
9506                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9507                 .name = "Channel Mode",
9508                 .info = alc_ch_mode_info,
9509                 .get = alc_ch_mode_get,
9510                 .put = alc_ch_mode_put,
9511                 .private_value = ARRAY_SIZE(alc861_asus_modes),
9512         },
9513         { }
9514 };
9515
9516 /* additional mixer */
9517 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
9518         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
9519         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
9520         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x23, 0x0, HDA_OUTPUT),
9521         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x23, 0x0, HDA_OUTPUT),
9522         { }
9523 };
9524
9525 /*
9526  * generic initialization of ADC, input mixers and output mixers
9527  */
9528 static struct hda_verb alc861_base_init_verbs[] = {
9529         /*
9530          * Unmute ADC0 and set the default input to mic-in
9531          */
9532         /* port-A for surround (rear panel) */
9533         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9534         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
9535         /* port-B for mic-in (rear panel) with vref */
9536         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9537         /* port-C for line-in (rear panel) */
9538         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
9539         /* port-D for Front */
9540         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9541         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
9542         /* port-E for HP out (front panel) */
9543         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
9544         /* route front PCM to HP */
9545         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
9546         /* port-F for mic-in (front panel) with vref */
9547         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9548         /* port-G for CLFE (rear panel) */
9549         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9550         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
9551         /* port-H for side (rear panel) */
9552         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9553         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
9554         /* CD-in */
9555         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
9556         /* route front mic to ADC1*/
9557         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9558         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9559         
9560         /* Unmute DAC0~3 & spdif out*/
9561         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9562         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9563         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9564         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9565         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9566         
9567         /* Unmute Mixer 14 (mic) 1c (Line in)*/
9568         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9569         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9570         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9571         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9572         
9573         /* Unmute Stereo Mixer 15 */
9574         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9575         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9576         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9577         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
9578
9579         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9580         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9581         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9582         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9583         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9584         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9585         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9586         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9587         /* hp used DAC 3 (Front) */
9588         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
9589         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9590
9591         { }
9592 };
9593
9594 static struct hda_verb alc861_threestack_init_verbs[] = {
9595         /*
9596          * Unmute ADC0 and set the default input to mic-in
9597          */
9598         /* port-A for surround (rear panel) */
9599         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
9600         /* port-B for mic-in (rear panel) with vref */
9601         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9602         /* port-C for line-in (rear panel) */
9603         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
9604         /* port-D for Front */
9605         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9606         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
9607         /* port-E for HP out (front panel) */
9608         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
9609         /* route front PCM to HP */
9610         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
9611         /* port-F for mic-in (front panel) with vref */
9612         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9613         /* port-G for CLFE (rear panel) */
9614         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
9615         /* port-H for side (rear panel) */
9616         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
9617         /* CD-in */
9618         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
9619         /* route front mic to ADC1*/
9620         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9621         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9622         /* Unmute DAC0~3 & spdif out*/
9623         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9624         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9625         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9626         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9627         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9628         
9629         /* Unmute Mixer 14 (mic) 1c (Line in)*/
9630         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9631         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9632         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9633         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9634         
9635         /* Unmute Stereo Mixer 15 */
9636         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9637         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9638         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9639         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
9640
9641         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9642         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9643         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9644         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9645         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9646         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9647         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9648         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9649         /* hp used DAC 3 (Front) */
9650         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
9651         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9652         { }
9653 };
9654
9655 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
9656         /*
9657          * Unmute ADC0 and set the default input to mic-in
9658          */
9659         /* port-A for surround (rear panel) */
9660         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
9661         /* port-B for mic-in (rear panel) with vref */
9662         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9663         /* port-C for line-in (rear panel) */
9664         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
9665         /* port-D for Front */
9666         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9667         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
9668         /* port-E for HP out (front panel) */
9669         /* this has to be set to VREF80 */
9670         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9671         /* route front PCM to HP */
9672         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
9673         /* port-F for mic-in (front panel) with vref */
9674         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9675         /* port-G for CLFE (rear panel) */
9676         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
9677         /* port-H for side (rear panel) */
9678         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
9679         /* CD-in */
9680         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
9681         /* route front mic to ADC1*/
9682         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9683         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9684         /* Unmute DAC0~3 & spdif out*/
9685         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9686         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9687         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9688         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9689         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9690         
9691         /* Unmute Mixer 14 (mic) 1c (Line in)*/
9692         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9693         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9694         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9695         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9696         
9697         /* Unmute Stereo Mixer 15 */
9698         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9699         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9700         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9701         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
9702
9703         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9704         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9705         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9706         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9707         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9708         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9709         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9710         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9711         /* hp used DAC 3 (Front) */
9712         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
9713         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9714         { }
9715 };
9716
9717 static struct hda_verb alc861_asus_init_verbs[] = {
9718         /*
9719          * Unmute ADC0 and set the default input to mic-in
9720          */
9721         /* port-A for surround (rear panel)
9722          * according to codec#0 this is the HP jack
9723          */
9724         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
9725         /* route front PCM to HP */
9726         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
9727         /* port-B for mic-in (rear panel) with vref */
9728         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9729         /* port-C for line-in (rear panel) */
9730         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
9731         /* port-D for Front */
9732         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9733         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
9734         /* port-E for HP out (front panel) */
9735         /* this has to be set to VREF80 */
9736         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9737         /* route front PCM to HP */
9738         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
9739         /* port-F for mic-in (front panel) with vref */
9740         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9741         /* port-G for CLFE (rear panel) */
9742         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9743         /* port-H for side (rear panel) */
9744         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9745         /* CD-in */
9746         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
9747         /* route front mic to ADC1*/
9748         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9749         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9750         /* Unmute DAC0~3 & spdif out*/
9751         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9752         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9753         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9754         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9755         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9756         /* Unmute Mixer 14 (mic) 1c (Line in)*/
9757         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9758         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9759         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9760         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9761         
9762         /* Unmute Stereo Mixer 15 */
9763         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9764         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9765         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9766         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
9767
9768         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9769         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9770         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9771         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9772         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9773         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9774         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9775         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9776         /* hp used DAC 3 (Front) */
9777         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
9778         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9779         { }
9780 };
9781
9782 /* additional init verbs for ASUS laptops */
9783 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
9784         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
9785         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
9786         { }
9787 };
9788
9789 /*
9790  * generic initialization of ADC, input mixers and output mixers
9791  */
9792 static struct hda_verb alc861_auto_init_verbs[] = {
9793         /*
9794          * Unmute ADC0 and set the default input to mic-in
9795          */
9796         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
9797         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9798         
9799         /* Unmute DAC0~3 & spdif out*/
9800         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9801         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9802         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9803         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9804         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9805         
9806         /* Unmute Mixer 14 (mic) 1c (Line in)*/
9807         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9808         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9809         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9810         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9811         
9812         /* Unmute Stereo Mixer 15 */
9813         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9814         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9815         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9816         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
9817
9818         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9819         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9820         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9821         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9822         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9823         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9824         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9825         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9826
9827         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9828         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9829         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9830         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
9831         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9832         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9833         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9834         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
9835
9836         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
9837
9838         { }
9839 };
9840
9841 static struct hda_verb alc861_toshiba_init_verbs[] = {
9842         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9843
9844         { }
9845 };
9846
9847 /* toggle speaker-output according to the hp-jack state */
9848 static void alc861_toshiba_automute(struct hda_codec *codec)
9849 {
9850         unsigned int present;
9851
9852         present = snd_hda_codec_read(codec, 0x0f, 0,
9853                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9854         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
9855                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
9856         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
9857                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
9858 }
9859
9860 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
9861                                        unsigned int res)
9862 {
9863         if ((res >> 26) == ALC880_HP_EVENT)
9864                 alc861_toshiba_automute(codec);
9865 }
9866
9867 /* pcm configuration: identiacal with ALC880 */
9868 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
9869 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
9870 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
9871 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
9872
9873
9874 #define ALC861_DIGOUT_NID       0x07
9875
9876 static struct hda_channel_mode alc861_8ch_modes[1] = {
9877         { 8, NULL }
9878 };
9879
9880 static hda_nid_t alc861_dac_nids[4] = {
9881         /* front, surround, clfe, side */
9882         0x03, 0x06, 0x05, 0x04
9883 };
9884
9885 static hda_nid_t alc660_dac_nids[3] = {
9886         /* front, clfe, surround */
9887         0x03, 0x05, 0x06
9888 };
9889
9890 static hda_nid_t alc861_adc_nids[1] = {
9891         /* ADC0-2 */
9892         0x08,
9893 };
9894
9895 static struct hda_input_mux alc861_capture_source = {
9896         .num_items = 5,
9897         .items = {
9898                 { "Mic", 0x0 },
9899                 { "Front Mic", 0x3 },
9900                 { "Line", 0x1 },
9901                 { "CD", 0x4 },
9902                 { "Mixer", 0x5 },
9903         },
9904 };
9905
9906 /* fill in the dac_nids table from the parsed pin configuration */
9907 static int alc861_auto_fill_dac_nids(struct alc_spec *spec,
9908                                      const struct auto_pin_cfg *cfg)
9909 {
9910         int i;
9911         hda_nid_t nid;
9912
9913         spec->multiout.dac_nids = spec->private_dac_nids;
9914         for (i = 0; i < cfg->line_outs; i++) {
9915                 nid = cfg->line_out_pins[i];
9916                 if (nid) {
9917                         if (i >= ARRAY_SIZE(alc861_dac_nids))
9918                                 continue;
9919                         spec->multiout.dac_nids[i] = alc861_dac_nids[i];
9920                 }
9921         }
9922         spec->multiout.num_dacs = cfg->line_outs;
9923         return 0;
9924 }
9925
9926 /* add playback controls from the parsed DAC table */
9927 static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
9928                                              const struct auto_pin_cfg *cfg)
9929 {
9930         char name[32];
9931         static const char *chname[4] = {
9932                 "Front", "Surround", NULL /*CLFE*/, "Side"
9933         };
9934         hda_nid_t nid;
9935         int i, idx, err;
9936
9937         for (i = 0; i < cfg->line_outs; i++) {
9938                 nid = spec->multiout.dac_nids[i];
9939                 if (!nid)
9940                         continue;
9941                 if (nid == 0x05) {
9942                         /* Center/LFE */
9943                         err = add_control(spec, ALC_CTL_BIND_MUTE,
9944                                           "Center Playback Switch",
9945                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
9946                                                               HDA_OUTPUT));
9947                         if (err < 0)
9948                                 return err;
9949                         err = add_control(spec, ALC_CTL_BIND_MUTE,
9950                                           "LFE Playback Switch",
9951                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
9952                                                               HDA_OUTPUT));
9953                         if (err < 0)
9954                                 return err;
9955                 } else {
9956                         for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1;
9957                              idx++)
9958                                 if (nid == alc861_dac_nids[idx])
9959                                         break;
9960                         sprintf(name, "%s Playback Switch", chname[idx]);
9961                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
9962                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
9963                                                               HDA_OUTPUT));
9964                         if (err < 0)
9965                                 return err;
9966                 }
9967         }
9968         return 0;
9969 }
9970
9971 static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
9972 {
9973         int err;
9974         hda_nid_t nid;
9975
9976         if (!pin)
9977                 return 0;
9978
9979         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
9980                 nid = 0x03;
9981                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9982                                   "Headphone Playback Switch",
9983                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
9984                 if (err < 0)
9985                         return err;
9986                 spec->multiout.hp_nid = nid;
9987         }
9988         return 0;
9989 }
9990
9991 /* create playback/capture controls for input pins */
9992 static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec,
9993                                                 const struct auto_pin_cfg *cfg)
9994 {
9995         struct hda_input_mux *imux = &spec->private_imux;
9996         int i, err, idx, idx1;
9997
9998         for (i = 0; i < AUTO_PIN_LAST; i++) {
9999                 switch (cfg->input_pins[i]) {
10000                 case 0x0c:
10001                         idx1 = 1;
10002                         idx = 2;        /* Line In */
10003                         break;
10004                 case 0x0f:
10005                         idx1 = 2;
10006                         idx = 2;        /* Line In */
10007                         break;
10008                 case 0x0d:
10009                         idx1 = 0;
10010                         idx = 1;        /* Mic In */
10011                         break;
10012                 case 0x10:
10013                         idx1 = 3;
10014                         idx = 1;        /* Mic In */
10015                         break;
10016                 case 0x11:
10017                         idx1 = 4;
10018                         idx = 0;        /* CD */
10019                         break;
10020                 default:
10021                         continue;
10022                 }
10023
10024                 err = new_analog_input(spec, cfg->input_pins[i],
10025                                        auto_pin_cfg_labels[i], idx, 0x15);
10026                 if (err < 0)
10027                         return err;
10028
10029                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
10030                 imux->items[imux->num_items].index = idx1;
10031                 imux->num_items++;
10032         }
10033         return 0;
10034 }
10035
10036 static struct snd_kcontrol_new alc861_capture_mixer[] = {
10037         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
10038         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
10039
10040         {
10041                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10042                 /* The multiple "Capture Source" controls confuse alsamixer
10043                  * So call somewhat different..
10044                  *FIXME: the controls appear in the "playback" view!
10045                  */
10046                 /* .name = "Capture Source", */
10047                 .name = "Input Source",
10048                 .count = 1,
10049                 .info = alc_mux_enum_info,
10050                 .get = alc_mux_enum_get,
10051                 .put = alc_mux_enum_put,
10052         },
10053         { } /* end */
10054 };
10055
10056 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
10057                                               hda_nid_t nid,
10058                                               int pin_type, int dac_idx)
10059 {
10060         /* set as output */
10061
10062         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
10063                             pin_type);
10064         snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE,
10065                             AMP_OUT_UNMUTE);
10066
10067 }
10068
10069 static void alc861_auto_init_multi_out(struct hda_codec *codec)
10070 {
10071         struct alc_spec *spec = codec->spec;
10072         int i;
10073
10074         alc_subsystem_id(codec, 0x0e, 0x0f, 0x0b);
10075         for (i = 0; i < spec->autocfg.line_outs; i++) {
10076                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
10077                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
10078                 if (nid)
10079                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
10080                                                           spec->multiout.dac_nids[i]);
10081         }
10082 }
10083
10084 static void alc861_auto_init_hp_out(struct hda_codec *codec)
10085 {
10086         struct alc_spec *spec = codec->spec;
10087         hda_nid_t pin;
10088
10089         pin = spec->autocfg.hp_pins[0];
10090         if (pin) /* connect to front */
10091                 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
10092                                                   spec->multiout.dac_nids[0]);
10093 }
10094
10095 static void alc861_auto_init_analog_input(struct hda_codec *codec)
10096 {
10097         struct alc_spec *spec = codec->spec;
10098         int i;
10099
10100         for (i = 0; i < AUTO_PIN_LAST; i++) {
10101                 hda_nid_t nid = spec->autocfg.input_pins[i];
10102                 if (nid >= 0x0c && nid <= 0x11) {
10103                         snd_hda_codec_write(codec, nid, 0,
10104                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
10105                                             i <= AUTO_PIN_FRONT_MIC ?
10106                                             PIN_VREF80 : PIN_IN);
10107                 }
10108         }
10109 }
10110
10111 /* parse the BIOS configuration and set up the alc_spec */
10112 /* return 1 if successful, 0 if the proper config is not found,
10113  * or a negative error code
10114  */
10115 static int alc861_parse_auto_config(struct hda_codec *codec)
10116 {
10117         struct alc_spec *spec = codec->spec;
10118         int err;
10119         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
10120
10121         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
10122                                            alc861_ignore);
10123         if (err < 0)
10124                 return err;
10125         if (!spec->autocfg.line_outs)
10126                 return 0; /* can't find valid BIOS pin config */
10127
10128         err = alc861_auto_fill_dac_nids(spec, &spec->autocfg);
10129         if (err < 0)
10130                 return err;
10131         err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg);
10132         if (err < 0)
10133                 return err;
10134         err = alc861_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
10135         if (err < 0)
10136                 return err;
10137         err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg);
10138         if (err < 0)
10139                 return err;
10140
10141         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
10142
10143         if (spec->autocfg.dig_out_pin)
10144                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
10145
10146         if (spec->kctl_alloc)
10147                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
10148
10149         spec->init_verbs[spec->num_init_verbs++] = alc861_auto_init_verbs;
10150
10151         spec->num_mux_defs = 1;
10152         spec->input_mux = &spec->private_imux;
10153
10154         spec->adc_nids = alc861_adc_nids;
10155         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
10156         spec->mixers[spec->num_mixers] = alc861_capture_mixer;
10157         spec->num_mixers++;
10158
10159         return 1;
10160 }
10161
10162 /* additional initialization for auto-configuration model */
10163 static void alc861_auto_init(struct hda_codec *codec)
10164 {
10165         alc861_auto_init_multi_out(codec);
10166         alc861_auto_init_hp_out(codec);
10167         alc861_auto_init_analog_input(codec);
10168 }
10169
10170 #ifdef CONFIG_SND_HDA_POWER_SAVE
10171 static struct hda_amp_list alc861_loopbacks[] = {
10172         { 0x15, HDA_INPUT, 0 },
10173         { 0x15, HDA_INPUT, 1 },
10174         { 0x15, HDA_INPUT, 2 },
10175         { 0x15, HDA_INPUT, 3 },
10176         { } /* end */
10177 };
10178 #endif
10179
10180
10181 /*
10182  * configuration and preset
10183  */
10184 static const char *alc861_models[ALC861_MODEL_LAST] = {
10185         [ALC861_3ST]            = "3stack",
10186         [ALC660_3ST]            = "3stack-660",
10187         [ALC861_3ST_DIG]        = "3stack-dig",
10188         [ALC861_6ST_DIG]        = "6stack-dig",
10189         [ALC861_UNIWILL_M31]    = "uniwill-m31",
10190         [ALC861_TOSHIBA]        = "toshiba",
10191         [ALC861_ASUS]           = "asus",
10192         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
10193         [ALC861_AUTO]           = "auto",
10194 };
10195
10196 static struct snd_pci_quirk alc861_cfg_tbl[] = {
10197         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
10198         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
10199         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
10200         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
10201         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
10202         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
10203         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
10204         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
10205         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
10206          *        Any other models that need this preset?
10207          */
10208         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
10209         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
10210         SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31),
10211         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
10212         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
10213         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
10214         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
10215         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
10216         {}
10217 };
10218
10219 static struct alc_config_preset alc861_presets[] = {
10220         [ALC861_3ST] = {
10221                 .mixers = { alc861_3ST_mixer },
10222                 .init_verbs = { alc861_threestack_init_verbs },
10223                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
10224                 .dac_nids = alc861_dac_nids,
10225                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
10226                 .channel_mode = alc861_threestack_modes,
10227                 .need_dac_fix = 1,
10228                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
10229                 .adc_nids = alc861_adc_nids,
10230                 .input_mux = &alc861_capture_source,
10231         },
10232         [ALC861_3ST_DIG] = {
10233                 .mixers = { alc861_base_mixer },
10234                 .init_verbs = { alc861_threestack_init_verbs },
10235                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
10236                 .dac_nids = alc861_dac_nids,
10237                 .dig_out_nid = ALC861_DIGOUT_NID,
10238                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
10239                 .channel_mode = alc861_threestack_modes,
10240                 .need_dac_fix = 1,
10241                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
10242                 .adc_nids = alc861_adc_nids,
10243                 .input_mux = &alc861_capture_source,
10244         },
10245         [ALC861_6ST_DIG] = {
10246                 .mixers = { alc861_base_mixer },
10247                 .init_verbs = { alc861_base_init_verbs },
10248                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
10249                 .dac_nids = alc861_dac_nids,
10250                 .dig_out_nid = ALC861_DIGOUT_NID,
10251                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
10252                 .channel_mode = alc861_8ch_modes,
10253                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
10254                 .adc_nids = alc861_adc_nids,
10255                 .input_mux = &alc861_capture_source,
10256         },
10257         [ALC660_3ST] = {
10258                 .mixers = { alc861_3ST_mixer },
10259                 .init_verbs = { alc861_threestack_init_verbs },
10260                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
10261                 .dac_nids = alc660_dac_nids,
10262                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
10263                 .channel_mode = alc861_threestack_modes,
10264                 .need_dac_fix = 1,
10265                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
10266                 .adc_nids = alc861_adc_nids,
10267                 .input_mux = &alc861_capture_source,
10268         },
10269         [ALC861_UNIWILL_M31] = {
10270                 .mixers = { alc861_uniwill_m31_mixer },
10271                 .init_verbs = { alc861_uniwill_m31_init_verbs },
10272                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
10273                 .dac_nids = alc861_dac_nids,
10274                 .dig_out_nid = ALC861_DIGOUT_NID,
10275                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
10276                 .channel_mode = alc861_uniwill_m31_modes,
10277                 .need_dac_fix = 1,
10278                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
10279                 .adc_nids = alc861_adc_nids,
10280                 .input_mux = &alc861_capture_source,
10281         },
10282         [ALC861_TOSHIBA] = {
10283                 .mixers = { alc861_toshiba_mixer },
10284                 .init_verbs = { alc861_base_init_verbs,
10285                                 alc861_toshiba_init_verbs },
10286                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
10287                 .dac_nids = alc861_dac_nids,
10288                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
10289                 .channel_mode = alc883_3ST_2ch_modes,
10290                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
10291                 .adc_nids = alc861_adc_nids,
10292                 .input_mux = &alc861_capture_source,
10293                 .unsol_event = alc861_toshiba_unsol_event,
10294                 .init_hook = alc861_toshiba_automute,
10295         },
10296         [ALC861_ASUS] = {
10297                 .mixers = { alc861_asus_mixer },
10298                 .init_verbs = { alc861_asus_init_verbs },
10299                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
10300                 .dac_nids = alc861_dac_nids,
10301                 .dig_out_nid = ALC861_DIGOUT_NID,
10302                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
10303                 .channel_mode = alc861_asus_modes,
10304                 .need_dac_fix = 1,
10305                 .hp_nid = 0x06,
10306                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
10307                 .adc_nids = alc861_adc_nids,
10308                 .input_mux = &alc861_capture_source,
10309         },
10310         [ALC861_ASUS_LAPTOP] = {
10311                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
10312                 .init_verbs = { alc861_asus_init_verbs,
10313                                 alc861_asus_laptop_init_verbs },
10314                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
10315                 .dac_nids = alc861_dac_nids,
10316                 .dig_out_nid = ALC861_DIGOUT_NID,
10317                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
10318                 .channel_mode = alc883_3ST_2ch_modes,
10319                 .need_dac_fix = 1,
10320                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
10321                 .adc_nids = alc861_adc_nids,
10322                 .input_mux = &alc861_capture_source,
10323         },
10324 };
10325
10326
10327 static int patch_alc861(struct hda_codec *codec)
10328 {
10329         struct alc_spec *spec;
10330         int board_config;
10331         int err;
10332
10333         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
10334         if (spec == NULL)
10335                 return -ENOMEM;
10336
10337         codec->spec = spec;
10338
10339         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
10340                                                   alc861_models,
10341                                                   alc861_cfg_tbl);
10342
10343         if (board_config < 0) {
10344                 printk(KERN_INFO "hda_codec: Unknown model for ALC861, "
10345                        "trying auto-probe from BIOS...\n");
10346                 board_config = ALC861_AUTO;
10347         }
10348
10349         if (board_config == ALC861_AUTO) {
10350                 /* automatic parse from the BIOS config */
10351                 err = alc861_parse_auto_config(codec);
10352                 if (err < 0) {
10353                         alc_free(codec);
10354                         return err;
10355                 } else if (!err) {
10356                         printk(KERN_INFO
10357                                "hda_codec: Cannot set up configuration "
10358                                "from BIOS.  Using base mode...\n");
10359                    board_config = ALC861_3ST_DIG;
10360                 }
10361         }
10362
10363         if (board_config != ALC861_AUTO)
10364                 setup_preset(spec, &alc861_presets[board_config]);
10365
10366         spec->stream_name_analog = "ALC861 Analog";
10367         spec->stream_analog_playback = &alc861_pcm_analog_playback;
10368         spec->stream_analog_capture = &alc861_pcm_analog_capture;
10369
10370         spec->stream_name_digital = "ALC861 Digital";
10371         spec->stream_digital_playback = &alc861_pcm_digital_playback;
10372         spec->stream_digital_capture = &alc861_pcm_digital_capture;
10373
10374         codec->patch_ops = alc_patch_ops;
10375         if (board_config == ALC861_AUTO)
10376                 spec->init_hook = alc861_auto_init;
10377 #ifdef CONFIG_SND_HDA_POWER_SAVE
10378         if (!spec->loopback.amplist)
10379                 spec->loopback.amplist = alc861_loopbacks;
10380 #endif
10381                 
10382         return 0;
10383 }
10384
10385 /*
10386  * ALC861-VD support
10387  *
10388  * Based on ALC882
10389  *
10390  * In addition, an independent DAC
10391  */
10392 #define ALC861VD_DIGOUT_NID     0x06
10393
10394 static hda_nid_t alc861vd_dac_nids[4] = {
10395         /* front, surr, clfe, side surr */
10396         0x02, 0x03, 0x04, 0x05
10397 };
10398
10399 /* dac_nids for ALC660vd are in a different order - according to
10400  * Realtek's driver.
10401  * This should probably tesult in a different mixer for 6stack models
10402  * of ALC660vd codecs, but for now there is only 3stack mixer
10403  * - and it is the same as in 861vd.
10404  * adc_nids in ALC660vd are (is) the same as in 861vd
10405  */
10406 static hda_nid_t alc660vd_dac_nids[3] = {
10407         /* front, rear, clfe, rear_surr */
10408         0x02, 0x04, 0x03
10409 };
10410
10411 static hda_nid_t alc861vd_adc_nids[1] = {
10412         /* ADC0 */
10413         0x09,
10414 };
10415
10416 /* input MUX */
10417 /* FIXME: should be a matrix-type input source selection */
10418 static struct hda_input_mux alc861vd_capture_source = {
10419         .num_items = 4,
10420         .items = {
10421                 { "Mic", 0x0 },
10422                 { "Front Mic", 0x1 },
10423                 { "Line", 0x2 },
10424                 { "CD", 0x4 },
10425         },
10426 };
10427
10428 static struct hda_input_mux alc861vd_dallas_capture_source = {
10429         .num_items = 3,
10430         .items = {
10431                 { "Front Mic", 0x0 },
10432                 { "ATAPI Mic", 0x1 },
10433                 { "Line In", 0x5 },
10434         },
10435 };
10436
10437 static struct hda_input_mux alc861vd_hp_capture_source = {
10438         .num_items = 2,
10439         .items = {
10440                 { "Front Mic", 0x0 },
10441                 { "ATAPI Mic", 0x1 },
10442         },
10443 };
10444
10445 #define alc861vd_mux_enum_info alc_mux_enum_info
10446 #define alc861vd_mux_enum_get alc_mux_enum_get
10447
10448 static int alc861vd_mux_enum_put(struct snd_kcontrol *kcontrol,
10449                                 struct snd_ctl_elem_value *ucontrol)
10450 {
10451         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10452         struct alc_spec *spec = codec->spec;
10453         const struct hda_input_mux *imux = spec->input_mux;
10454         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
10455         static hda_nid_t capture_mixers[1] = { 0x22 };
10456         hda_nid_t nid = capture_mixers[adc_idx];
10457         unsigned int *cur_val = &spec->cur_mux[adc_idx];
10458         unsigned int i, idx;
10459
10460         idx = ucontrol->value.enumerated.item[0];
10461         if (idx >= imux->num_items)
10462                 idx = imux->num_items - 1;
10463         if (*cur_val == idx)
10464                 return 0;
10465         for (i = 0; i < imux->num_items; i++) {
10466                 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
10467                 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
10468                                          imux->items[i].index,
10469                                          HDA_AMP_MUTE, v);
10470         }
10471         *cur_val = idx;
10472         return 1;
10473 }
10474
10475 /*
10476  * 2ch mode
10477  */
10478 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
10479         { 2, NULL }
10480 };
10481
10482 /*
10483  * 6ch mode
10484  */
10485 static struct hda_verb alc861vd_6stack_ch6_init[] = {
10486         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
10487         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10488         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10489         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10490         { } /* end */
10491 };
10492
10493 /*
10494  * 8ch mode
10495  */
10496 static struct hda_verb alc861vd_6stack_ch8_init[] = {
10497         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10498         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10499         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10500         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10501         { } /* end */
10502 };
10503
10504 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
10505         { 6, alc861vd_6stack_ch6_init },
10506         { 8, alc861vd_6stack_ch8_init },
10507 };
10508
10509 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
10510         {
10511                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10512                 .name = "Channel Mode",
10513                 .info = alc_ch_mode_info,
10514                 .get = alc_ch_mode_get,
10515                 .put = alc_ch_mode_put,
10516         },
10517         { } /* end */
10518 };
10519
10520 static struct snd_kcontrol_new alc861vd_capture_mixer[] = {
10521         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
10522         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
10523
10524         {
10525                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10526                 /* The multiple "Capture Source" controls confuse alsamixer
10527                  * So call somewhat different..
10528                  *FIXME: the controls appear in the "playback" view!
10529                  */
10530                 /* .name = "Capture Source", */
10531                 .name = "Input Source",
10532                 .count = 1,
10533                 .info = alc861vd_mux_enum_info,
10534                 .get = alc861vd_mux_enum_get,
10535                 .put = alc861vd_mux_enum_put,
10536         },
10537         { } /* end */
10538 };
10539
10540 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
10541  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
10542  */
10543 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
10544         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10545         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
10546
10547         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
10548         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
10549
10550         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
10551                                 HDA_OUTPUT),
10552         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
10553                                 HDA_OUTPUT),
10554         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
10555         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
10556
10557         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
10558         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
10559
10560         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10561
10562         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10563         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10564         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10565
10566         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10567         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10568         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10569
10570         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10571         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10572
10573         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10574         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10575
10576         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
10577         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
10578
10579         { } /* end */
10580 };
10581
10582 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
10583         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10584         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
10585
10586         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10587
10588         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10589         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10590         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10591
10592         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10593         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10594         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10595
10596         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10597         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10598
10599         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10600         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10601
10602         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
10603         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
10604
10605         { } /* end */
10606 };
10607
10608 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
10609         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10610         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
10611         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10612
10613         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10614
10615         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10616         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10617         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10618
10619         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10620         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10621         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10622
10623         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10624         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10625
10626         { } /* end */
10627 };
10628
10629 /* Pin assignment: Front=0x14, HP = 0x15,
10630  *                 Front Mic=0x18, ATAPI Mic = 0x19, Line In = 0x1d
10631  */
10632 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
10633         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10634         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
10635         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
10636         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
10637         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10638         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10639         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10640         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10641         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x05, HDA_INPUT),
10642         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x05, HDA_INPUT),
10643         { } /* end */
10644 };
10645
10646 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
10647  *                 Front Mic=0x18, ATAPI Mic = 0x19,
10648  */
10649 static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
10650         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10651         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
10652         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
10653         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
10654         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10655         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10656         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10657         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10658         
10659         { } /* end */
10660 };
10661
10662 /*
10663  * generic initialization of ADC, input mixers and output mixers
10664  */
10665 static struct hda_verb alc861vd_volume_init_verbs[] = {
10666         /*
10667          * Unmute ADC0 and set the default input to mic-in
10668          */
10669         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10670         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10671
10672         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
10673          * the analog-loopback mixer widget
10674          */
10675         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10676         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10677         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10678         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10679         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10680         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10681
10682         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
10683         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10684         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10685         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10686         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
10687
10688         /*
10689          * Set up output mixers (0x02 - 0x05)
10690          */
10691         /* set vol=0 to output mixers */
10692         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10693         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10694         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10695         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10696
10697         /* set up input amps for analog loopback */
10698         /* Amp Indices: DAC = 0, mixer = 1 */
10699         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10700         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10701         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10702         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10703         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10704         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10705         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10706         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10707
10708         { }
10709 };
10710
10711 /*
10712  * 3-stack pin configuration:
10713  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
10714  */
10715 static struct hda_verb alc861vd_3stack_init_verbs[] = {
10716         /*
10717          * Set pin mode and muting
10718          */
10719         /* set front pin widgets 0x14 for output */
10720         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10721         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10722         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
10723
10724         /* Mic (rear) pin: input vref at 80% */
10725         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10726         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10727         /* Front Mic pin: input vref at 80% */
10728         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10729         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10730         /* Line In pin: input */
10731         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10732         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10733         /* Line-2 In: Headphone output (output 0 - 0x0c) */
10734         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10735         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10736         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10737         /* CD pin widget for input */
10738         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10739
10740         { }
10741 };
10742
10743 /*
10744  * 6-stack pin configuration:
10745  */
10746 static struct hda_verb alc861vd_6stack_init_verbs[] = {
10747         /*
10748          * Set pin mode and muting
10749          */
10750         /* set front pin widgets 0x14 for output */
10751         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10752         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10753         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
10754
10755         /* Rear Pin: output 1 (0x0d) */
10756         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10757         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10758         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
10759         /* CLFE Pin: output 2 (0x0e) */
10760         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10761         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10762         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
10763         /* Side Pin: output 3 (0x0f) */
10764         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10765         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10766         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
10767
10768         /* Mic (rear) pin: input vref at 80% */
10769         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10770         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10771         /* Front Mic pin: input vref at 80% */
10772         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10773         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10774         /* Line In pin: input */
10775         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10776         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10777         /* Line-2 In: Headphone output (output 0 - 0x0c) */
10778         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10779         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10780         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10781         /* CD pin widget for input */
10782         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10783
10784         { }
10785 };
10786
10787 static struct hda_verb alc861vd_eapd_verbs[] = {
10788         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
10789         { }
10790 };
10791
10792 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
10793         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10794         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10795         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10796         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10797         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT}, 
10798         {}
10799 };
10800
10801 /* toggle speaker-output according to the hp-jack state */
10802 static void alc861vd_lenovo_hp_automute(struct hda_codec *codec)
10803 {
10804         unsigned int present;
10805         unsigned char bits;
10806
10807         present = snd_hda_codec_read(codec, 0x1b, 0,
10808                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10809         bits = present ? HDA_AMP_MUTE : 0;
10810         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10811                                  HDA_AMP_MUTE, bits);
10812 }
10813
10814 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
10815 {
10816         unsigned int present;
10817         unsigned char bits;
10818
10819         present = snd_hda_codec_read(codec, 0x18, 0,
10820                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10821         bits = present ? HDA_AMP_MUTE : 0;
10822         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
10823                                  HDA_AMP_MUTE, bits);
10824 }
10825
10826 static void alc861vd_lenovo_automute(struct hda_codec *codec)
10827 {
10828         alc861vd_lenovo_hp_automute(codec);
10829         alc861vd_lenovo_mic_automute(codec);
10830 }
10831
10832 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
10833                                         unsigned int res)
10834 {
10835         switch (res >> 26) {
10836         case ALC880_HP_EVENT:
10837                 alc861vd_lenovo_hp_automute(codec);
10838                 break;
10839         case ALC880_MIC_EVENT:
10840                 alc861vd_lenovo_mic_automute(codec);
10841                 break;
10842         }
10843 }
10844
10845 static struct hda_verb alc861vd_dallas_verbs[] = {
10846         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10847         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10848         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10849         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10850
10851         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10852         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10853         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10854         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10855         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10856         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10857         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10858         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10859         
10860         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10861         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10862         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10863         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10864         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10865         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10866         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10867         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10868
10869         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
10870         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10871         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
10872         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10873         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10874         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10875         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10876         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10877
10878         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10879         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10880         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10881         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10882
10883         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10884         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},  
10885         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10886
10887         { } /* end */
10888 };
10889
10890 /* toggle speaker-output according to the hp-jack state */
10891 static void alc861vd_dallas_automute(struct hda_codec *codec)
10892 {
10893         unsigned int present;
10894
10895         present = snd_hda_codec_read(codec, 0x15, 0,
10896                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10897         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10898                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
10899 }
10900
10901 static void alc861vd_dallas_unsol_event(struct hda_codec *codec, unsigned int res)
10902 {
10903         if ((res >> 26) == ALC880_HP_EVENT)
10904                 alc861vd_dallas_automute(codec);
10905 }
10906
10907 #ifdef CONFIG_SND_HDA_POWER_SAVE
10908 #define alc861vd_loopbacks      alc880_loopbacks
10909 #endif
10910
10911 /* pcm configuration: identiacal with ALC880 */
10912 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
10913 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
10914 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
10915 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
10916
10917 /*
10918  * configuration and preset
10919  */
10920 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
10921         [ALC660VD_3ST]          = "3stack-660",
10922         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
10923         [ALC861VD_3ST]          = "3stack",
10924         [ALC861VD_3ST_DIG]      = "3stack-digout",
10925         [ALC861VD_6ST_DIG]      = "6stack-digout",
10926         [ALC861VD_LENOVO]       = "lenovo",
10927         [ALC861VD_DALLAS]       = "dallas",
10928         [ALC861VD_HP]           = "hp",
10929         [ALC861VD_AUTO]         = "auto",
10930 };
10931
10932 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
10933         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
10934         SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),
10935         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
10936         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
10937         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
10938
10939         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
10940         SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS),
10941         SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo 3000 C200", ALC861VD_LENOVO),
10942         SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo", ALC861VD_LENOVO),
10943         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
10944         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
10945         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
10946         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
10947         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
10948         {}
10949 };
10950
10951 static struct alc_config_preset alc861vd_presets[] = {
10952         [ALC660VD_3ST] = {
10953                 .mixers = { alc861vd_3st_mixer },
10954                 .init_verbs = { alc861vd_volume_init_verbs,
10955                                  alc861vd_3stack_init_verbs },
10956                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
10957                 .dac_nids = alc660vd_dac_nids,
10958                 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
10959                 .adc_nids = alc861vd_adc_nids,
10960                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
10961                 .channel_mode = alc861vd_3stack_2ch_modes,
10962                 .input_mux = &alc861vd_capture_source,
10963         },
10964         [ALC660VD_3ST_DIG] = {
10965                 .mixers = { alc861vd_3st_mixer },
10966                 .init_verbs = { alc861vd_volume_init_verbs,
10967                                  alc861vd_3stack_init_verbs },
10968                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
10969                 .dac_nids = alc660vd_dac_nids,
10970                 .dig_out_nid = ALC861VD_DIGOUT_NID,
10971                 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
10972                 .adc_nids = alc861vd_adc_nids,
10973                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
10974                 .channel_mode = alc861vd_3stack_2ch_modes,
10975                 .input_mux = &alc861vd_capture_source,
10976         },
10977         [ALC861VD_3ST] = {
10978                 .mixers = { alc861vd_3st_mixer },
10979                 .init_verbs = { alc861vd_volume_init_verbs,
10980                                  alc861vd_3stack_init_verbs },
10981                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
10982                 .dac_nids = alc861vd_dac_nids,
10983                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
10984                 .channel_mode = alc861vd_3stack_2ch_modes,
10985                 .input_mux = &alc861vd_capture_source,
10986         },
10987         [ALC861VD_3ST_DIG] = {
10988                 .mixers = { alc861vd_3st_mixer },
10989                 .init_verbs = { alc861vd_volume_init_verbs,
10990                                  alc861vd_3stack_init_verbs },
10991                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
10992                 .dac_nids = alc861vd_dac_nids,
10993                 .dig_out_nid = ALC861VD_DIGOUT_NID,
10994                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
10995                 .channel_mode = alc861vd_3stack_2ch_modes,
10996                 .input_mux = &alc861vd_capture_source,
10997         },
10998         [ALC861VD_6ST_DIG] = {
10999                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
11000                 .init_verbs = { alc861vd_volume_init_verbs,
11001                                 alc861vd_6stack_init_verbs },
11002                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
11003                 .dac_nids = alc861vd_dac_nids,
11004                 .dig_out_nid = ALC861VD_DIGOUT_NID,
11005                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
11006                 .channel_mode = alc861vd_6stack_modes,
11007                 .input_mux = &alc861vd_capture_source,
11008         },
11009         [ALC861VD_LENOVO] = {
11010                 .mixers = { alc861vd_lenovo_mixer },
11011                 .init_verbs = { alc861vd_volume_init_verbs,
11012                                 alc861vd_3stack_init_verbs,
11013                                 alc861vd_eapd_verbs,
11014                                 alc861vd_lenovo_unsol_verbs },
11015                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
11016                 .dac_nids = alc660vd_dac_nids,
11017                 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
11018                 .adc_nids = alc861vd_adc_nids,
11019                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
11020                 .channel_mode = alc861vd_3stack_2ch_modes,
11021                 .input_mux = &alc861vd_capture_source,
11022                 .unsol_event = alc861vd_lenovo_unsol_event,
11023                 .init_hook = alc861vd_lenovo_automute,
11024         },
11025         [ALC861VD_DALLAS] = {
11026                 .mixers = { alc861vd_dallas_mixer },
11027                 .init_verbs = { alc861vd_dallas_verbs },
11028                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
11029                 .dac_nids = alc861vd_dac_nids,
11030                 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
11031                 .adc_nids = alc861vd_adc_nids,
11032                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
11033                 .channel_mode = alc861vd_3stack_2ch_modes,
11034                 .input_mux = &alc861vd_dallas_capture_source,
11035                 .unsol_event = alc861vd_dallas_unsol_event,
11036                 .init_hook = alc861vd_dallas_automute,
11037         },
11038         [ALC861VD_HP] = {
11039                 .mixers = { alc861vd_hp_mixer },
11040                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
11041                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
11042                 .dac_nids = alc861vd_dac_nids,
11043                 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
11044                 .dig_out_nid = ALC861VD_DIGOUT_NID,
11045                 .adc_nids = alc861vd_adc_nids,
11046                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
11047                 .channel_mode = alc861vd_3stack_2ch_modes,
11048                 .input_mux = &alc861vd_hp_capture_source,
11049                 .unsol_event = alc861vd_dallas_unsol_event,
11050                 .init_hook = alc861vd_dallas_automute,
11051         },              
11052 };
11053
11054 /*
11055  * BIOS auto configuration
11056  */
11057 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
11058                                 hda_nid_t nid, int pin_type, int dac_idx)
11059 {
11060         /* set as output */
11061         snd_hda_codec_write(codec, nid, 0,
11062                                 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
11063         snd_hda_codec_write(codec, nid, 0,
11064                                 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
11065 }
11066
11067 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
11068 {
11069         struct alc_spec *spec = codec->spec;
11070         int i;
11071
11072         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
11073         for (i = 0; i <= HDA_SIDE; i++) {
11074                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
11075                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
11076                 if (nid)
11077                         alc861vd_auto_set_output_and_unmute(codec, nid,
11078                                                             pin_type, i);
11079         }
11080 }
11081
11082
11083 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
11084 {
11085         struct alc_spec *spec = codec->spec;
11086         hda_nid_t pin;
11087
11088         pin = spec->autocfg.hp_pins[0];
11089         if (pin) /* connect to front and  use dac 0 */
11090                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
11091 }
11092
11093 #define alc861vd_is_input_pin(nid)      alc880_is_input_pin(nid)
11094 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
11095
11096 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
11097 {
11098         struct alc_spec *spec = codec->spec;
11099         int i;
11100
11101         for (i = 0; i < AUTO_PIN_LAST; i++) {
11102                 hda_nid_t nid = spec->autocfg.input_pins[i];
11103                 if (alc861vd_is_input_pin(nid)) {
11104                         snd_hda_codec_write(codec, nid, 0,
11105                                         AC_VERB_SET_PIN_WIDGET_CONTROL,
11106                                         i <= AUTO_PIN_FRONT_MIC ?
11107                                                         PIN_VREF80 : PIN_IN);
11108                         if (nid != ALC861VD_PIN_CD_NID)
11109                                 snd_hda_codec_write(codec, nid, 0,
11110                                                 AC_VERB_SET_AMP_GAIN_MUTE,
11111                                                 AMP_OUT_MUTE);
11112                 }
11113         }
11114 }
11115
11116 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
11117 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
11118
11119 /* add playback controls from the parsed DAC table */
11120 /* Based on ALC880 version. But ALC861VD has separate,
11121  * different NIDs for mute/unmute switch and volume control */
11122 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
11123                                              const struct auto_pin_cfg *cfg)
11124 {
11125         char name[32];
11126         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
11127         hda_nid_t nid_v, nid_s;
11128         int i, err;
11129
11130         for (i = 0; i < cfg->line_outs; i++) {
11131                 if (!spec->multiout.dac_nids[i])
11132                         continue;
11133                 nid_v = alc861vd_idx_to_mixer_vol(
11134                                 alc880_dac_to_idx(
11135                                         spec->multiout.dac_nids[i]));
11136                 nid_s = alc861vd_idx_to_mixer_switch(
11137                                 alc880_dac_to_idx(
11138                                         spec->multiout.dac_nids[i]));
11139
11140                 if (i == 2) {
11141                         /* Center/LFE */
11142                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
11143                                           "Center Playback Volume",
11144                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
11145                                                               HDA_OUTPUT));
11146                         if (err < 0)
11147                                 return err;
11148                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
11149                                           "LFE Playback Volume",
11150                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
11151                                                               HDA_OUTPUT));
11152                         if (err < 0)
11153                                 return err;
11154                         err = add_control(spec, ALC_CTL_BIND_MUTE,
11155                                           "Center Playback Switch",
11156                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
11157                                                               HDA_INPUT));
11158                         if (err < 0)
11159                                 return err;
11160                         err = add_control(spec, ALC_CTL_BIND_MUTE,
11161                                           "LFE Playback Switch",
11162                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
11163                                                               HDA_INPUT));
11164                         if (err < 0)
11165                                 return err;
11166                 } else {
11167                         sprintf(name, "%s Playback Volume", chname[i]);
11168                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11169                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
11170                                                               HDA_OUTPUT));
11171                         if (err < 0)
11172                                 return err;
11173                         sprintf(name, "%s Playback Switch", chname[i]);
11174                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
11175                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
11176                                                               HDA_INPUT));
11177                         if (err < 0)
11178                                 return err;
11179                 }
11180         }
11181         return 0;
11182 }
11183
11184 /* add playback controls for speaker and HP outputs */
11185 /* Based on ALC880 version. But ALC861VD has separate,
11186  * different NIDs for mute/unmute switch and volume control */
11187 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
11188                                         hda_nid_t pin, const char *pfx)
11189 {
11190         hda_nid_t nid_v, nid_s;
11191         int err;
11192         char name[32];
11193
11194         if (!pin)
11195                 return 0;
11196
11197         if (alc880_is_fixed_pin(pin)) {
11198                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
11199                 /* specify the DAC as the extra output */
11200                 if (!spec->multiout.hp_nid)
11201                         spec->multiout.hp_nid = nid_v;
11202                 else
11203                         spec->multiout.extra_out_nid[0] = nid_v;
11204                 /* control HP volume/switch on the output mixer amp */
11205                 nid_v = alc861vd_idx_to_mixer_vol(
11206                                 alc880_fixed_pin_idx(pin));
11207                 nid_s = alc861vd_idx_to_mixer_switch(
11208                                 alc880_fixed_pin_idx(pin));
11209
11210                 sprintf(name, "%s Playback Volume", pfx);
11211                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11212                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
11213                 if (err < 0)
11214                         return err;
11215                 sprintf(name, "%s Playback Switch", pfx);
11216                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
11217                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
11218                 if (err < 0)
11219                         return err;
11220         } else if (alc880_is_multi_pin(pin)) {
11221                 /* set manual connection */
11222                 /* we have only a switch on HP-out PIN */
11223                 sprintf(name, "%s Playback Switch", pfx);
11224                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
11225                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
11226                 if (err < 0)
11227                         return err;
11228         }
11229         return 0;
11230 }
11231
11232 /* parse the BIOS configuration and set up the alc_spec
11233  * return 1 if successful, 0 if the proper config is not found,
11234  * or a negative error code
11235  * Based on ALC880 version - had to change it to override
11236  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
11237 static int alc861vd_parse_auto_config(struct hda_codec *codec)
11238 {
11239         struct alc_spec *spec = codec->spec;
11240         int err;
11241         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
11242
11243         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11244                                            alc861vd_ignore);
11245         if (err < 0)
11246                 return err;
11247         if (!spec->autocfg.line_outs)
11248                 return 0; /* can't find valid BIOS pin config */
11249
11250         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
11251         if (err < 0)
11252                 return err;
11253         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
11254         if (err < 0)
11255                 return err;
11256         err = alc861vd_auto_create_extra_out(spec,
11257                                              spec->autocfg.speaker_pins[0],
11258                                              "Speaker");
11259         if (err < 0)
11260                 return err;
11261         err = alc861vd_auto_create_extra_out(spec,
11262                                              spec->autocfg.hp_pins[0],
11263                                              "Headphone");
11264         if (err < 0)
11265                 return err;
11266         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
11267         if (err < 0)
11268                 return err;
11269
11270         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
11271
11272         if (spec->autocfg.dig_out_pin)
11273                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
11274
11275         if (spec->kctl_alloc)
11276                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
11277
11278         spec->init_verbs[spec->num_init_verbs++]
11279                 = alc861vd_volume_init_verbs;
11280
11281         spec->num_mux_defs = 1;
11282         spec->input_mux = &spec->private_imux;
11283
11284         err = alc_auto_add_mic_boost(codec);
11285         if (err < 0)
11286                 return err;
11287
11288         return 1;
11289 }
11290
11291 /* additional initialization for auto-configuration model */
11292 static void alc861vd_auto_init(struct hda_codec *codec)
11293 {
11294         alc861vd_auto_init_multi_out(codec);
11295         alc861vd_auto_init_hp_out(codec);
11296         alc861vd_auto_init_analog_input(codec);
11297 }
11298
11299 static int patch_alc861vd(struct hda_codec *codec)
11300 {
11301         struct alc_spec *spec;
11302         int err, board_config;
11303
11304         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
11305         if (spec == NULL)
11306                 return -ENOMEM;
11307
11308         codec->spec = spec;
11309
11310         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
11311                                                   alc861vd_models,
11312                                                   alc861vd_cfg_tbl);
11313
11314         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
11315                 printk(KERN_INFO "hda_codec: Unknown model for ALC660VD/"
11316                         "ALC861VD, trying auto-probe from BIOS...\n");
11317                 board_config = ALC861VD_AUTO;
11318         }
11319
11320         if (board_config == ALC861VD_AUTO) {
11321                 /* automatic parse from the BIOS config */
11322                 err = alc861vd_parse_auto_config(codec);
11323                 if (err < 0) {
11324                         alc_free(codec);
11325                         return err;
11326                 } else if (!err) {
11327                         printk(KERN_INFO
11328                                "hda_codec: Cannot set up configuration "
11329                                "from BIOS.  Using base mode...\n");
11330                         board_config = ALC861VD_3ST;
11331                 }
11332         }
11333
11334         if (board_config != ALC861VD_AUTO)
11335                 setup_preset(spec, &alc861vd_presets[board_config]);
11336
11337         spec->stream_name_analog = "ALC861VD Analog";
11338         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
11339         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
11340
11341         spec->stream_name_digital = "ALC861VD Digital";
11342         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
11343         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
11344
11345         spec->adc_nids = alc861vd_adc_nids;
11346         spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
11347
11348         spec->mixers[spec->num_mixers] = alc861vd_capture_mixer;
11349         spec->num_mixers++;
11350
11351         codec->patch_ops = alc_patch_ops;
11352
11353         if (board_config == ALC861VD_AUTO)
11354                 spec->init_hook = alc861vd_auto_init;
11355 #ifdef CONFIG_SND_HDA_POWER_SAVE
11356         if (!spec->loopback.amplist)
11357                 spec->loopback.amplist = alc861vd_loopbacks;
11358 #endif
11359
11360         return 0;
11361 }
11362
11363 /*
11364  * ALC662 support
11365  *
11366  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
11367  * configuration.  Each pin widget can choose any input DACs and a mixer.
11368  * Each ADC is connected from a mixer of all inputs.  This makes possible
11369  * 6-channel independent captures.
11370  *
11371  * In addition, an independent DAC for the multi-playback (not used in this
11372  * driver yet).
11373  */
11374 #define ALC662_DIGOUT_NID       0x06
11375 #define ALC662_DIGIN_NID        0x0a
11376
11377 static hda_nid_t alc662_dac_nids[4] = {
11378         /* front, rear, clfe, rear_surr */
11379         0x02, 0x03, 0x04
11380 };
11381
11382 static hda_nid_t alc662_adc_nids[1] = {
11383         /* ADC1-2 */
11384         0x09,
11385 };
11386 /* input MUX */
11387 /* FIXME: should be a matrix-type input source selection */
11388
11389 static struct hda_input_mux alc662_capture_source = {
11390         .num_items = 4,
11391         .items = {
11392                 { "Mic", 0x0 },
11393                 { "Front Mic", 0x1 },
11394                 { "Line", 0x2 },
11395                 { "CD", 0x4 },
11396         },
11397 };
11398
11399 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
11400         .num_items = 2,
11401         .items = {
11402                 { "Mic", 0x1 },
11403                 { "Line", 0x2 },
11404         },
11405 };
11406 #define alc662_mux_enum_info alc_mux_enum_info
11407 #define alc662_mux_enum_get alc_mux_enum_get
11408
11409 static int alc662_mux_enum_put(struct snd_kcontrol *kcontrol,
11410                                struct snd_ctl_elem_value *ucontrol)
11411 {
11412         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
11413         struct alc_spec *spec = codec->spec;
11414         const struct hda_input_mux *imux = spec->input_mux;
11415         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
11416         static hda_nid_t capture_mixers[2] = { 0x23, 0x22 };
11417         hda_nid_t nid = capture_mixers[adc_idx];
11418         unsigned int *cur_val = &spec->cur_mux[adc_idx];
11419         unsigned int i, idx;
11420
11421         idx = ucontrol->value.enumerated.item[0];
11422         if (idx >= imux->num_items)
11423                 idx = imux->num_items - 1;
11424         if (*cur_val == idx)
11425                 return 0;
11426         for (i = 0; i < imux->num_items; i++) {
11427                 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
11428                 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
11429                                          imux->items[i].index,
11430                                          HDA_AMP_MUTE, v);
11431         }
11432         *cur_val = idx;
11433         return 1;
11434 }
11435 /*
11436  * 2ch mode
11437  */
11438 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
11439         { 2, NULL }
11440 };
11441
11442 /*
11443  * 2ch mode
11444  */
11445 static struct hda_verb alc662_3ST_ch2_init[] = {
11446         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
11447         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
11448         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
11449         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
11450         { } /* end */
11451 };
11452
11453 /*
11454  * 6ch mode
11455  */
11456 static struct hda_verb alc662_3ST_ch6_init[] = {
11457         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11458         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11459         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
11460         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11461         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11462         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
11463         { } /* end */
11464 };
11465
11466 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
11467         { 2, alc662_3ST_ch2_init },
11468         { 6, alc662_3ST_ch6_init },
11469 };
11470
11471 /*
11472  * 2ch mode
11473  */
11474 static struct hda_verb alc662_sixstack_ch6_init[] = {
11475         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11476         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11477         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11478         { } /* end */
11479 };
11480
11481 /*
11482  * 6ch mode
11483  */
11484 static struct hda_verb alc662_sixstack_ch8_init[] = {
11485         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11486         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11487         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11488         { } /* end */
11489 };
11490
11491 static struct hda_channel_mode alc662_5stack_modes[2] = {
11492         { 2, alc662_sixstack_ch6_init },
11493         { 6, alc662_sixstack_ch8_init },
11494 };
11495
11496 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
11497  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
11498  */
11499
11500 static struct snd_kcontrol_new alc662_base_mixer[] = {
11501         /* output mixer control */
11502         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
11503         HDA_CODEC_MUTE("Front Playback Switch", 0x02, 0x0, HDA_OUTPUT),
11504         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
11505         HDA_CODEC_MUTE("Surround Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11506         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
11507         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
11508         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
11509         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
11510         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
11511
11512         /*Input mixer control */
11513         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
11514         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
11515         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
11516         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
11517         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
11518         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
11519         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
11520         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
11521
11522         /* Capture mixer control */
11523         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
11524         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
11525         {
11526                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11527                 .name = "Capture Source",
11528                 .count = 1,
11529                 .info = alc_mux_enum_info,
11530                 .get = alc_mux_enum_get,
11531                 .put = alc_mux_enum_put,
11532         },
11533         { } /* end */
11534 };
11535
11536 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
11537         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11538         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
11539         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
11540         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
11541         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
11542         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
11543         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11544         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11545         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11546         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
11547         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
11548         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
11549         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
11550         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
11551         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
11552         {
11553                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11554                 /* .name = "Capture Source", */
11555                 .name = "Input Source",
11556                 .count = 1,
11557                 .info = alc662_mux_enum_info,
11558                 .get = alc662_mux_enum_get,
11559                 .put = alc662_mux_enum_put,
11560         },
11561         { } /* end */
11562 };
11563
11564 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
11565         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11566         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
11567         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11568         HDA_BIND_MUTE("Surround Playback Switch", 0x03, 2, HDA_INPUT),
11569         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
11570         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
11571         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
11572         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
11573         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
11574         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
11575         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
11576         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
11577         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11578         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11579         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11580         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
11581         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
11582         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
11583         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
11584         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
11585         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
11586         {
11587                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11588                 /* .name = "Capture Source", */
11589                 .name = "Input Source",
11590                 .count = 1,
11591                 .info = alc662_mux_enum_info,
11592                 .get = alc662_mux_enum_get,
11593                 .put = alc662_mux_enum_put,
11594         },
11595         { } /* end */
11596 };
11597
11598 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
11599         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11600         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
11601         HDA_CODEC_VOLUME("iSpeaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11602         HDA_BIND_MUTE("iSpeaker Playback Switch", 0x03, 2, HDA_INPUT),
11603         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
11604         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
11605         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11606         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
11607         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
11608         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
11609         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
11610         {
11611                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11612                 /* .name = "Capture Source", */
11613                 .name = "Input Source",
11614                 .count = 1,
11615                 .info = alc662_mux_enum_info,
11616                 .get = alc662_mux_enum_get,
11617                 .put = alc662_mux_enum_put,
11618         },
11619         { } /* end */
11620 };
11621
11622 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
11623         {
11624                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11625                 .name = "Channel Mode",
11626                 .info = alc_ch_mode_info,
11627                 .get = alc_ch_mode_get,
11628                 .put = alc_ch_mode_put,
11629         },
11630         { } /* end */
11631 };
11632
11633 static struct hda_verb alc662_init_verbs[] = {
11634         /* ADC: mute amp left and right */
11635         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11636         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
11637         /* Front mixer: unmute input/output amp left and right (volume = 0) */
11638
11639         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11640         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11641         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11642         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11643         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11644
11645         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11646         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11647         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11648         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11649         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11650         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11651
11652         /* Front Pin: output 0 (0x0c) */
11653         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11654         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11655
11656         /* Rear Pin: output 1 (0x0d) */
11657         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11658         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11659
11660         /* CLFE Pin: output 2 (0x0e) */
11661         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11662         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11663
11664         /* Mic (rear) pin: input vref at 80% */
11665         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11666         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11667         /* Front Mic pin: input vref at 80% */
11668         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11669         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11670         /* Line In pin: input */
11671         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11672         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11673         /* Line-2 In: Headphone output (output 0 - 0x0c) */
11674         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11675         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11676         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
11677         /* CD pin widget for input */
11678         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11679
11680         /* FIXME: use matrix-type input source selection */
11681         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
11682         /* Input mixer */
11683         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11684         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11685         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11686         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
11687         { }
11688 };
11689
11690 static struct hda_verb alc662_sue_init_verbs[] = {
11691         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
11692         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
11693         {}
11694 };
11695
11696 /*
11697  * generic initialization of ADC, input mixers and output mixers
11698  */
11699 static struct hda_verb alc662_auto_init_verbs[] = {
11700         /*
11701          * Unmute ADC and set the default input to mic-in
11702          */
11703         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
11704         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11705
11706         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
11707          * mixer widget
11708          * Note: PASD motherboards uses the Line In 2 as the input for front
11709          * panel mic (mic 2)
11710          */
11711         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11712         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11713         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11714         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11715         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11716         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11717
11718         /*
11719          * Set up output mixers (0x0c - 0x0f)
11720          */
11721         /* set vol=0 to output mixers */
11722         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11723         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11724         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11725
11726         /* set up input amps for analog loopback */
11727         /* Amp Indices: DAC = 0, mixer = 1 */
11728         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11729         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11730         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11731         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11732         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11733         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11734
11735
11736         /* FIXME: use matrix-type input source selection */
11737         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
11738         /* Input mixer */
11739         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11740         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11741         { }
11742 };
11743
11744 /* capture mixer elements */
11745 static struct snd_kcontrol_new alc662_capture_mixer[] = {
11746         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
11747         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
11748         {
11749                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11750                 /* The multiple "Capture Source" controls confuse alsamixer
11751                  * So call somewhat different..
11752                  * FIXME: the controls appear in the "playback" view!
11753                  */
11754                 /* .name = "Capture Source", */
11755                 .name = "Input Source",
11756                 .count = 1,
11757                 .info = alc882_mux_enum_info,
11758                 .get = alc882_mux_enum_get,
11759                 .put = alc882_mux_enum_put,
11760         },
11761         { } /* end */
11762 };
11763
11764 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
11765 {
11766         unsigned int present;
11767         unsigned char bits;
11768
11769         present = snd_hda_codec_read(codec, 0x14, 0,
11770                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11771         bits = present ? HDA_AMP_MUTE : 0;
11772         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
11773                                  HDA_AMP_MUTE, bits);
11774 }
11775
11776 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
11777 {
11778         unsigned int present;
11779         unsigned char bits;
11780
11781         present = snd_hda_codec_read(codec, 0x1b, 0,
11782                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11783         bits = present ? HDA_AMP_MUTE : 0;
11784         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
11785                                  HDA_AMP_MUTE, bits);
11786         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
11787                                  HDA_AMP_MUTE, bits);
11788 }
11789
11790 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
11791                                            unsigned int res)
11792 {
11793         if ((res >> 26) == ALC880_HP_EVENT)
11794                 alc662_lenovo_101e_all_automute(codec);
11795         if ((res >> 26) == ALC880_FRONT_EVENT)
11796                 alc662_lenovo_101e_ispeaker_automute(codec);
11797 }
11798
11799 #ifdef CONFIG_SND_HDA_POWER_SAVE
11800 #define alc662_loopbacks        alc880_loopbacks
11801 #endif
11802
11803
11804 /* pcm configuration: identiacal with ALC880 */
11805 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
11806 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
11807 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
11808 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
11809
11810 /*
11811  * configuration and preset
11812  */
11813 static const char *alc662_models[ALC662_MODEL_LAST] = {
11814         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
11815         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
11816         [ALC662_3ST_6ch]        = "3stack-6ch",
11817         [ALC662_5ST_DIG]        = "6stack-dig",
11818         [ALC662_LENOVO_101E]    = "lenovo-101e",
11819         [ALC662_AUTO]           = "auto",
11820 };
11821
11822 static struct snd_pci_quirk alc662_cfg_tbl[] = {
11823         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
11824         {}
11825 };
11826
11827 static struct alc_config_preset alc662_presets[] = {
11828         [ALC662_3ST_2ch_DIG] = {
11829                 .mixers = { alc662_3ST_2ch_mixer },
11830                 .init_verbs = { alc662_init_verbs },
11831                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
11832                 .dac_nids = alc662_dac_nids,
11833                 .dig_out_nid = ALC662_DIGOUT_NID,
11834                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
11835                 .adc_nids = alc662_adc_nids,
11836                 .dig_in_nid = ALC662_DIGIN_NID,
11837                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
11838                 .channel_mode = alc662_3ST_2ch_modes,
11839                 .input_mux = &alc662_capture_source,
11840         },
11841         [ALC662_3ST_6ch_DIG] = {
11842                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
11843                 .init_verbs = { alc662_init_verbs },
11844                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
11845                 .dac_nids = alc662_dac_nids,
11846                 .dig_out_nid = ALC662_DIGOUT_NID,
11847                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
11848                 .adc_nids = alc662_adc_nids,
11849                 .dig_in_nid = ALC662_DIGIN_NID,
11850                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
11851                 .channel_mode = alc662_3ST_6ch_modes,
11852                 .need_dac_fix = 1,
11853                 .input_mux = &alc662_capture_source,
11854         },
11855         [ALC662_3ST_6ch] = {
11856                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
11857                 .init_verbs = { alc662_init_verbs },
11858                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
11859                 .dac_nids = alc662_dac_nids,
11860                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
11861                 .adc_nids = alc662_adc_nids,
11862                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
11863                 .channel_mode = alc662_3ST_6ch_modes,
11864                 .need_dac_fix = 1,
11865                 .input_mux = &alc662_capture_source,
11866         },
11867         [ALC662_5ST_DIG] = {
11868                 .mixers = { alc662_base_mixer, alc662_chmode_mixer },
11869                 .init_verbs = { alc662_init_verbs },
11870                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
11871                 .dac_nids = alc662_dac_nids,
11872                 .dig_out_nid = ALC662_DIGOUT_NID,
11873                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
11874                 .adc_nids = alc662_adc_nids,
11875                 .dig_in_nid = ALC662_DIGIN_NID,
11876                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
11877                 .channel_mode = alc662_5stack_modes,
11878                 .input_mux = &alc662_capture_source,
11879         },
11880         [ALC662_LENOVO_101E] = {
11881                 .mixers = { alc662_lenovo_101e_mixer },
11882                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
11883                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
11884                 .dac_nids = alc662_dac_nids,
11885                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
11886                 .adc_nids = alc662_adc_nids,
11887                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
11888                 .channel_mode = alc662_3ST_2ch_modes,
11889                 .input_mux = &alc662_lenovo_101e_capture_source,
11890                 .unsol_event = alc662_lenovo_101e_unsol_event,
11891                 .init_hook = alc662_lenovo_101e_all_automute,
11892         },
11893
11894 };
11895
11896
11897 /*
11898  * BIOS auto configuration
11899  */
11900
11901 /* add playback controls from the parsed DAC table */
11902 static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec,
11903                                              const struct auto_pin_cfg *cfg)
11904 {
11905         char name[32];
11906         static const char *chname[4] = {
11907                 "Front", "Surround", NULL /*CLFE*/, "Side"
11908         };
11909         hda_nid_t nid;
11910         int i, err;
11911
11912         for (i = 0; i < cfg->line_outs; i++) {
11913                 if (!spec->multiout.dac_nids[i])
11914                         continue;
11915                 nid = alc880_idx_to_mixer(i);
11916                 if (i == 2) {
11917                         /* Center/LFE */
11918                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
11919                                           "Center Playback Volume",
11920                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
11921                                                               HDA_OUTPUT));
11922                         if (err < 0)
11923                                 return err;
11924                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
11925                                           "LFE Playback Volume",
11926                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
11927                                                               HDA_OUTPUT));
11928                         if (err < 0)
11929                                 return err;
11930                         err = add_control(spec, ALC_CTL_BIND_MUTE,
11931                                           "Center Playback Switch",
11932                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
11933                                                               HDA_INPUT));
11934                         if (err < 0)
11935                                 return err;
11936                         err = add_control(spec, ALC_CTL_BIND_MUTE,
11937                                           "LFE Playback Switch",
11938                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
11939                                                               HDA_INPUT));
11940                         if (err < 0)
11941                                 return err;
11942                 } else {
11943                         sprintf(name, "%s Playback Volume", chname[i]);
11944                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11945                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
11946                                                               HDA_OUTPUT));
11947                         if (err < 0)
11948                                 return err;
11949                         sprintf(name, "%s Playback Switch", chname[i]);
11950                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
11951                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
11952                                                               HDA_INPUT));
11953                         if (err < 0)
11954                                 return err;
11955                 }
11956         }
11957         return 0;
11958 }
11959
11960 /* add playback controls for speaker and HP outputs */
11961 static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
11962                                         const char *pfx)
11963 {
11964         hda_nid_t nid;
11965         int err;
11966         char name[32];
11967
11968         if (!pin)
11969                 return 0;
11970
11971         if (alc880_is_fixed_pin(pin)) {
11972                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
11973                 /* printk("DAC nid=%x\n",nid); */
11974                 /* specify the DAC as the extra output */
11975                 if (!spec->multiout.hp_nid)
11976                         spec->multiout.hp_nid = nid;
11977                 else
11978                         spec->multiout.extra_out_nid[0] = nid;
11979                 /* control HP volume/switch on the output mixer amp */
11980                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
11981                 sprintf(name, "%s Playback Volume", pfx);
11982                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11983                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
11984                 if (err < 0)
11985                         return err;
11986                 sprintf(name, "%s Playback Switch", pfx);
11987                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
11988                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
11989                 if (err < 0)
11990                         return err;
11991         } else if (alc880_is_multi_pin(pin)) {
11992                 /* set manual connection */
11993                 /* we have only a switch on HP-out PIN */
11994                 sprintf(name, "%s Playback Switch", pfx);
11995                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
11996                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
11997                 if (err < 0)
11998                         return err;
11999         }
12000         return 0;
12001 }
12002
12003 /* create playback/capture controls for input pins */
12004 static int alc662_auto_create_analog_input_ctls(struct alc_spec *spec,
12005                                                 const struct auto_pin_cfg *cfg)
12006 {
12007         struct hda_input_mux *imux = &spec->private_imux;
12008         int i, err, idx;
12009
12010         for (i = 0; i < AUTO_PIN_LAST; i++) {
12011                 if (alc880_is_input_pin(cfg->input_pins[i])) {
12012                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
12013                         err = new_analog_input(spec, cfg->input_pins[i],
12014                                                auto_pin_cfg_labels[i],
12015                                                idx, 0x0b);
12016                         if (err < 0)
12017                                 return err;
12018                         imux->items[imux->num_items].label =
12019                                 auto_pin_cfg_labels[i];
12020                         imux->items[imux->num_items].index =
12021                                 alc880_input_pin_idx(cfg->input_pins[i]);
12022                         imux->num_items++;
12023                 }
12024         }
12025         return 0;
12026 }
12027
12028 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
12029                                               hda_nid_t nid, int pin_type,
12030                                               int dac_idx)
12031 {
12032         /* set as output */
12033         snd_hda_codec_write(codec, nid, 0,
12034                             AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
12035         snd_hda_codec_write(codec, nid, 0,
12036                             AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
12037         /* need the manual connection? */
12038         if (alc880_is_multi_pin(nid)) {
12039                 struct alc_spec *spec = codec->spec;
12040                 int idx = alc880_multi_pin_idx(nid);
12041                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
12042                                     AC_VERB_SET_CONNECT_SEL,
12043                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
12044         }
12045 }
12046
12047 static void alc662_auto_init_multi_out(struct hda_codec *codec)
12048 {
12049         struct alc_spec *spec = codec->spec;
12050         int i;
12051
12052         for (i = 0; i <= HDA_SIDE; i++) {
12053                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
12054                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
12055                 if (nid)
12056                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
12057                                                           i);
12058         }
12059 }
12060
12061 static void alc662_auto_init_hp_out(struct hda_codec *codec)
12062 {
12063         struct alc_spec *spec = codec->spec;
12064         hda_nid_t pin;
12065
12066         pin = spec->autocfg.hp_pins[0];
12067         if (pin) /* connect to front */
12068                 /* use dac 0 */
12069                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
12070 }
12071
12072 #define alc662_is_input_pin(nid)        alc880_is_input_pin(nid)
12073 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
12074
12075 static void alc662_auto_init_analog_input(struct hda_codec *codec)
12076 {
12077         struct alc_spec *spec = codec->spec;
12078         int i;
12079
12080         for (i = 0; i < AUTO_PIN_LAST; i++) {
12081                 hda_nid_t nid = spec->autocfg.input_pins[i];
12082                 if (alc662_is_input_pin(nid)) {
12083                         snd_hda_codec_write(codec, nid, 0,
12084                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
12085                                             (i <= AUTO_PIN_FRONT_MIC ?
12086                                              PIN_VREF80 : PIN_IN));
12087                         if (nid != ALC662_PIN_CD_NID)
12088                                 snd_hda_codec_write(codec, nid, 0,
12089                                                     AC_VERB_SET_AMP_GAIN_MUTE,
12090                                                     AMP_OUT_MUTE);
12091                 }
12092         }
12093 }
12094
12095 static int alc662_parse_auto_config(struct hda_codec *codec)
12096 {
12097         struct alc_spec *spec = codec->spec;
12098         int err;
12099         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
12100
12101         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
12102                                            alc662_ignore);
12103         if (err < 0)
12104                 return err;
12105         if (!spec->autocfg.line_outs)
12106                 return 0; /* can't find valid BIOS pin config */
12107
12108         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
12109         if (err < 0)
12110                 return err;
12111         err = alc662_auto_create_multi_out_ctls(spec, &spec->autocfg);
12112         if (err < 0)
12113                 return err;
12114         err = alc662_auto_create_extra_out(spec,
12115                                            spec->autocfg.speaker_pins[0],
12116                                            "Speaker");
12117         if (err < 0)
12118                 return err;
12119         err = alc662_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
12120                                            "Headphone");
12121         if (err < 0)
12122                 return err;
12123         err = alc662_auto_create_analog_input_ctls(spec, &spec->autocfg);
12124         if (err < 0)
12125                 return err;
12126
12127         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
12128
12129         if (spec->autocfg.dig_out_pin)
12130                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
12131
12132         if (spec->kctl_alloc)
12133                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
12134
12135         spec->num_mux_defs = 1;
12136         spec->input_mux = &spec->private_imux;
12137         
12138         spec->init_verbs[spec->num_init_verbs++] = alc662_auto_init_verbs;
12139         spec->mixers[spec->num_mixers] = alc662_capture_mixer;
12140         spec->num_mixers++;
12141         return 1;
12142 }
12143
12144 /* additional initialization for auto-configuration model */
12145 static void alc662_auto_init(struct hda_codec *codec)
12146 {
12147         alc662_auto_init_multi_out(codec);
12148         alc662_auto_init_hp_out(codec);
12149         alc662_auto_init_analog_input(codec);
12150 }
12151
12152 static int patch_alc662(struct hda_codec *codec)
12153 {
12154         struct alc_spec *spec;
12155         int err, board_config;
12156
12157         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
12158         if (!spec)
12159                 return -ENOMEM;
12160
12161         codec->spec = spec;
12162
12163         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
12164                                                   alc662_models,
12165                                                   alc662_cfg_tbl);
12166         if (board_config < 0) {
12167                 printk(KERN_INFO "hda_codec: Unknown model for ALC662, "
12168                        "trying auto-probe from BIOS...\n");
12169                 board_config = ALC662_AUTO;
12170         }
12171
12172         if (board_config == ALC662_AUTO) {
12173                 /* automatic parse from the BIOS config */
12174                 err = alc662_parse_auto_config(codec);
12175                 if (err < 0) {
12176                         alc_free(codec);
12177                         return err;
12178                 } else if (!err) {
12179                         printk(KERN_INFO
12180                                "hda_codec: Cannot set up configuration "
12181                                "from BIOS.  Using base mode...\n");
12182                         board_config = ALC662_3ST_2ch_DIG;
12183                 }
12184         }
12185
12186         if (board_config != ALC662_AUTO)
12187                 setup_preset(spec, &alc662_presets[board_config]);
12188
12189         spec->stream_name_analog = "ALC662 Analog";
12190         spec->stream_analog_playback = &alc662_pcm_analog_playback;
12191         spec->stream_analog_capture = &alc662_pcm_analog_capture;
12192
12193         spec->stream_name_digital = "ALC662 Digital";
12194         spec->stream_digital_playback = &alc662_pcm_digital_playback;
12195         spec->stream_digital_capture = &alc662_pcm_digital_capture;
12196
12197         if (!spec->adc_nids && spec->input_mux) {
12198                 spec->adc_nids = alc662_adc_nids;
12199                 spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
12200         }
12201
12202         codec->patch_ops = alc_patch_ops;
12203         if (board_config == ALC662_AUTO)
12204                 spec->init_hook = alc662_auto_init;
12205 #ifdef CONFIG_SND_HDA_POWER_SAVE
12206         if (!spec->loopback.amplist)
12207                 spec->loopback.amplist = alc662_loopbacks;
12208 #endif
12209
12210         return 0;
12211 }
12212
12213 /*
12214  * patch entries
12215  */
12216 struct hda_codec_preset snd_hda_preset_realtek[] = {
12217         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
12218         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
12219         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
12220         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
12221           .patch = patch_alc861 },
12222         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
12223         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
12224         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
12225         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
12226           .patch = patch_alc883 },
12227         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
12228           .patch = patch_alc662 },
12229         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
12230         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
12231         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
12232         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
12233         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
12234         {} /* terminator */
12235 };