[ALSA] hda-codec - Improve ALC262 ultra model
[linux-2.6] / sound / pci / hda / patch_realtek.c
1 /*
2  * Universal Interface for Intel High Definition Audio Codec
3  *
4  * HD audio interface patch for ALC 260/880/882 codecs
5  *
6  * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7  *                    PeiSen Hou <pshou@realtek.com.tw>
8  *                    Takashi Iwai <tiwai@suse.de>
9  *                    Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
10  *
11  *  This driver is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This driver is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
24  */
25
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/slab.h>
29 #include <linux/pci.h>
30 #include <sound/core.h>
31 #include "hda_codec.h"
32 #include "hda_local.h"
33 #include "hda_patch.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_HP_TC_T5735,
96         ALC262_HP_RP5700,
97         ALC262_BENQ_ED8,
98         ALC262_SONY_ASSAMD,
99         ALC262_BENQ_T31,
100         ALC262_ULTRA,
101         ALC262_AUTO,
102         ALC262_MODEL_LAST /* last tag */
103 };
104
105 /* ALC268 models */
106 enum {
107         ALC268_3ST,
108         ALC268_TOSHIBA,
109         ALC268_ACER,
110         ALC268_DELL,
111         ALC268_ZEPTO,
112 #ifdef CONFIG_SND_DEBUG
113         ALC268_TEST,
114 #endif
115         ALC268_AUTO,
116         ALC268_MODEL_LAST /* last tag */
117 };
118
119 /* ALC269 models */
120 enum {
121         ALC269_BASIC,
122         ALC269_AUTO,
123         ALC269_MODEL_LAST /* last tag */
124 };
125
126 /* ALC861 models */
127 enum {
128         ALC861_3ST,
129         ALC660_3ST,
130         ALC861_3ST_DIG,
131         ALC861_6ST_DIG,
132         ALC861_UNIWILL_M31,
133         ALC861_TOSHIBA,
134         ALC861_ASUS,
135         ALC861_ASUS_LAPTOP,
136         ALC861_AUTO,
137         ALC861_MODEL_LAST,
138 };
139
140 /* ALC861-VD models */
141 enum {
142         ALC660VD_3ST,
143         ALC660VD_3ST_DIG,
144         ALC861VD_3ST,
145         ALC861VD_3ST_DIG,
146         ALC861VD_6ST_DIG,
147         ALC861VD_LENOVO,
148         ALC861VD_DALLAS,
149         ALC861VD_HP,
150         ALC861VD_AUTO,
151         ALC861VD_MODEL_LAST,
152 };
153
154 /* ALC662 models */
155 enum {
156         ALC662_3ST_2ch_DIG,
157         ALC662_3ST_6ch_DIG,
158         ALC662_3ST_6ch,
159         ALC662_5ST_DIG,
160         ALC662_LENOVO_101E,
161         ALC662_ASUS_EEEPC_P701,
162         ALC662_ASUS_EEEPC_EP20,
163         ALC662_AUTO,
164         ALC662_MODEL_LAST,
165 };
166
167 /* ALC882 models */
168 enum {
169         ALC882_3ST_DIG,
170         ALC882_6ST_DIG,
171         ALC882_ARIMA,
172         ALC882_W2JC,
173         ALC882_TARGA,
174         ALC882_ASUS_A7J,
175         ALC882_ASUS_A7M,
176         ALC885_MACPRO,
177         ALC885_MBP3,
178         ALC885_IMAC24,
179         ALC882_AUTO,
180         ALC882_MODEL_LAST,
181 };
182
183 /* ALC883 models */
184 enum {
185         ALC883_3ST_2ch_DIG,
186         ALC883_3ST_6ch_DIG,
187         ALC883_3ST_6ch,
188         ALC883_6ST_DIG,
189         ALC883_TARGA_DIG,
190         ALC883_TARGA_2ch_DIG,
191         ALC883_ACER,
192         ALC883_ACER_ASPIRE,
193         ALC883_MEDION,
194         ALC883_MEDION_MD2,      
195         ALC883_LAPTOP_EAPD,
196         ALC883_LENOVO_101E_2ch,
197         ALC883_LENOVO_NB0763,
198         ALC888_LENOVO_MS7195_DIG,
199         ALC883_HAIER_W66,               
200         ALC888_6ST_HP,
201         ALC888_3ST_HP,
202         ALC888_6ST_DELL,
203         ALC883_MITAC,
204         ALC883_CLEVO_M720R,
205         ALC883_FUJITSU_PI2515,
206         ALC883_AUTO,
207         ALC883_MODEL_LAST,
208 };
209
210 /* for GPIO Poll */
211 #define GPIO_MASK       0x03
212
213 struct alc_spec {
214         /* codec parameterization */
215         struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
216         unsigned int num_mixers;
217
218         const struct hda_verb *init_verbs[5];   /* initialization verbs
219                                                  * don't forget NULL
220                                                  * termination!
221                                                  */
222         unsigned int num_init_verbs;
223
224         char *stream_name_analog;       /* analog PCM stream */
225         struct hda_pcm_stream *stream_analog_playback;
226         struct hda_pcm_stream *stream_analog_capture;
227         struct hda_pcm_stream *stream_analog_alt_playback;
228         struct hda_pcm_stream *stream_analog_alt_capture;
229
230         char *stream_name_digital;      /* digital PCM stream */
231         struct hda_pcm_stream *stream_digital_playback;
232         struct hda_pcm_stream *stream_digital_capture;
233
234         /* playback */
235         struct hda_multi_out multiout;  /* playback set-up
236                                          * max_channels, dacs must be set
237                                          * dig_out_nid and hp_nid are optional
238                                          */
239         hda_nid_t alt_dac_nid;
240
241         /* capture */
242         unsigned int num_adc_nids;
243         hda_nid_t *adc_nids;
244         hda_nid_t *capsrc_nids;
245         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
246
247         /* capture source */
248         unsigned int num_mux_defs;
249         const struct hda_input_mux *input_mux;
250         unsigned int cur_mux[3];
251
252         /* channel model */
253         const struct hda_channel_mode *channel_mode;
254         int num_channel_mode;
255         int need_dac_fix;
256
257         /* PCM information */
258         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
259
260         /* dynamic controls, init_verbs and input_mux */
261         struct auto_pin_cfg autocfg;
262         unsigned int num_kctl_alloc, num_kctl_used;
263         struct snd_kcontrol_new *kctl_alloc;
264         struct hda_input_mux private_imux;
265         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
266
267         /* hooks */
268         void (*init_hook)(struct hda_codec *codec);
269         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
270
271         /* for pin sensing */
272         unsigned int sense_updated: 1;
273         unsigned int jack_present: 1;
274         unsigned int master_sw: 1;
275
276         /* for virtual master */
277         hda_nid_t vmaster_nid;
278 #ifdef CONFIG_SND_HDA_POWER_SAVE
279         struct hda_loopback_check loopback;
280 #endif
281 };
282
283 /*
284  * configuration template - to be copied to the spec instance
285  */
286 struct alc_config_preset {
287         struct snd_kcontrol_new *mixers[5]; /* should be identical size
288                                              * with spec
289                                              */
290         const struct hda_verb *init_verbs[5];
291         unsigned int num_dacs;
292         hda_nid_t *dac_nids;
293         hda_nid_t dig_out_nid;          /* optional */
294         hda_nid_t hp_nid;               /* optional */
295         unsigned int num_adc_nids;
296         hda_nid_t *adc_nids;
297         hda_nid_t *capsrc_nids;
298         hda_nid_t dig_in_nid;
299         unsigned int num_channel_mode;
300         const struct hda_channel_mode *channel_mode;
301         int need_dac_fix;
302         unsigned int num_mux_defs;
303         const struct hda_input_mux *input_mux;
304         void (*unsol_event)(struct hda_codec *, unsigned int);
305         void (*init_hook)(struct hda_codec *);
306 #ifdef CONFIG_SND_HDA_POWER_SAVE
307         struct hda_amp_list *loopbacks;
308 #endif
309 };
310
311
312 /*
313  * input MUX handling
314  */
315 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
316                              struct snd_ctl_elem_info *uinfo)
317 {
318         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
319         struct alc_spec *spec = codec->spec;
320         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
321         if (mux_idx >= spec->num_mux_defs)
322                 mux_idx = 0;
323         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
324 }
325
326 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
327                             struct snd_ctl_elem_value *ucontrol)
328 {
329         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
330         struct alc_spec *spec = codec->spec;
331         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
332
333         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
334         return 0;
335 }
336
337 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
338                             struct snd_ctl_elem_value *ucontrol)
339 {
340         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
341         struct alc_spec *spec = codec->spec;
342         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
343         unsigned int mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
344         hda_nid_t nid = spec->capsrc_nids ?
345                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
346         return snd_hda_input_mux_put(codec, &spec->input_mux[mux_idx], ucontrol,
347                                      nid, &spec->cur_mux[adc_idx]);
348 }
349
350
351 /*
352  * channel mode setting
353  */
354 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
355                             struct snd_ctl_elem_info *uinfo)
356 {
357         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
358         struct alc_spec *spec = codec->spec;
359         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
360                                     spec->num_channel_mode);
361 }
362
363 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
364                            struct snd_ctl_elem_value *ucontrol)
365 {
366         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
367         struct alc_spec *spec = codec->spec;
368         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
369                                    spec->num_channel_mode,
370                                    spec->multiout.max_channels);
371 }
372
373 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
374                            struct snd_ctl_elem_value *ucontrol)
375 {
376         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
377         struct alc_spec *spec = codec->spec;
378         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
379                                       spec->num_channel_mode,
380                                       &spec->multiout.max_channels);
381         if (err >= 0 && spec->need_dac_fix)
382                 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
383         return err;
384 }
385
386 /*
387  * Control the mode of pin widget settings via the mixer.  "pc" is used
388  * instead of "%" to avoid consequences of accidently treating the % as 
389  * being part of a format specifier.  Maximum allowed length of a value is
390  * 63 characters plus NULL terminator.
391  *
392  * Note: some retasking pin complexes seem to ignore requests for input
393  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
394  * are requested.  Therefore order this list so that this behaviour will not
395  * cause problems when mixer clients move through the enum sequentially.
396  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
397  * March 2006.
398  */
399 static char *alc_pin_mode_names[] = {
400         "Mic 50pc bias", "Mic 80pc bias",
401         "Line in", "Line out", "Headphone out",
402 };
403 static unsigned char alc_pin_mode_values[] = {
404         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
405 };
406 /* The control can present all 5 options, or it can limit the options based
407  * in the pin being assumed to be exclusively an input or an output pin.  In
408  * addition, "input" pins may or may not process the mic bias option
409  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
410  * accept requests for bias as of chip versions up to March 2006) and/or
411  * wiring in the computer.
412  */
413 #define ALC_PIN_DIR_IN              0x00
414 #define ALC_PIN_DIR_OUT             0x01
415 #define ALC_PIN_DIR_INOUT           0x02
416 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
417 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
418
419 /* Info about the pin modes supported by the different pin direction modes. 
420  * For each direction the minimum and maximum values are given.
421  */
422 static signed char alc_pin_mode_dir_info[5][2] = {
423         { 0, 2 },    /* ALC_PIN_DIR_IN */
424         { 3, 4 },    /* ALC_PIN_DIR_OUT */
425         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
426         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
427         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
428 };
429 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
430 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
431 #define alc_pin_mode_n_items(_dir) \
432         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
433
434 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
435                              struct snd_ctl_elem_info *uinfo)
436 {
437         unsigned int item_num = uinfo->value.enumerated.item;
438         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
439
440         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
441         uinfo->count = 1;
442         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
443
444         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
445                 item_num = alc_pin_mode_min(dir);
446         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
447         return 0;
448 }
449
450 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
451                             struct snd_ctl_elem_value *ucontrol)
452 {
453         unsigned int i;
454         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
455         hda_nid_t nid = kcontrol->private_value & 0xffff;
456         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
457         long *valp = ucontrol->value.integer.value;
458         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
459                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
460                                                  0x00);
461
462         /* Find enumerated value for current pinctl setting */
463         i = alc_pin_mode_min(dir);
464         while (alc_pin_mode_values[i] != pinctl && i <= alc_pin_mode_max(dir))
465                 i++;
466         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
467         return 0;
468 }
469
470 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
471                             struct snd_ctl_elem_value *ucontrol)
472 {
473         signed int change;
474         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
475         hda_nid_t nid = kcontrol->private_value & 0xffff;
476         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
477         long val = *ucontrol->value.integer.value;
478         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
479                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
480                                                  0x00);
481
482         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
483                 val = alc_pin_mode_min(dir);
484
485         change = pinctl != alc_pin_mode_values[val];
486         if (change) {
487                 /* Set pin mode to that requested */
488                 snd_hda_codec_write_cache(codec, nid, 0,
489                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
490                                           alc_pin_mode_values[val]);
491
492                 /* Also enable the retasking pin's input/output as required 
493                  * for the requested pin mode.  Enum values of 2 or less are
494                  * input modes.
495                  *
496                  * Dynamically switching the input/output buffers probably
497                  * reduces noise slightly (particularly on input) so we'll
498                  * do it.  However, having both input and output buffers
499                  * enabled simultaneously doesn't seem to be problematic if
500                  * this turns out to be necessary in the future.
501                  */
502                 if (val <= 2) {
503                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
504                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
505                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
506                                                  HDA_AMP_MUTE, 0);
507                 } else {
508                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
509                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
510                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
511                                                  HDA_AMP_MUTE, 0);
512                 }
513         }
514         return change;
515 }
516
517 #define ALC_PIN_MODE(xname, nid, dir) \
518         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
519           .info = alc_pin_mode_info, \
520           .get = alc_pin_mode_get, \
521           .put = alc_pin_mode_put, \
522           .private_value = nid | (dir<<16) }
523
524 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
525  * together using a mask with more than one bit set.  This control is
526  * currently used only by the ALC260 test model.  At this stage they are not
527  * needed for any "production" models.
528  */
529 #ifdef CONFIG_SND_DEBUG
530 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
531
532 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
533                              struct snd_ctl_elem_value *ucontrol)
534 {
535         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
536         hda_nid_t nid = kcontrol->private_value & 0xffff;
537         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
538         long *valp = ucontrol->value.integer.value;
539         unsigned int val = snd_hda_codec_read(codec, nid, 0,
540                                               AC_VERB_GET_GPIO_DATA, 0x00);
541
542         *valp = (val & mask) != 0;
543         return 0;
544 }
545 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
546                              struct snd_ctl_elem_value *ucontrol)
547 {
548         signed int change;
549         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
550         hda_nid_t nid = kcontrol->private_value & 0xffff;
551         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
552         long val = *ucontrol->value.integer.value;
553         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
554                                                     AC_VERB_GET_GPIO_DATA,
555                                                     0x00);
556
557         /* Set/unset the masked GPIO bit(s) as needed */
558         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
559         if (val == 0)
560                 gpio_data &= ~mask;
561         else
562                 gpio_data |= mask;
563         snd_hda_codec_write_cache(codec, nid, 0,
564                                   AC_VERB_SET_GPIO_DATA, gpio_data);
565
566         return change;
567 }
568 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
569         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
570           .info = alc_gpio_data_info, \
571           .get = alc_gpio_data_get, \
572           .put = alc_gpio_data_put, \
573           .private_value = nid | (mask<<16) }
574 #endif   /* CONFIG_SND_DEBUG */
575
576 /* A switch control to allow the enabling of the digital IO pins on the
577  * ALC260.  This is incredibly simplistic; the intention of this control is
578  * to provide something in the test model allowing digital outputs to be
579  * identified if present.  If models are found which can utilise these
580  * outputs a more complete mixer control can be devised for those models if
581  * necessary.
582  */
583 #ifdef CONFIG_SND_DEBUG
584 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
585
586 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
587                               struct snd_ctl_elem_value *ucontrol)
588 {
589         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
590         hda_nid_t nid = kcontrol->private_value & 0xffff;
591         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
592         long *valp = ucontrol->value.integer.value;
593         unsigned int val = snd_hda_codec_read(codec, nid, 0,
594                                               AC_VERB_GET_DIGI_CONVERT_1, 0x00);
595
596         *valp = (val & mask) != 0;
597         return 0;
598 }
599 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
600                               struct snd_ctl_elem_value *ucontrol)
601 {
602         signed int change;
603         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
604         hda_nid_t nid = kcontrol->private_value & 0xffff;
605         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
606         long val = *ucontrol->value.integer.value;
607         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
608                                                     AC_VERB_GET_DIGI_CONVERT_1,
609                                                     0x00);
610
611         /* Set/unset the masked control bit(s) as needed */
612         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
613         if (val==0)
614                 ctrl_data &= ~mask;
615         else
616                 ctrl_data |= mask;
617         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
618                                   ctrl_data);
619
620         return change;
621 }
622 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
623         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
624           .info = alc_spdif_ctrl_info, \
625           .get = alc_spdif_ctrl_get, \
626           .put = alc_spdif_ctrl_put, \
627           .private_value = nid | (mask<<16) }
628 #endif   /* CONFIG_SND_DEBUG */
629
630 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
631  * Again, this is only used in the ALC26x test models to help identify when
632  * the EAPD line must be asserted for features to work.
633  */
634 #ifdef CONFIG_SND_DEBUG
635 #define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
636
637 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
638                               struct snd_ctl_elem_value *ucontrol)
639 {
640         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
641         hda_nid_t nid = kcontrol->private_value & 0xffff;
642         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
643         long *valp = ucontrol->value.integer.value;
644         unsigned int val = snd_hda_codec_read(codec, nid, 0,
645                                               AC_VERB_GET_EAPD_BTLENABLE, 0x00);
646
647         *valp = (val & mask) != 0;
648         return 0;
649 }
650
651 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
652                               struct snd_ctl_elem_value *ucontrol)
653 {
654         int change;
655         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
656         hda_nid_t nid = kcontrol->private_value & 0xffff;
657         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
658         long val = *ucontrol->value.integer.value;
659         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
660                                                     AC_VERB_GET_EAPD_BTLENABLE,
661                                                     0x00);
662
663         /* Set/unset the masked control bit(s) as needed */
664         change = (!val ? 0 : mask) != (ctrl_data & mask);
665         if (!val)
666                 ctrl_data &= ~mask;
667         else
668                 ctrl_data |= mask;
669         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
670                                   ctrl_data);
671
672         return change;
673 }
674
675 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
676         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
677           .info = alc_eapd_ctrl_info, \
678           .get = alc_eapd_ctrl_get, \
679           .put = alc_eapd_ctrl_put, \
680           .private_value = nid | (mask<<16) }
681 #endif   /* CONFIG_SND_DEBUG */
682
683 /*
684  * set up from the preset table
685  */
686 static void setup_preset(struct alc_spec *spec,
687                          const struct alc_config_preset *preset)
688 {
689         int i;
690
691         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
692                 spec->mixers[spec->num_mixers++] = preset->mixers[i];
693         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
694              i++)
695                 spec->init_verbs[spec->num_init_verbs++] =
696                         preset->init_verbs[i];
697         
698         spec->channel_mode = preset->channel_mode;
699         spec->num_channel_mode = preset->num_channel_mode;
700         spec->need_dac_fix = preset->need_dac_fix;
701
702         spec->multiout.max_channels = spec->channel_mode[0].channels;
703
704         spec->multiout.num_dacs = preset->num_dacs;
705         spec->multiout.dac_nids = preset->dac_nids;
706         spec->multiout.dig_out_nid = preset->dig_out_nid;
707         spec->multiout.hp_nid = preset->hp_nid;
708         
709         spec->num_mux_defs = preset->num_mux_defs;
710         if (!spec->num_mux_defs)
711                 spec->num_mux_defs = 1;
712         spec->input_mux = preset->input_mux;
713
714         spec->num_adc_nids = preset->num_adc_nids;
715         spec->adc_nids = preset->adc_nids;
716         spec->capsrc_nids = preset->capsrc_nids;
717         spec->dig_in_nid = preset->dig_in_nid;
718
719         spec->unsol_event = preset->unsol_event;
720         spec->init_hook = preset->init_hook;
721 #ifdef CONFIG_SND_HDA_POWER_SAVE
722         spec->loopback.amplist = preset->loopbacks;
723 #endif
724 }
725
726 /* Enable GPIO mask and set output */
727 static struct hda_verb alc_gpio1_init_verbs[] = {
728         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
729         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
730         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
731         { }
732 };
733
734 static struct hda_verb alc_gpio2_init_verbs[] = {
735         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
736         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
737         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
738         { }
739 };
740
741 static struct hda_verb alc_gpio3_init_verbs[] = {
742         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
743         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
744         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
745         { }
746 };
747
748 static void alc_sku_automute(struct hda_codec *codec)
749 {
750         struct alc_spec *spec = codec->spec;
751         unsigned int present;
752         unsigned int hp_nid = spec->autocfg.hp_pins[0];
753         unsigned int sp_nid = spec->autocfg.speaker_pins[0];
754
755         /* need to execute and sync at first */
756         snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
757         present = snd_hda_codec_read(codec, hp_nid, 0,
758                                      AC_VERB_GET_PIN_SENSE, 0);
759         spec->jack_present = (present & 0x80000000) != 0;
760         snd_hda_codec_write(codec, sp_nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
761                             spec->jack_present ? 0 : PIN_OUT);
762 }
763
764 /* unsolicited event for HP jack sensing */
765 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
766 {
767         if (codec->vendor_id == 0x10ec0880)
768                 res >>= 28;
769         else
770                 res >>= 26;
771         if (res != ALC880_HP_EVENT)
772                 return;
773
774         alc_sku_automute(codec);
775 }
776
777 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
778  *      31 ~ 16 :       Manufacture ID
779  *      15 ~ 8  :       SKU ID
780  *      7  ~ 0  :       Assembly ID
781  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
782  */
783 static void alc_subsystem_id(struct hda_codec *codec,
784                              unsigned int porta, unsigned int porte,
785                              unsigned int portd)
786 {
787         unsigned int ass, tmp, i;
788         unsigned nid;
789         struct alc_spec *spec = codec->spec;
790
791         ass = codec->subsystem_id & 0xffff;
792         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
793                 goto do_sku;
794
795         /*      
796          * 31~30        : port conetcivity
797          * 29~21        : reserve
798          * 20           : PCBEEP input
799          * 19~16        : Check sum (15:1)
800          * 15~1         : Custom
801          * 0            : override
802         */
803         nid = 0x1d;
804         if (codec->vendor_id == 0x10ec0260)
805                 nid = 0x17;
806         ass = snd_hda_codec_read(codec, nid, 0,
807                                  AC_VERB_GET_CONFIG_DEFAULT, 0);
808         if (!(ass & 1) && !(ass & 0x100000))
809                 return;
810         if ((ass >> 30) != 1)   /* no physical connection */
811                 return;
812
813         /* check sum */
814         tmp = 0;
815         for (i = 1; i < 16; i++) {
816                 if ((ass >> i) & 1)
817                         tmp++;
818         }
819         if (((ass >> 16) & 0xf) != tmp)
820                 return;
821 do_sku:
822         /*
823          * 0 : override
824          * 1 :  Swap Jack
825          * 2 : 0 --> Desktop, 1 --> Laptop
826          * 3~5 : External Amplifier control
827          * 7~6 : Reserved
828         */
829         tmp = (ass & 0x38) >> 3;        /* external Amp control */
830         switch (tmp) {
831         case 1:
832                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
833                 break;
834         case 3:
835                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
836                 break;
837         case 7:
838                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
839                 break;
840         case 5: /* set EAPD output high */
841                 switch (codec->vendor_id) {
842                 case 0x10ec0260:
843                         snd_hda_codec_write(codec, 0x0f, 0,
844                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
845                         snd_hda_codec_write(codec, 0x10, 0,
846                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
847                         break;
848                 case 0x10ec0262:
849                 case 0x10ec0267:
850                 case 0x10ec0268:
851                 case 0x10ec0269:
852                 case 0x10ec0862:
853                 case 0x10ec0662:        
854                         snd_hda_codec_write(codec, 0x14, 0,
855                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
856                         snd_hda_codec_write(codec, 0x15, 0,
857                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
858                         break;
859                 }
860                 switch (codec->vendor_id) {
861                 case 0x10ec0260:
862                         snd_hda_codec_write(codec, 0x1a, 0,
863                                             AC_VERB_SET_COEF_INDEX, 7);
864                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
865                                                  AC_VERB_GET_PROC_COEF, 0);
866                         snd_hda_codec_write(codec, 0x1a, 0,
867                                             AC_VERB_SET_COEF_INDEX, 7);
868                         snd_hda_codec_write(codec, 0x1a, 0,
869                                             AC_VERB_SET_PROC_COEF,
870                                             tmp | 0x2010);
871                         break;
872                 case 0x10ec0262:
873                 case 0x10ec0880:
874                 case 0x10ec0882:
875                 case 0x10ec0883:
876                 case 0x10ec0885:
877                 case 0x10ec0888:
878                         snd_hda_codec_write(codec, 0x20, 0,
879                                             AC_VERB_SET_COEF_INDEX, 7);
880                         tmp = snd_hda_codec_read(codec, 0x20, 0,
881                                                  AC_VERB_GET_PROC_COEF, 0);
882                         snd_hda_codec_write(codec, 0x20, 0,
883                                             AC_VERB_SET_COEF_INDEX, 7); 
884                         snd_hda_codec_write(codec, 0x20, 0,
885                                             AC_VERB_SET_PROC_COEF,
886                                             tmp | 0x2010);
887                         break;
888                 case 0x10ec0267:
889                 case 0x10ec0268:
890                         snd_hda_codec_write(codec, 0x20, 0,
891                                             AC_VERB_SET_COEF_INDEX, 7);
892                         tmp = snd_hda_codec_read(codec, 0x20, 0,
893                                                  AC_VERB_GET_PROC_COEF, 0);
894                         snd_hda_codec_write(codec, 0x20, 0,
895                                             AC_VERB_SET_COEF_INDEX, 7); 
896                         snd_hda_codec_write(codec, 0x20, 0,
897                                             AC_VERB_SET_PROC_COEF,
898                                             tmp | 0x3000);
899                         break;
900                 }
901         default:
902                 break;
903         }
904         
905         /* is laptop or Desktop and enable the function "Mute internal speaker
906          * when the external headphone out jack is plugged"
907          */
908         if (!(ass & 0x8000))
909                 return;
910         /*
911          * 10~8 : Jack location
912          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
913          * 14~13: Resvered
914          * 15   : 1 --> enable the function "Mute internal speaker
915          *              when the external headphone out jack is plugged"
916          */
917         if (!spec->autocfg.speaker_pins[0]) {
918                 if (spec->autocfg.line_out_pins[0])
919                         spec->autocfg.speaker_pins[0] =
920                                 spec->autocfg.line_out_pins[0];
921                 else
922                         return;
923         }
924
925         if (!spec->autocfg.hp_pins[0]) {
926                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
927                 if (tmp == 0)
928                         spec->autocfg.hp_pins[0] = porta;
929                 else if (tmp == 1)
930                         spec->autocfg.hp_pins[0] = porte;
931                 else if (tmp == 2)
932                         spec->autocfg.hp_pins[0] = portd;
933                 else
934                         return;
935         }
936
937         snd_hda_codec_write(codec, spec->autocfg.hp_pins[0], 0,
938                             AC_VERB_SET_UNSOLICITED_ENABLE,
939                             AC_USRSP_EN | ALC880_HP_EVENT);
940         spec->unsol_event = alc_sku_unsol_event;
941         spec->init_hook = alc_sku_automute;     
942 }
943
944 /*
945  * Fix-up pin default configurations
946  */
947
948 struct alc_pincfg {
949         hda_nid_t nid;
950         u32 val;
951 };
952
953 static void alc_fix_pincfg(struct hda_codec *codec,
954                            const struct snd_pci_quirk *quirk,
955                            const struct alc_pincfg **pinfix)
956 {
957         const struct alc_pincfg *cfg;
958
959         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
960         if (!quirk)
961                 return;
962
963         cfg = pinfix[quirk->value];
964         for (; cfg->nid; cfg++) {
965                 int i;
966                 u32 val = cfg->val;
967                 for (i = 0; i < 4; i++) {
968                         snd_hda_codec_write(codec, cfg->nid, 0,
969                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0 + i,
970                                     val & 0xff);
971                         val >>= 8;
972                 }
973         }
974 }
975
976 /*
977  * ALC880 3-stack model
978  *
979  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
980  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
981  *                 F-Mic = 0x1b, HP = 0x19
982  */
983
984 static hda_nid_t alc880_dac_nids[4] = {
985         /* front, rear, clfe, rear_surr */
986         0x02, 0x05, 0x04, 0x03
987 };
988
989 static hda_nid_t alc880_adc_nids[3] = {
990         /* ADC0-2 */
991         0x07, 0x08, 0x09,
992 };
993
994 /* The datasheet says the node 0x07 is connected from inputs,
995  * but it shows zero connection in the real implementation on some devices.
996  * Note: this is a 915GAV bug, fixed on 915GLV
997  */
998 static hda_nid_t alc880_adc_nids_alt[2] = {
999         /* ADC1-2 */
1000         0x08, 0x09,
1001 };
1002
1003 #define ALC880_DIGOUT_NID       0x06
1004 #define ALC880_DIGIN_NID        0x0a
1005
1006 static struct hda_input_mux alc880_capture_source = {
1007         .num_items = 4,
1008         .items = {
1009                 { "Mic", 0x0 },
1010                 { "Front Mic", 0x3 },
1011                 { "Line", 0x2 },
1012                 { "CD", 0x4 },
1013         },
1014 };
1015
1016 /* channel source setting (2/6 channel selection for 3-stack) */
1017 /* 2ch mode */
1018 static struct hda_verb alc880_threestack_ch2_init[] = {
1019         /* set line-in to input, mute it */
1020         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1021         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1022         /* set mic-in to input vref 80%, mute it */
1023         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1024         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1025         { } /* end */
1026 };
1027
1028 /* 6ch mode */
1029 static struct hda_verb alc880_threestack_ch6_init[] = {
1030         /* set line-in to output, unmute it */
1031         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1032         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1033         /* set mic-in to output, unmute it */
1034         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1035         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1036         { } /* end */
1037 };
1038
1039 static struct hda_channel_mode alc880_threestack_modes[2] = {
1040         { 2, alc880_threestack_ch2_init },
1041         { 6, alc880_threestack_ch6_init },
1042 };
1043
1044 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1045         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1046         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1047         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1048         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1049         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1050         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1051         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1052         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1053         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1054         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1055         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1056         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1057         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1058         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1059         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
1060         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
1061         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1062         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1063         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
1064         {
1065                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1066                 .name = "Channel Mode",
1067                 .info = alc_ch_mode_info,
1068                 .get = alc_ch_mode_get,
1069                 .put = alc_ch_mode_put,
1070         },
1071         { } /* end */
1072 };
1073
1074 /* capture mixer elements */
1075 static struct snd_kcontrol_new alc880_capture_mixer[] = {
1076         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
1077         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
1078         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
1079         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
1080         HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
1081         HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
1082         {
1083                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1084                 /* The multiple "Capture Source" controls confuse alsamixer
1085                  * So call somewhat different..
1086                  */
1087                 /* .name = "Capture Source", */
1088                 .name = "Input Source",
1089                 .count = 3,
1090                 .info = alc_mux_enum_info,
1091                 .get = alc_mux_enum_get,
1092                 .put = alc_mux_enum_put,
1093         },
1094         { } /* end */
1095 };
1096
1097 /* capture mixer elements (in case NID 0x07 not available) */
1098 static struct snd_kcontrol_new alc880_capture_alt_mixer[] = {
1099         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1100         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1101         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
1102         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
1103         {
1104                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1105                 /* The multiple "Capture Source" controls confuse alsamixer
1106                  * So call somewhat different..
1107                  */
1108                 /* .name = "Capture Source", */
1109                 .name = "Input Source",
1110                 .count = 2,
1111                 .info = alc_mux_enum_info,
1112                 .get = alc_mux_enum_get,
1113                 .put = alc_mux_enum_put,
1114         },
1115         { } /* end */
1116 };
1117
1118
1119
1120 /*
1121  * ALC880 5-stack model
1122  *
1123  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
1124  *      Side = 0x02 (0xd)
1125  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
1126  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
1127  */
1128
1129 /* additional mixers to alc880_three_stack_mixer */
1130 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
1131         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1132         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
1133         { } /* end */
1134 };
1135
1136 /* channel source setting (6/8 channel selection for 5-stack) */
1137 /* 6ch mode */
1138 static struct hda_verb alc880_fivestack_ch6_init[] = {
1139         /* set line-in to input, mute it */
1140         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1141         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1142         { } /* end */
1143 };
1144
1145 /* 8ch mode */
1146 static struct hda_verb alc880_fivestack_ch8_init[] = {
1147         /* set line-in to output, unmute it */
1148         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1149         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1150         { } /* end */
1151 };
1152
1153 static struct hda_channel_mode alc880_fivestack_modes[2] = {
1154         { 6, alc880_fivestack_ch6_init },
1155         { 8, alc880_fivestack_ch8_init },
1156 };
1157
1158
1159 /*
1160  * ALC880 6-stack model
1161  *
1162  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
1163  *      Side = 0x05 (0x0f)
1164  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
1165  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
1166  */
1167
1168 static hda_nid_t alc880_6st_dac_nids[4] = {
1169         /* front, rear, clfe, rear_surr */
1170         0x02, 0x03, 0x04, 0x05
1171 };
1172
1173 static struct hda_input_mux alc880_6stack_capture_source = {
1174         .num_items = 4,
1175         .items = {
1176                 { "Mic", 0x0 },
1177                 { "Front Mic", 0x1 },
1178                 { "Line", 0x2 },
1179                 { "CD", 0x4 },
1180         },
1181 };
1182
1183 /* fixed 8-channels */
1184 static struct hda_channel_mode alc880_sixstack_modes[1] = {
1185         { 8, NULL },
1186 };
1187
1188 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
1189         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1190         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1191         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1192         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1193         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1194         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1195         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1196         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1197         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1198         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1199         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1200         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1201         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1202         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1203         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1204         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1205         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1206         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1207         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1208         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1209         {
1210                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1211                 .name = "Channel Mode",
1212                 .info = alc_ch_mode_info,
1213                 .get = alc_ch_mode_get,
1214                 .put = alc_ch_mode_put,
1215         },
1216         { } /* end */
1217 };
1218
1219
1220 /*
1221  * ALC880 W810 model
1222  *
1223  * W810 has rear IO for:
1224  * Front (DAC 02)
1225  * Surround (DAC 03)
1226  * Center/LFE (DAC 04)
1227  * Digital out (06)
1228  *
1229  * The system also has a pair of internal speakers, and a headphone jack.
1230  * These are both connected to Line2 on the codec, hence to DAC 02.
1231  * 
1232  * There is a variable resistor to control the speaker or headphone
1233  * volume. This is a hardware-only device without a software API.
1234  *
1235  * Plugging headphones in will disable the internal speakers. This is
1236  * implemented in hardware, not via the driver using jack sense. In
1237  * a similar fashion, plugging into the rear socket marked "front" will
1238  * disable both the speakers and headphones.
1239  *
1240  * For input, there's a microphone jack, and an "audio in" jack.
1241  * These may not do anything useful with this driver yet, because I
1242  * haven't setup any initialization verbs for these yet...
1243  */
1244
1245 static hda_nid_t alc880_w810_dac_nids[3] = {
1246         /* front, rear/surround, clfe */
1247         0x02, 0x03, 0x04
1248 };
1249
1250 /* fixed 6 channels */
1251 static struct hda_channel_mode alc880_w810_modes[1] = {
1252         { 6, NULL }
1253 };
1254
1255 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
1256 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
1257         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1258         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1259         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1260         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1261         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1262         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1263         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1264         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1265         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1266         { } /* end */
1267 };
1268
1269
1270 /*
1271  * Z710V model
1272  *
1273  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
1274  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
1275  *                 Line = 0x1a
1276  */
1277
1278 static hda_nid_t alc880_z71v_dac_nids[1] = {
1279         0x02
1280 };
1281 #define ALC880_Z71V_HP_DAC      0x03
1282
1283 /* fixed 2 channels */
1284 static struct hda_channel_mode alc880_2_jack_modes[1] = {
1285         { 2, NULL }
1286 };
1287
1288 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
1289         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1290         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1291         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1292         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
1293         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1294         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1295         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1296         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1297         { } /* end */
1298 };
1299
1300
1301 /*
1302  * ALC880 F1734 model
1303  *
1304  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
1305  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
1306  */
1307
1308 static hda_nid_t alc880_f1734_dac_nids[1] = {
1309         0x03
1310 };
1311 #define ALC880_F1734_HP_DAC     0x02
1312
1313 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
1314         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1315         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1316         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1317         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1318         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1319         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1320         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1321         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1322         { } /* end */
1323 };
1324
1325 static struct hda_input_mux alc880_f1734_capture_source = {
1326         .num_items = 2,
1327         .items = {
1328                 { "Mic", 0x1 },
1329                 { "CD", 0x4 },
1330         },
1331 };
1332
1333
1334 /*
1335  * ALC880 ASUS model
1336  *
1337  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1338  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1339  *  Mic = 0x18, Line = 0x1a
1340  */
1341
1342 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
1343 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
1344
1345 static struct snd_kcontrol_new alc880_asus_mixer[] = {
1346         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1347         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1348         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1349         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1350         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1351         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1352         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1353         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1354         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1355         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1356         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1357         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1358         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1359         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1360         {
1361                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1362                 .name = "Channel Mode",
1363                 .info = alc_ch_mode_info,
1364                 .get = alc_ch_mode_get,
1365                 .put = alc_ch_mode_put,
1366         },
1367         { } /* end */
1368 };
1369
1370 /*
1371  * ALC880 ASUS W1V model
1372  *
1373  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1374  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1375  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
1376  */
1377
1378 /* additional mixers to alc880_asus_mixer */
1379 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
1380         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
1381         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
1382         { } /* end */
1383 };
1384
1385 /* additional mixers to alc880_asus_mixer */
1386 static struct snd_kcontrol_new alc880_pcbeep_mixer[] = {
1387         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1388         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1389         { } /* end */
1390 };
1391
1392 /* TCL S700 */
1393 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
1394         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1395         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1396         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1397         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
1398         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
1399         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
1400         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
1401         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1402         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1403         {
1404                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1405                 /* The multiple "Capture Source" controls confuse alsamixer
1406                  * So call somewhat different..
1407                  */
1408                 /* .name = "Capture Source", */
1409                 .name = "Input Source",
1410                 .count = 1,
1411                 .info = alc_mux_enum_info,
1412                 .get = alc_mux_enum_get,
1413                 .put = alc_mux_enum_put,
1414         },
1415         { } /* end */
1416 };
1417
1418 /* Uniwill */
1419 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
1420         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1421         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1422         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1423         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1424         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1425         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1426         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1427         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1428         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1429         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1430         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1431         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1432         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1433         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1434         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1435         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1436         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1437         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1438         {
1439                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1440                 .name = "Channel Mode",
1441                 .info = alc_ch_mode_info,
1442                 .get = alc_ch_mode_get,
1443                 .put = alc_ch_mode_put,
1444         },
1445         { } /* end */
1446 };
1447
1448 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
1449         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1450         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1451         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1452         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1453         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1454         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1455         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1456         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1457         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1458         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1459         { } /* end */
1460 };
1461
1462 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
1463         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1464         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1465         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1466         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1467         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1468         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1469         { } /* end */
1470 };
1471
1472 /*
1473  * virtual master controls
1474  */
1475
1476 /*
1477  * slave controls for virtual master
1478  */
1479 static const char *alc_slave_vols[] = {
1480         "Front Playback Volume",
1481         "Surround Playback Volume",
1482         "Center Playback Volume",
1483         "LFE Playback Volume",
1484         "Side Playback Volume",
1485         "Headphone Playback Volume",
1486         "Speaker Playback Volume",
1487         "Mono Playback Volume",
1488         "Line-Out Playback Volume",
1489         NULL,
1490 };
1491
1492 static const char *alc_slave_sws[] = {
1493         "Front Playback Switch",
1494         "Surround Playback Switch",
1495         "Center Playback Switch",
1496         "LFE Playback Switch",
1497         "Side Playback Switch",
1498         "Headphone Playback Switch",
1499         "Speaker Playback Switch",
1500         "Mono Playback Switch",
1501         "IEC958 Playback Switch",
1502         NULL,
1503 };
1504
1505 /*
1506  * build control elements
1507  */
1508 static int alc_build_controls(struct hda_codec *codec)
1509 {
1510         struct alc_spec *spec = codec->spec;
1511         int err;
1512         int i;
1513
1514         for (i = 0; i < spec->num_mixers; i++) {
1515                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1516                 if (err < 0)
1517                         return err;
1518         }
1519
1520         if (spec->multiout.dig_out_nid) {
1521                 err = snd_hda_create_spdif_out_ctls(codec,
1522                                                     spec->multiout.dig_out_nid);
1523                 if (err < 0)
1524                         return err;
1525                 err = snd_hda_create_spdif_share_sw(codec,
1526                                                     &spec->multiout);
1527                 if (err < 0)
1528                         return err;
1529                 spec->multiout.share_spdif = 1;
1530         }
1531         if (spec->dig_in_nid) {
1532                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1533                 if (err < 0)
1534                         return err;
1535         }
1536
1537         /* if we have no master control, let's create it */
1538         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1539                 unsigned int vmaster_tlv[4];
1540                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1541                                         HDA_OUTPUT, vmaster_tlv);
1542                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1543                                           vmaster_tlv, alc_slave_vols);
1544                 if (err < 0)
1545                         return err;
1546         }
1547         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1548                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1549                                           NULL, alc_slave_sws);
1550                 if (err < 0)
1551                         return err;
1552         }
1553
1554         return 0;
1555 }
1556
1557
1558 /*
1559  * initialize the codec volumes, etc
1560  */
1561
1562 /*
1563  * generic initialization of ADC, input mixers and output mixers
1564  */
1565 static struct hda_verb alc880_volume_init_verbs[] = {
1566         /*
1567          * Unmute ADC0-2 and set the default input to mic-in
1568          */
1569         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
1570         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1571         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
1572         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1573         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
1574         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1575
1576         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1577          * mixer widget
1578          * Note: PASD motherboards uses the Line In 2 as the input for front
1579          * panel mic (mic 2)
1580          */
1581         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
1582         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1583         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1584         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
1585         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
1586         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
1587         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
1588         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
1589
1590         /*
1591          * Set up output mixers (0x0c - 0x0f)
1592          */
1593         /* set vol=0 to output mixers */
1594         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1595         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1596         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1597         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1598         /* set up input amps for analog loopback */
1599         /* Amp Indices: DAC = 0, mixer = 1 */
1600         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1601         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1602         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1603         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1604         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1605         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1606         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1607         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1608
1609         { }
1610 };
1611
1612 /*
1613  * 3-stack pin configuration:
1614  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
1615  */
1616 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
1617         /*
1618          * preset connection lists of input pins
1619          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1620          */
1621         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
1622         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1623         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
1624
1625         /*
1626          * Set pin mode and muting
1627          */
1628         /* set front pin widgets 0x14 for output */
1629         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1630         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1631         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1632         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1633         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1634         /* Mic2 (as headphone out) for HP output */
1635         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1636         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1637         /* Line In pin widget for input */
1638         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1639         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1640         /* Line2 (as front mic) pin widget for input and vref at 80% */
1641         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1642         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1643         /* CD pin widget for input */
1644         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1645
1646         { }
1647 };
1648
1649 /*
1650  * 5-stack pin configuration:
1651  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
1652  * line-in/side = 0x1a, f-mic = 0x1b
1653  */
1654 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
1655         /*
1656          * preset connection lists of input pins
1657          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1658          */
1659         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1660         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
1661
1662         /*
1663          * Set pin mode and muting
1664          */
1665         /* set pin widgets 0x14-0x17 for output */
1666         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1667         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1668         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1669         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1670         /* unmute pins for output (no gain on this amp) */
1671         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1672         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1673         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1674         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1675
1676         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1677         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1678         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1679         /* Mic2 (as headphone out) for HP output */
1680         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1681         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1682         /* Line In pin widget for input */
1683         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1684         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1685         /* Line2 (as front mic) pin widget for input and vref at 80% */
1686         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1687         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1688         /* CD pin widget for input */
1689         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1690
1691         { }
1692 };
1693
1694 /*
1695  * W810 pin configuration:
1696  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
1697  */
1698 static struct hda_verb alc880_pin_w810_init_verbs[] = {
1699         /* hphone/speaker input selector: front DAC */
1700         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
1701
1702         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1703         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1704         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1705         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1706         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1707         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1708
1709         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1710         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1711
1712         { }
1713 };
1714
1715 /*
1716  * Z71V pin configuration:
1717  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
1718  */
1719 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
1720         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1721         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1722         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1723         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1724
1725         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1726         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1727         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1728         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1729
1730         { }
1731 };
1732
1733 /*
1734  * 6-stack pin configuration:
1735  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
1736  * f-mic = 0x19, line = 0x1a, HP = 0x1b
1737  */
1738 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
1739         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1740
1741         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1742         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1743         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1744         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1745         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1746         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1747         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1748         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1749
1750         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1751         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1752         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1753         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1754         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1755         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1756         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1757         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1758         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1759         
1760         { }
1761 };
1762
1763 /*
1764  * Uniwill pin configuration:
1765  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
1766  * line = 0x1a
1767  */
1768 static struct hda_verb alc880_uniwill_init_verbs[] = {
1769         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1770
1771         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1772         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1773         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1774         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1775         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1776         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1777         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1778         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1779         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1780         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1781         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1782         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1783         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1784         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1785
1786         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1787         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1788         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1789         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1790         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1791         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1792         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
1793         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
1794         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1795
1796         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
1797         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
1798
1799         { }
1800 };
1801
1802 /*
1803 * Uniwill P53
1804 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19, 
1805  */
1806 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
1807         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1808
1809         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1810         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1811         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1812         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1813         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1814         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1815         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1816         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1817         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1818         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1819         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1820         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1821
1822         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1823         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1824         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1825         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1826         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1827         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1828
1829         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
1830         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
1831
1832         { }
1833 };
1834
1835 static struct hda_verb alc880_beep_init_verbs[] = {
1836         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
1837         { }
1838 };
1839
1840 /* toggle speaker-output according to the hp-jack state */
1841 static void alc880_uniwill_hp_automute(struct hda_codec *codec)
1842 {
1843         unsigned int present;
1844         unsigned char bits;
1845
1846         present = snd_hda_codec_read(codec, 0x14, 0,
1847                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1848         bits = present ? HDA_AMP_MUTE : 0;
1849         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
1850                                  HDA_AMP_MUTE, bits);
1851         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
1852                                  HDA_AMP_MUTE, bits);
1853 }
1854
1855 /* auto-toggle front mic */
1856 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
1857 {
1858         unsigned int present;
1859         unsigned char bits;
1860
1861         present = snd_hda_codec_read(codec, 0x18, 0,
1862                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1863         bits = present ? HDA_AMP_MUTE : 0;
1864         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
1865 }
1866
1867 static void alc880_uniwill_automute(struct hda_codec *codec)
1868 {
1869         alc880_uniwill_hp_automute(codec);
1870         alc880_uniwill_mic_automute(codec);
1871 }
1872
1873 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
1874                                        unsigned int res)
1875 {
1876         /* Looks like the unsol event is incompatible with the standard
1877          * definition.  4bit tag is placed at 28 bit!
1878          */
1879         switch (res >> 28) {
1880         case ALC880_HP_EVENT:
1881                 alc880_uniwill_hp_automute(codec);
1882                 break;
1883         case ALC880_MIC_EVENT:
1884                 alc880_uniwill_mic_automute(codec);
1885                 break;
1886         }
1887 }
1888
1889 static void alc880_uniwill_p53_hp_automute(struct hda_codec *codec)
1890 {
1891         unsigned int present;
1892         unsigned char bits;
1893
1894         present = snd_hda_codec_read(codec, 0x14, 0,
1895                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1896         bits = present ? HDA_AMP_MUTE : 0;
1897         snd_hda_codec_amp_stereo(codec, 0x15, HDA_INPUT, 0, HDA_AMP_MUTE, bits);
1898 }
1899
1900 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
1901 {
1902         unsigned int present;
1903         
1904         present = snd_hda_codec_read(codec, 0x21, 0,
1905                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
1906         present &= HDA_AMP_VOLMASK;
1907         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
1908                                  HDA_AMP_VOLMASK, present);
1909         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
1910                                  HDA_AMP_VOLMASK, present);
1911 }
1912
1913 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
1914                                            unsigned int res)
1915 {
1916         /* Looks like the unsol event is incompatible with the standard
1917          * definition.  4bit tag is placed at 28 bit!
1918          */
1919         if ((res >> 28) == ALC880_HP_EVENT)
1920                 alc880_uniwill_p53_hp_automute(codec);
1921         if ((res >> 28) == ALC880_DCVOL_EVENT)
1922                 alc880_uniwill_p53_dcvol_automute(codec);
1923 }
1924
1925 /*
1926  * F1734 pin configuration:
1927  * HP = 0x14, speaker-out = 0x15, mic = 0x18
1928  */
1929 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
1930         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
1931         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
1932         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
1933         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
1934         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
1935
1936         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1937         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1938         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1939         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1940
1941         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1942         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1943         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
1944         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1945         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1946         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1947         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1948         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1949         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1950
1951         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
1952         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
1953
1954         { }
1955 };
1956
1957 /*
1958  * ASUS pin configuration:
1959  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
1960  */
1961 static struct hda_verb alc880_pin_asus_init_verbs[] = {
1962         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
1963         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
1964         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
1965         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
1966
1967         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1968         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1969         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1970         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1971         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1972         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1973         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1974         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1975
1976         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1977         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1978         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1979         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1980         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1981         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1982         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1983         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1984         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1985         
1986         { }
1987 };
1988
1989 /* Enable GPIO mask and set output */
1990 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
1991 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
1992
1993 /* Clevo m520g init */
1994 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
1995         /* headphone output */
1996         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
1997         /* line-out */
1998         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1999         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2000         /* Line-in */
2001         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2002         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2003         /* CD */
2004         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2005         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2006         /* Mic1 (rear panel) */
2007         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2008         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2009         /* Mic2 (front panel) */
2010         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2011         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2012         /* headphone */
2013         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2014         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2015         /* change to EAPD mode */
2016         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2017         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2018
2019         { }
2020 };
2021
2022 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
2023         /* change to EAPD mode */
2024         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2025         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2026
2027         /* Headphone output */
2028         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2029         /* Front output*/
2030         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2031         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2032
2033         /* Line In pin widget for input */
2034         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2035         /* CD pin widget for input */
2036         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2037         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2038         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2039
2040         /* change to EAPD mode */
2041         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2042         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
2043
2044         { }
2045 };
2046
2047 /*
2048  * LG m1 express dual
2049  *
2050  * Pin assignment:
2051  *   Rear Line-In/Out (blue): 0x14
2052  *   Build-in Mic-In: 0x15
2053  *   Speaker-out: 0x17
2054  *   HP-Out (green): 0x1b
2055  *   Mic-In/Out (red): 0x19
2056  *   SPDIF-Out: 0x1e
2057  */
2058
2059 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
2060 static hda_nid_t alc880_lg_dac_nids[3] = {
2061         0x05, 0x02, 0x03
2062 };
2063
2064 /* seems analog CD is not working */
2065 static struct hda_input_mux alc880_lg_capture_source = {
2066         .num_items = 3,
2067         .items = {
2068                 { "Mic", 0x1 },
2069                 { "Line", 0x5 },
2070                 { "Internal Mic", 0x6 },
2071         },
2072 };
2073
2074 /* 2,4,6 channel modes */
2075 static struct hda_verb alc880_lg_ch2_init[] = {
2076         /* set line-in and mic-in to input */
2077         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2078         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2079         { }
2080 };
2081
2082 static struct hda_verb alc880_lg_ch4_init[] = {
2083         /* set line-in to out and mic-in to input */
2084         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2085         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2086         { }
2087 };
2088
2089 static struct hda_verb alc880_lg_ch6_init[] = {
2090         /* set line-in and mic-in to output */
2091         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2092         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2093         { }
2094 };
2095
2096 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
2097         { 2, alc880_lg_ch2_init },
2098         { 4, alc880_lg_ch4_init },
2099         { 6, alc880_lg_ch6_init },
2100 };
2101
2102 static struct snd_kcontrol_new alc880_lg_mixer[] = {
2103         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2104         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
2105         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2106         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
2107         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
2108         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
2109         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
2110         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
2111         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2112         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2113         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
2114         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
2115         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
2116         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
2117         {
2118                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2119                 .name = "Channel Mode",
2120                 .info = alc_ch_mode_info,
2121                 .get = alc_ch_mode_get,
2122                 .put = alc_ch_mode_put,
2123         },
2124         { } /* end */
2125 };
2126
2127 static struct hda_verb alc880_lg_init_verbs[] = {
2128         /* set capture source to mic-in */
2129         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2130         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2131         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2132         /* mute all amp mixer inputs */
2133         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
2134         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2135         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2136         /* line-in to input */
2137         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2138         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2139         /* built-in mic */
2140         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2141         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2142         /* speaker-out */
2143         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2144         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2145         /* mic-in to input */
2146         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2147         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2148         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2149         /* HP-out */
2150         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
2151         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2152         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2153         /* jack sense */
2154         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2155         { }
2156 };
2157
2158 /* toggle speaker-output according to the hp-jack state */
2159 static void alc880_lg_automute(struct hda_codec *codec)
2160 {
2161         unsigned int present;
2162         unsigned char bits;
2163
2164         present = snd_hda_codec_read(codec, 0x1b, 0,
2165                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2166         bits = present ? HDA_AMP_MUTE : 0;
2167         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
2168                                  HDA_AMP_MUTE, bits);
2169 }
2170
2171 static void alc880_lg_unsol_event(struct hda_codec *codec, unsigned int res)
2172 {
2173         /* Looks like the unsol event is incompatible with the standard
2174          * definition.  4bit tag is placed at 28 bit!
2175          */
2176         if ((res >> 28) == 0x01)
2177                 alc880_lg_automute(codec);
2178 }
2179
2180 /*
2181  * LG LW20
2182  *
2183  * Pin assignment:
2184  *   Speaker-out: 0x14
2185  *   Mic-In: 0x18
2186  *   Built-in Mic-In: 0x19
2187  *   Line-In: 0x1b
2188  *   HP-Out: 0x1a
2189  *   SPDIF-Out: 0x1e
2190  */
2191
2192 static struct hda_input_mux alc880_lg_lw_capture_source = {
2193         .num_items = 3,
2194         .items = {
2195                 { "Mic", 0x0 },
2196                 { "Internal Mic", 0x1 },
2197                 { "Line In", 0x2 },
2198         },
2199 };
2200
2201 #define alc880_lg_lw_modes alc880_threestack_modes
2202
2203 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
2204         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2205         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2206         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2207         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
2208         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2209         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2210         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2211         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2212         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2213         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2214         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2215         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2216         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
2217         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
2218         {
2219                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2220                 .name = "Channel Mode",
2221                 .info = alc_ch_mode_info,
2222                 .get = alc_ch_mode_get,
2223                 .put = alc_ch_mode_put,
2224         },
2225         { } /* end */
2226 };
2227
2228 static struct hda_verb alc880_lg_lw_init_verbs[] = {
2229         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2230         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2231         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2232
2233         /* set capture source to mic-in */
2234         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2235         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2236         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2237         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2238         /* speaker-out */
2239         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2240         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2241         /* HP-out */
2242         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2243         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2244         /* mic-in to input */
2245         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2246         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2247         /* built-in mic */
2248         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2249         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2250         /* jack sense */
2251         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2252         { }
2253 };
2254
2255 /* toggle speaker-output according to the hp-jack state */
2256 static void alc880_lg_lw_automute(struct hda_codec *codec)
2257 {
2258         unsigned int present;
2259         unsigned char bits;
2260
2261         present = snd_hda_codec_read(codec, 0x1b, 0,
2262                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2263         bits = present ? HDA_AMP_MUTE : 0;
2264         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
2265                                  HDA_AMP_MUTE, bits);
2266 }
2267
2268 static void alc880_lg_lw_unsol_event(struct hda_codec *codec, unsigned int res)
2269 {
2270         /* Looks like the unsol event is incompatible with the standard
2271          * definition.  4bit tag is placed at 28 bit!
2272          */
2273         if ((res >> 28) == 0x01)
2274                 alc880_lg_lw_automute(codec);
2275 }
2276
2277 #ifdef CONFIG_SND_HDA_POWER_SAVE
2278 static struct hda_amp_list alc880_loopbacks[] = {
2279         { 0x0b, HDA_INPUT, 0 },
2280         { 0x0b, HDA_INPUT, 1 },
2281         { 0x0b, HDA_INPUT, 2 },
2282         { 0x0b, HDA_INPUT, 3 },
2283         { 0x0b, HDA_INPUT, 4 },
2284         { } /* end */
2285 };
2286
2287 static struct hda_amp_list alc880_lg_loopbacks[] = {
2288         { 0x0b, HDA_INPUT, 1 },
2289         { 0x0b, HDA_INPUT, 6 },
2290         { 0x0b, HDA_INPUT, 7 },
2291         { } /* end */
2292 };
2293 #endif
2294
2295 /*
2296  * Common callbacks
2297  */
2298
2299 static int alc_init(struct hda_codec *codec)
2300 {
2301         struct alc_spec *spec = codec->spec;
2302         unsigned int i;
2303
2304         for (i = 0; i < spec->num_init_verbs; i++)
2305                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2306
2307         if (spec->init_hook)
2308                 spec->init_hook(codec);
2309
2310         return 0;
2311 }
2312
2313 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2314 {
2315         struct alc_spec *spec = codec->spec;
2316
2317         if (spec->unsol_event)
2318                 spec->unsol_event(codec, res);
2319 }
2320
2321 #ifdef CONFIG_SND_HDA_POWER_SAVE
2322 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2323 {
2324         struct alc_spec *spec = codec->spec;
2325         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2326 }
2327 #endif
2328
2329 /*
2330  * Analog playback callbacks
2331  */
2332 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
2333                                     struct hda_codec *codec,
2334                                     struct snd_pcm_substream *substream)
2335 {
2336         struct alc_spec *spec = codec->spec;
2337         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2338                                              hinfo);
2339 }
2340
2341 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2342                                        struct hda_codec *codec,
2343                                        unsigned int stream_tag,
2344                                        unsigned int format,
2345                                        struct snd_pcm_substream *substream)
2346 {
2347         struct alc_spec *spec = codec->spec;
2348         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2349                                                 stream_tag, format, substream);
2350 }
2351
2352 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2353                                        struct hda_codec *codec,
2354                                        struct snd_pcm_substream *substream)
2355 {
2356         struct alc_spec *spec = codec->spec;
2357         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2358 }
2359
2360 /*
2361  * Digital out
2362  */
2363 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2364                                         struct hda_codec *codec,
2365                                         struct snd_pcm_substream *substream)
2366 {
2367         struct alc_spec *spec = codec->spec;
2368         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2369 }
2370
2371 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2372                                            struct hda_codec *codec,
2373                                            unsigned int stream_tag,
2374                                            unsigned int format,
2375                                            struct snd_pcm_substream *substream)
2376 {
2377         struct alc_spec *spec = codec->spec;
2378         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2379                                              stream_tag, format, substream);
2380 }
2381
2382 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2383                                          struct hda_codec *codec,
2384                                          struct snd_pcm_substream *substream)
2385 {
2386         struct alc_spec *spec = codec->spec;
2387         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2388 }
2389
2390 /*
2391  * Analog capture
2392  */
2393 static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2394                                       struct hda_codec *codec,
2395                                       unsigned int stream_tag,
2396                                       unsigned int format,
2397                                       struct snd_pcm_substream *substream)
2398 {
2399         struct alc_spec *spec = codec->spec;
2400
2401         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2402                                    stream_tag, 0, format);
2403         return 0;
2404 }
2405
2406 static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2407                                       struct hda_codec *codec,
2408                                       struct snd_pcm_substream *substream)
2409 {
2410         struct alc_spec *spec = codec->spec;
2411
2412         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2413                                    0, 0, 0);
2414         return 0;
2415 }
2416
2417
2418 /*
2419  */
2420 static struct hda_pcm_stream alc880_pcm_analog_playback = {
2421         .substreams = 1,
2422         .channels_min = 2,
2423         .channels_max = 8,
2424         /* NID is set in alc_build_pcms */
2425         .ops = {
2426                 .open = alc880_playback_pcm_open,
2427                 .prepare = alc880_playback_pcm_prepare,
2428                 .cleanup = alc880_playback_pcm_cleanup
2429         },
2430 };
2431
2432 static struct hda_pcm_stream alc880_pcm_analog_capture = {
2433         .substreams = 1,
2434         .channels_min = 2,
2435         .channels_max = 2,
2436         /* NID is set in alc_build_pcms */
2437 };
2438
2439 static struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
2440         .substreams = 1,
2441         .channels_min = 2,
2442         .channels_max = 2,
2443         /* NID is set in alc_build_pcms */
2444 };
2445
2446 static struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
2447         .substreams = 2, /* can be overridden */
2448         .channels_min = 2,
2449         .channels_max = 2,
2450         /* NID is set in alc_build_pcms */
2451         .ops = {
2452                 .prepare = alc880_alt_capture_pcm_prepare,
2453                 .cleanup = alc880_alt_capture_pcm_cleanup
2454         },
2455 };
2456
2457 static struct hda_pcm_stream alc880_pcm_digital_playback = {
2458         .substreams = 1,
2459         .channels_min = 2,
2460         .channels_max = 2,
2461         /* NID is set in alc_build_pcms */
2462         .ops = {
2463                 .open = alc880_dig_playback_pcm_open,
2464                 .close = alc880_dig_playback_pcm_close,
2465                 .prepare = alc880_dig_playback_pcm_prepare
2466         },
2467 };
2468
2469 static struct hda_pcm_stream alc880_pcm_digital_capture = {
2470         .substreams = 1,
2471         .channels_min = 2,
2472         .channels_max = 2,
2473         /* NID is set in alc_build_pcms */
2474 };
2475
2476 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2477 static struct hda_pcm_stream alc_pcm_null_stream = {
2478         .substreams = 0,
2479         .channels_min = 0,
2480         .channels_max = 0,
2481 };
2482
2483 static int alc_build_pcms(struct hda_codec *codec)
2484 {
2485         struct alc_spec *spec = codec->spec;
2486         struct hda_pcm *info = spec->pcm_rec;
2487         int i;
2488
2489         codec->num_pcms = 1;
2490         codec->pcm_info = info;
2491
2492         info->name = spec->stream_name_analog;
2493         if (spec->stream_analog_playback) {
2494                 snd_assert(spec->multiout.dac_nids, return -EINVAL);
2495                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
2496                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2497         }
2498         if (spec->stream_analog_capture) {
2499                 snd_assert(spec->adc_nids, return -EINVAL);
2500                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
2501                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2502         }
2503
2504         if (spec->channel_mode) {
2505                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2506                 for (i = 0; i < spec->num_channel_mode; i++) {
2507                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2508                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2509                         }
2510                 }
2511         }
2512
2513         /* SPDIF for stream index #1 */
2514         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2515                 codec->num_pcms = 2;
2516                 info = spec->pcm_rec + 1;
2517                 info->name = spec->stream_name_digital;
2518                 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2519                 if (spec->multiout.dig_out_nid &&
2520                     spec->stream_digital_playback) {
2521                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
2522                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2523                 }
2524                 if (spec->dig_in_nid &&
2525                     spec->stream_digital_capture) {
2526                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
2527                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2528                 }
2529         }
2530
2531         /* If the use of more than one ADC is requested for the current
2532          * model, configure a second analog capture-only PCM.
2533          */
2534         /* Additional Analaog capture for index #2 */
2535         if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
2536             (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
2537                 codec->num_pcms = 3;
2538                 info = spec->pcm_rec + 2;
2539                 info->name = spec->stream_name_analog;
2540                 if (spec->alt_dac_nid) {
2541                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2542                                 *spec->stream_analog_alt_playback;
2543                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2544                                 spec->alt_dac_nid;
2545                 } else {
2546                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2547                                 alc_pcm_null_stream;
2548                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2549                 }
2550                 if (spec->num_adc_nids > 1) {
2551                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2552                                 *spec->stream_analog_alt_capture;
2553                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2554                                 spec->adc_nids[1];
2555                         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2556                                 spec->num_adc_nids - 1;
2557                 } else {
2558                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2559                                 alc_pcm_null_stream;
2560                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
2561                 }
2562         }
2563
2564         return 0;
2565 }
2566
2567 static void alc_free(struct hda_codec *codec)
2568 {
2569         struct alc_spec *spec = codec->spec;
2570         unsigned int i;
2571
2572         if (!spec)
2573                 return;
2574
2575         if (spec->kctl_alloc) {
2576                 for (i = 0; i < spec->num_kctl_used; i++)
2577                         kfree(spec->kctl_alloc[i].name);
2578                 kfree(spec->kctl_alloc);
2579         }
2580         kfree(spec);
2581 }
2582
2583 /*
2584  */
2585 static struct hda_codec_ops alc_patch_ops = {
2586         .build_controls = alc_build_controls,
2587         .build_pcms = alc_build_pcms,
2588         .init = alc_init,
2589         .free = alc_free,
2590         .unsol_event = alc_unsol_event,
2591 #ifdef CONFIG_SND_HDA_POWER_SAVE
2592         .check_power_status = alc_check_power_status,
2593 #endif
2594 };
2595
2596
2597 /*
2598  * Test configuration for debugging
2599  *
2600  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
2601  * enum controls.
2602  */
2603 #ifdef CONFIG_SND_DEBUG
2604 static hda_nid_t alc880_test_dac_nids[4] = {
2605         0x02, 0x03, 0x04, 0x05
2606 };
2607
2608 static struct hda_input_mux alc880_test_capture_source = {
2609         .num_items = 7,
2610         .items = {
2611                 { "In-1", 0x0 },
2612                 { "In-2", 0x1 },
2613                 { "In-3", 0x2 },
2614                 { "In-4", 0x3 },
2615                 { "CD", 0x4 },
2616                 { "Front", 0x5 },
2617                 { "Surround", 0x6 },
2618         },
2619 };
2620
2621 static struct hda_channel_mode alc880_test_modes[4] = {
2622         { 2, NULL },
2623         { 4, NULL },
2624         { 6, NULL },
2625         { 8, NULL },
2626 };
2627
2628 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
2629                                  struct snd_ctl_elem_info *uinfo)
2630 {
2631         static char *texts[] = {
2632                 "N/A", "Line Out", "HP Out",
2633                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
2634         };
2635         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2636         uinfo->count = 1;
2637         uinfo->value.enumerated.items = 8;
2638         if (uinfo->value.enumerated.item >= 8)
2639                 uinfo->value.enumerated.item = 7;
2640         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2641         return 0;
2642 }
2643
2644 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
2645                                 struct snd_ctl_elem_value *ucontrol)
2646 {
2647         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2648         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2649         unsigned int pin_ctl, item = 0;
2650
2651         pin_ctl = snd_hda_codec_read(codec, nid, 0,
2652                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2653         if (pin_ctl & AC_PINCTL_OUT_EN) {
2654                 if (pin_ctl & AC_PINCTL_HP_EN)
2655                         item = 2;
2656                 else
2657                         item = 1;
2658         } else if (pin_ctl & AC_PINCTL_IN_EN) {
2659                 switch (pin_ctl & AC_PINCTL_VREFEN) {
2660                 case AC_PINCTL_VREF_HIZ: item = 3; break;
2661                 case AC_PINCTL_VREF_50:  item = 4; break;
2662                 case AC_PINCTL_VREF_GRD: item = 5; break;
2663                 case AC_PINCTL_VREF_80:  item = 6; break;
2664                 case AC_PINCTL_VREF_100: item = 7; break;
2665                 }
2666         }
2667         ucontrol->value.enumerated.item[0] = item;
2668         return 0;
2669 }
2670
2671 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
2672                                 struct snd_ctl_elem_value *ucontrol)
2673 {
2674         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2675         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2676         static unsigned int ctls[] = {
2677                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
2678                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
2679                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
2680                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
2681                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
2682                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
2683         };
2684         unsigned int old_ctl, new_ctl;
2685
2686         old_ctl = snd_hda_codec_read(codec, nid, 0,
2687                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2688         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
2689         if (old_ctl != new_ctl) {
2690                 int val;
2691                 snd_hda_codec_write_cache(codec, nid, 0,
2692                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
2693                                           new_ctl);
2694                 val = ucontrol->value.enumerated.item[0] >= 3 ?
2695                         HDA_AMP_MUTE : 0;
2696                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
2697                                          HDA_AMP_MUTE, val);
2698                 return 1;
2699         }
2700         return 0;
2701 }
2702
2703 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
2704                                  struct snd_ctl_elem_info *uinfo)
2705 {
2706         static char *texts[] = {
2707                 "Front", "Surround", "CLFE", "Side"
2708         };
2709         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2710         uinfo->count = 1;
2711         uinfo->value.enumerated.items = 4;
2712         if (uinfo->value.enumerated.item >= 4)
2713                 uinfo->value.enumerated.item = 3;
2714         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2715         return 0;
2716 }
2717
2718 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
2719                                 struct snd_ctl_elem_value *ucontrol)
2720 {
2721         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2722         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2723         unsigned int sel;
2724
2725         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
2726         ucontrol->value.enumerated.item[0] = sel & 3;
2727         return 0;
2728 }
2729
2730 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
2731                                 struct snd_ctl_elem_value *ucontrol)
2732 {
2733         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2734         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2735         unsigned int sel;
2736
2737         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
2738         if (ucontrol->value.enumerated.item[0] != sel) {
2739                 sel = ucontrol->value.enumerated.item[0] & 3;
2740                 snd_hda_codec_write_cache(codec, nid, 0,
2741                                           AC_VERB_SET_CONNECT_SEL, sel);
2742                 return 1;
2743         }
2744         return 0;
2745 }
2746
2747 #define PIN_CTL_TEST(xname,nid) {                       \
2748                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
2749                         .name = xname,                 \
2750                         .info = alc_test_pin_ctl_info, \
2751                         .get = alc_test_pin_ctl_get,   \
2752                         .put = alc_test_pin_ctl_put,   \
2753                         .private_value = nid           \
2754                         }
2755
2756 #define PIN_SRC_TEST(xname,nid) {                       \
2757                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
2758                         .name = xname,                 \
2759                         .info = alc_test_pin_src_info, \
2760                         .get = alc_test_pin_src_get,   \
2761                         .put = alc_test_pin_src_put,   \
2762                         .private_value = nid           \
2763                         }
2764
2765 static struct snd_kcontrol_new alc880_test_mixer[] = {
2766         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2767         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2768         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
2769         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2770         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2771         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2772         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
2773         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2774         PIN_CTL_TEST("Front Pin Mode", 0x14),
2775         PIN_CTL_TEST("Surround Pin Mode", 0x15),
2776         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
2777         PIN_CTL_TEST("Side Pin Mode", 0x17),
2778         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
2779         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
2780         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
2781         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
2782         PIN_SRC_TEST("In-1 Pin Source", 0x18),
2783         PIN_SRC_TEST("In-2 Pin Source", 0x19),
2784         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
2785         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
2786         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
2787         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
2788         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
2789         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
2790         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
2791         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
2792         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
2793         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
2794         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
2795         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
2796         {
2797                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2798                 .name = "Channel Mode",
2799                 .info = alc_ch_mode_info,
2800                 .get = alc_ch_mode_get,
2801                 .put = alc_ch_mode_put,
2802         },
2803         { } /* end */
2804 };
2805
2806 static struct hda_verb alc880_test_init_verbs[] = {
2807         /* Unmute inputs of 0x0c - 0x0f */
2808         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2809         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2810         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2811         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2812         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2813         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2814         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2815         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2816         /* Vol output for 0x0c-0x0f */
2817         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2818         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2819         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2820         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2821         /* Set output pins 0x14-0x17 */
2822         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2823         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2824         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2825         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2826         /* Unmute output pins 0x14-0x17 */
2827         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2828         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2829         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2830         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2831         /* Set input pins 0x18-0x1c */
2832         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2833         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2834         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2835         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2836         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2837         /* Mute input pins 0x18-0x1b */
2838         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2839         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2840         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2841         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2842         /* ADC set up */
2843         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2844         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2845         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2846         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2847         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2848         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2849         /* Analog input/passthru */
2850         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2851         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2852         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2853         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2854         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2855         { }
2856 };
2857 #endif
2858
2859 /*
2860  */
2861
2862 static const char *alc880_models[ALC880_MODEL_LAST] = {
2863         [ALC880_3ST]            = "3stack",
2864         [ALC880_TCL_S700]       = "tcl",
2865         [ALC880_3ST_DIG]        = "3stack-digout",
2866         [ALC880_CLEVO]          = "clevo",
2867         [ALC880_5ST]            = "5stack",
2868         [ALC880_5ST_DIG]        = "5stack-digout",
2869         [ALC880_W810]           = "w810",
2870         [ALC880_Z71V]           = "z71v",
2871         [ALC880_6ST]            = "6stack",
2872         [ALC880_6ST_DIG]        = "6stack-digout",
2873         [ALC880_ASUS]           = "asus",
2874         [ALC880_ASUS_W1V]       = "asus-w1v",
2875         [ALC880_ASUS_DIG]       = "asus-dig",
2876         [ALC880_ASUS_DIG2]      = "asus-dig2",
2877         [ALC880_UNIWILL_DIG]    = "uniwill",
2878         [ALC880_UNIWILL_P53]    = "uniwill-p53",
2879         [ALC880_FUJITSU]        = "fujitsu",
2880         [ALC880_F1734]          = "F1734",
2881         [ALC880_LG]             = "lg",
2882         [ALC880_LG_LW]          = "lg-lw",
2883 #ifdef CONFIG_SND_DEBUG
2884         [ALC880_TEST]           = "test",
2885 #endif
2886         [ALC880_AUTO]           = "auto",
2887 };
2888
2889 static struct snd_pci_quirk alc880_cfg_tbl[] = {
2890         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
2891         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
2892         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
2893         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
2894         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
2895         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
2896         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
2897         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
2898         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
2899         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
2900         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
2901         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
2902         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
2903         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
2904         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
2905         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
2906         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
2907         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
2908         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
2909         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
2910         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
2911         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS", ALC880_ASUS),
2912         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
2913         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
2914         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
2915         SND_PCI_QUIRK(0x1043, 0, "ASUS", ALC880_ASUS), /* default ASUS */
2916         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
2917         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
2918         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
2919         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
2920         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
2921         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
2922         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
2923         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
2924         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
2925         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
2926         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
2927         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
2928         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
2929         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
2930         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
2931         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
2932         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
2933         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
2934         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
2935         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
2936         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
2937         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
2938         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
2939         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
2940         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
2941         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
2942         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
2943         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
2944         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
2945         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
2946         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
2947         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
2948         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
2949         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
2950         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
2951         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
2952         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
2953         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
2954         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
2955         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
2956         SND_PCI_QUIRK(0x8086, 0, "Intel mobo", ALC880_3ST), /* default Intel */
2957         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
2958         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
2959         {}
2960 };
2961
2962 /*
2963  * ALC880 codec presets
2964  */
2965 static struct alc_config_preset alc880_presets[] = {
2966         [ALC880_3ST] = {
2967                 .mixers = { alc880_three_stack_mixer },
2968                 .init_verbs = { alc880_volume_init_verbs,
2969                                 alc880_pin_3stack_init_verbs },
2970                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2971                 .dac_nids = alc880_dac_nids,
2972                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
2973                 .channel_mode = alc880_threestack_modes,
2974                 .need_dac_fix = 1,
2975                 .input_mux = &alc880_capture_source,
2976         },
2977         [ALC880_3ST_DIG] = {
2978                 .mixers = { alc880_three_stack_mixer },
2979                 .init_verbs = { alc880_volume_init_verbs,
2980                                 alc880_pin_3stack_init_verbs },
2981                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2982                 .dac_nids = alc880_dac_nids,
2983                 .dig_out_nid = ALC880_DIGOUT_NID,
2984                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
2985                 .channel_mode = alc880_threestack_modes,
2986                 .need_dac_fix = 1,
2987                 .input_mux = &alc880_capture_source,
2988         },
2989         [ALC880_TCL_S700] = {
2990                 .mixers = { alc880_tcl_s700_mixer },
2991                 .init_verbs = { alc880_volume_init_verbs,
2992                                 alc880_pin_tcl_S700_init_verbs,
2993                                 alc880_gpio2_init_verbs },
2994                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2995                 .dac_nids = alc880_dac_nids,
2996                 .hp_nid = 0x03,
2997                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
2998                 .channel_mode = alc880_2_jack_modes,
2999                 .input_mux = &alc880_capture_source,
3000         },
3001         [ALC880_5ST] = {
3002                 .mixers = { alc880_three_stack_mixer,
3003                             alc880_five_stack_mixer},
3004                 .init_verbs = { alc880_volume_init_verbs,
3005                                 alc880_pin_5stack_init_verbs },
3006                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3007                 .dac_nids = alc880_dac_nids,
3008                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3009                 .channel_mode = alc880_fivestack_modes,
3010                 .input_mux = &alc880_capture_source,
3011         },
3012         [ALC880_5ST_DIG] = {
3013                 .mixers = { alc880_three_stack_mixer,
3014                             alc880_five_stack_mixer },
3015                 .init_verbs = { alc880_volume_init_verbs,
3016                                 alc880_pin_5stack_init_verbs },
3017                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3018                 .dac_nids = alc880_dac_nids,
3019                 .dig_out_nid = ALC880_DIGOUT_NID,
3020                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3021                 .channel_mode = alc880_fivestack_modes,
3022                 .input_mux = &alc880_capture_source,
3023         },
3024         [ALC880_6ST] = {
3025                 .mixers = { alc880_six_stack_mixer },
3026                 .init_verbs = { alc880_volume_init_verbs,
3027                                 alc880_pin_6stack_init_verbs },
3028                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3029                 .dac_nids = alc880_6st_dac_nids,
3030                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3031                 .channel_mode = alc880_sixstack_modes,
3032                 .input_mux = &alc880_6stack_capture_source,
3033         },
3034         [ALC880_6ST_DIG] = {
3035                 .mixers = { alc880_six_stack_mixer },
3036                 .init_verbs = { alc880_volume_init_verbs,
3037                                 alc880_pin_6stack_init_verbs },
3038                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3039                 .dac_nids = alc880_6st_dac_nids,
3040                 .dig_out_nid = ALC880_DIGOUT_NID,
3041                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3042                 .channel_mode = alc880_sixstack_modes,
3043                 .input_mux = &alc880_6stack_capture_source,
3044         },
3045         [ALC880_W810] = {
3046                 .mixers = { alc880_w810_base_mixer },
3047                 .init_verbs = { alc880_volume_init_verbs,
3048                                 alc880_pin_w810_init_verbs,
3049                                 alc880_gpio2_init_verbs },
3050                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
3051                 .dac_nids = alc880_w810_dac_nids,
3052                 .dig_out_nid = ALC880_DIGOUT_NID,
3053                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3054                 .channel_mode = alc880_w810_modes,
3055                 .input_mux = &alc880_capture_source,
3056         },
3057         [ALC880_Z71V] = {
3058                 .mixers = { alc880_z71v_mixer },
3059                 .init_verbs = { alc880_volume_init_verbs,
3060                                 alc880_pin_z71v_init_verbs },
3061                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
3062                 .dac_nids = alc880_z71v_dac_nids,
3063                 .dig_out_nid = ALC880_DIGOUT_NID,
3064                 .hp_nid = 0x03,
3065                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3066                 .channel_mode = alc880_2_jack_modes,
3067                 .input_mux = &alc880_capture_source,
3068         },
3069         [ALC880_F1734] = {
3070                 .mixers = { alc880_f1734_mixer },
3071                 .init_verbs = { alc880_volume_init_verbs,
3072                                 alc880_pin_f1734_init_verbs },
3073                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
3074                 .dac_nids = alc880_f1734_dac_nids,
3075                 .hp_nid = 0x02,
3076                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3077                 .channel_mode = alc880_2_jack_modes,
3078                 .input_mux = &alc880_f1734_capture_source,
3079                 .unsol_event = alc880_uniwill_p53_unsol_event,
3080                 .init_hook = alc880_uniwill_p53_hp_automute,
3081         },
3082         [ALC880_ASUS] = {
3083                 .mixers = { alc880_asus_mixer },
3084                 .init_verbs = { alc880_volume_init_verbs,
3085                                 alc880_pin_asus_init_verbs,
3086                                 alc880_gpio1_init_verbs },
3087                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3088                 .dac_nids = alc880_asus_dac_nids,
3089                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3090                 .channel_mode = alc880_asus_modes,
3091                 .need_dac_fix = 1,
3092                 .input_mux = &alc880_capture_source,
3093         },
3094         [ALC880_ASUS_DIG] = {
3095                 .mixers = { alc880_asus_mixer },
3096                 .init_verbs = { alc880_volume_init_verbs,
3097                                 alc880_pin_asus_init_verbs,
3098                                 alc880_gpio1_init_verbs },
3099                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3100                 .dac_nids = alc880_asus_dac_nids,
3101                 .dig_out_nid = ALC880_DIGOUT_NID,
3102                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3103                 .channel_mode = alc880_asus_modes,
3104                 .need_dac_fix = 1,
3105                 .input_mux = &alc880_capture_source,
3106         },
3107         [ALC880_ASUS_DIG2] = {
3108                 .mixers = { alc880_asus_mixer },
3109                 .init_verbs = { alc880_volume_init_verbs,
3110                                 alc880_pin_asus_init_verbs,
3111                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
3112                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3113                 .dac_nids = alc880_asus_dac_nids,
3114                 .dig_out_nid = ALC880_DIGOUT_NID,
3115                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3116                 .channel_mode = alc880_asus_modes,
3117                 .need_dac_fix = 1,
3118                 .input_mux = &alc880_capture_source,
3119         },
3120         [ALC880_ASUS_W1V] = {
3121                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
3122                 .init_verbs = { alc880_volume_init_verbs,
3123                                 alc880_pin_asus_init_verbs,
3124                                 alc880_gpio1_init_verbs },
3125                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3126                 .dac_nids = alc880_asus_dac_nids,
3127                 .dig_out_nid = ALC880_DIGOUT_NID,
3128                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3129                 .channel_mode = alc880_asus_modes,
3130                 .need_dac_fix = 1,
3131                 .input_mux = &alc880_capture_source,
3132         },
3133         [ALC880_UNIWILL_DIG] = {
3134                 .mixers = { alc880_asus_mixer, alc880_pcbeep_mixer },
3135                 .init_verbs = { alc880_volume_init_verbs,
3136                                 alc880_pin_asus_init_verbs },
3137                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3138                 .dac_nids = alc880_asus_dac_nids,
3139                 .dig_out_nid = ALC880_DIGOUT_NID,
3140                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3141                 .channel_mode = alc880_asus_modes,
3142                 .need_dac_fix = 1,
3143                 .input_mux = &alc880_capture_source,
3144         },
3145         [ALC880_UNIWILL] = {
3146                 .mixers = { alc880_uniwill_mixer },
3147                 .init_verbs = { alc880_volume_init_verbs,
3148                                 alc880_uniwill_init_verbs },
3149                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3150                 .dac_nids = alc880_asus_dac_nids,
3151                 .dig_out_nid = ALC880_DIGOUT_NID,
3152                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3153                 .channel_mode = alc880_threestack_modes,
3154                 .need_dac_fix = 1,
3155                 .input_mux = &alc880_capture_source,
3156                 .unsol_event = alc880_uniwill_unsol_event,
3157                 .init_hook = alc880_uniwill_automute,
3158         },
3159         [ALC880_UNIWILL_P53] = {
3160                 .mixers = { alc880_uniwill_p53_mixer },
3161                 .init_verbs = { alc880_volume_init_verbs,
3162                                 alc880_uniwill_p53_init_verbs },
3163                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3164                 .dac_nids = alc880_asus_dac_nids,
3165                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3166                 .channel_mode = alc880_threestack_modes,
3167                 .input_mux = &alc880_capture_source,
3168                 .unsol_event = alc880_uniwill_p53_unsol_event,
3169                 .init_hook = alc880_uniwill_p53_hp_automute,
3170         },
3171         [ALC880_FUJITSU] = {
3172                 .mixers = { alc880_fujitsu_mixer,
3173                             alc880_pcbeep_mixer, },
3174                 .init_verbs = { alc880_volume_init_verbs,
3175                                 alc880_uniwill_p53_init_verbs,
3176                                 alc880_beep_init_verbs },
3177                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3178                 .dac_nids = alc880_dac_nids,
3179                 .dig_out_nid = ALC880_DIGOUT_NID,
3180                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3181                 .channel_mode = alc880_2_jack_modes,
3182                 .input_mux = &alc880_capture_source,
3183                 .unsol_event = alc880_uniwill_p53_unsol_event,
3184                 .init_hook = alc880_uniwill_p53_hp_automute,
3185         },
3186         [ALC880_CLEVO] = {
3187                 .mixers = { alc880_three_stack_mixer },
3188                 .init_verbs = { alc880_volume_init_verbs,
3189                                 alc880_pin_clevo_init_verbs },
3190                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3191                 .dac_nids = alc880_dac_nids,
3192                 .hp_nid = 0x03,
3193                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3194                 .channel_mode = alc880_threestack_modes,
3195                 .need_dac_fix = 1,
3196                 .input_mux = &alc880_capture_source,
3197         },
3198         [ALC880_LG] = {
3199                 .mixers = { alc880_lg_mixer },
3200                 .init_verbs = { alc880_volume_init_verbs,
3201                                 alc880_lg_init_verbs },
3202                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
3203                 .dac_nids = alc880_lg_dac_nids,
3204                 .dig_out_nid = ALC880_DIGOUT_NID,
3205                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
3206                 .channel_mode = alc880_lg_ch_modes,
3207                 .need_dac_fix = 1,
3208                 .input_mux = &alc880_lg_capture_source,
3209                 .unsol_event = alc880_lg_unsol_event,
3210                 .init_hook = alc880_lg_automute,
3211 #ifdef CONFIG_SND_HDA_POWER_SAVE
3212                 .loopbacks = alc880_lg_loopbacks,
3213 #endif
3214         },
3215         [ALC880_LG_LW] = {
3216                 .mixers = { alc880_lg_lw_mixer },
3217                 .init_verbs = { alc880_volume_init_verbs,
3218                                 alc880_lg_lw_init_verbs },
3219                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3220                 .dac_nids = alc880_dac_nids,
3221                 .dig_out_nid = ALC880_DIGOUT_NID,
3222                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
3223                 .channel_mode = alc880_lg_lw_modes,
3224                 .input_mux = &alc880_lg_lw_capture_source,
3225                 .unsol_event = alc880_lg_lw_unsol_event,
3226                 .init_hook = alc880_lg_lw_automute,
3227         },
3228 #ifdef CONFIG_SND_DEBUG
3229         [ALC880_TEST] = {
3230                 .mixers = { alc880_test_mixer },
3231                 .init_verbs = { alc880_test_init_verbs },
3232                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
3233                 .dac_nids = alc880_test_dac_nids,
3234                 .dig_out_nid = ALC880_DIGOUT_NID,
3235                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
3236                 .channel_mode = alc880_test_modes,
3237                 .input_mux = &alc880_test_capture_source,
3238         },
3239 #endif
3240 };
3241
3242 /*
3243  * Automatic parse of I/O pins from the BIOS configuration
3244  */
3245
3246 #define NUM_CONTROL_ALLOC       32
3247 #define NUM_VERB_ALLOC          32
3248
3249 enum {
3250         ALC_CTL_WIDGET_VOL,
3251         ALC_CTL_WIDGET_MUTE,
3252         ALC_CTL_BIND_MUTE,
3253 };
3254 static struct snd_kcontrol_new alc880_control_templates[] = {
3255         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
3256         HDA_CODEC_MUTE(NULL, 0, 0, 0),
3257         HDA_BIND_MUTE(NULL, 0, 0, 0),
3258 };
3259
3260 /* add dynamic controls */
3261 static int add_control(struct alc_spec *spec, int type, const char *name,
3262                        unsigned long val)
3263 {
3264         struct snd_kcontrol_new *knew;
3265
3266         if (spec->num_kctl_used >= spec->num_kctl_alloc) {
3267                 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
3268
3269                 /* array + terminator */
3270                 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL);
3271                 if (!knew)
3272                         return -ENOMEM;
3273                 if (spec->kctl_alloc) {
3274                         memcpy(knew, spec->kctl_alloc,
3275                                sizeof(*knew) * spec->num_kctl_alloc);
3276                         kfree(spec->kctl_alloc);
3277                 }
3278                 spec->kctl_alloc = knew;
3279                 spec->num_kctl_alloc = num;
3280         }
3281
3282         knew = &spec->kctl_alloc[spec->num_kctl_used];
3283         *knew = alc880_control_templates[type];
3284         knew->name = kstrdup(name, GFP_KERNEL);
3285         if (!knew->name)
3286                 return -ENOMEM;
3287         knew->private_value = val;
3288         spec->num_kctl_used++;
3289         return 0;
3290 }
3291
3292 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
3293 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
3294 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
3295 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
3296 #define alc880_is_input_pin(nid)        ((nid) >= 0x18)
3297 #define alc880_input_pin_idx(nid)       ((nid) - 0x18)
3298 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
3299 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
3300 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
3301 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
3302 #define ALC880_PIN_CD_NID               0x1c
3303
3304 /* fill in the dac_nids table from the parsed pin configuration */
3305 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
3306                                      const struct auto_pin_cfg *cfg)
3307 {
3308         hda_nid_t nid;
3309         int assigned[4];
3310         int i, j;
3311
3312         memset(assigned, 0, sizeof(assigned));
3313         spec->multiout.dac_nids = spec->private_dac_nids;
3314
3315         /* check the pins hardwired to audio widget */
3316         for (i = 0; i < cfg->line_outs; i++) {
3317                 nid = cfg->line_out_pins[i];
3318                 if (alc880_is_fixed_pin(nid)) {
3319                         int idx = alc880_fixed_pin_idx(nid);
3320                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
3321                         assigned[idx] = 1;
3322                 }
3323         }
3324         /* left pins can be connect to any audio widget */
3325         for (i = 0; i < cfg->line_outs; i++) {
3326                 nid = cfg->line_out_pins[i];
3327                 if (alc880_is_fixed_pin(nid))
3328                         continue;
3329                 /* search for an empty channel */
3330                 for (j = 0; j < cfg->line_outs; j++) {
3331                         if (!assigned[j]) {
3332                                 spec->multiout.dac_nids[i] =
3333                                         alc880_idx_to_dac(j);
3334                                 assigned[j] = 1;
3335                                 break;
3336                         }
3337                 }
3338         }
3339         spec->multiout.num_dacs = cfg->line_outs;
3340         return 0;
3341 }
3342
3343 /* add playback controls from the parsed DAC table */
3344 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
3345                                              const struct auto_pin_cfg *cfg)
3346 {
3347         char name[32];
3348         static const char *chname[4] = {
3349                 "Front", "Surround", NULL /*CLFE*/, "Side"
3350         };
3351         hda_nid_t nid;
3352         int i, err;
3353
3354         for (i = 0; i < cfg->line_outs; i++) {
3355                 if (!spec->multiout.dac_nids[i])
3356                         continue;
3357                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
3358                 if (i == 2) {
3359                         /* Center/LFE */
3360                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3361                                           "Center Playback Volume",
3362                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
3363                                                               HDA_OUTPUT));
3364                         if (err < 0)
3365                                 return err;
3366                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3367                                           "LFE Playback Volume",
3368                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
3369                                                               HDA_OUTPUT));
3370                         if (err < 0)
3371                                 return err;
3372                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3373                                           "Center Playback Switch",
3374                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
3375                                                               HDA_INPUT));
3376                         if (err < 0)
3377                                 return err;
3378                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3379                                           "LFE Playback Switch",
3380                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
3381                                                               HDA_INPUT));
3382                         if (err < 0)
3383                                 return err;
3384                 } else {
3385                         sprintf(name, "%s Playback Volume", chname[i]);
3386                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3387                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3388                                                               HDA_OUTPUT));
3389                         if (err < 0)
3390                                 return err;
3391                         sprintf(name, "%s Playback Switch", chname[i]);
3392                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3393                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
3394                                                               HDA_INPUT));
3395                         if (err < 0)
3396                                 return err;
3397                 }
3398         }
3399         return 0;
3400 }
3401
3402 /* add playback controls for speaker and HP outputs */
3403 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
3404                                         const char *pfx)
3405 {
3406         hda_nid_t nid;
3407         int err;
3408         char name[32];
3409
3410         if (!pin)
3411                 return 0;
3412
3413         if (alc880_is_fixed_pin(pin)) {
3414                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
3415                 /* specify the DAC as the extra output */
3416                 if (!spec->multiout.hp_nid)
3417                         spec->multiout.hp_nid = nid;
3418                 else
3419                         spec->multiout.extra_out_nid[0] = nid;
3420                 /* control HP volume/switch on the output mixer amp */
3421                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
3422                 sprintf(name, "%s Playback Volume", pfx);
3423                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3424                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3425                 if (err < 0)
3426                         return err;
3427                 sprintf(name, "%s Playback Switch", pfx);
3428                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3429                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
3430                 if (err < 0)
3431                         return err;
3432         } else if (alc880_is_multi_pin(pin)) {
3433                 /* set manual connection */
3434                 /* we have only a switch on HP-out PIN */
3435                 sprintf(name, "%s Playback Switch", pfx);
3436                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3437                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3438                 if (err < 0)
3439                         return err;
3440         }
3441         return 0;
3442 }
3443
3444 /* create input playback/capture controls for the given pin */
3445 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
3446                             const char *ctlname,
3447                             int idx, hda_nid_t mix_nid)
3448 {
3449         char name[32];
3450         int err;
3451
3452         sprintf(name, "%s Playback Volume", ctlname);
3453         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3454                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3455         if (err < 0)
3456                 return err;
3457         sprintf(name, "%s Playback Switch", ctlname);
3458         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3459                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3460         if (err < 0)
3461                 return err;
3462         return 0;
3463 }
3464
3465 /* create playback/capture controls for input pins */
3466 static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
3467                                                 const struct auto_pin_cfg *cfg)
3468 {
3469         struct hda_input_mux *imux = &spec->private_imux;
3470         int i, err, idx;
3471
3472         for (i = 0; i < AUTO_PIN_LAST; i++) {
3473                 if (alc880_is_input_pin(cfg->input_pins[i])) {
3474                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
3475                         err = new_analog_input(spec, cfg->input_pins[i],
3476                                                auto_pin_cfg_labels[i],
3477                                                idx, 0x0b);
3478                         if (err < 0)
3479                                 return err;
3480                         imux->items[imux->num_items].label =
3481                                 auto_pin_cfg_labels[i];
3482                         imux->items[imux->num_items].index =
3483                                 alc880_input_pin_idx(cfg->input_pins[i]);
3484                         imux->num_items++;
3485                 }
3486         }
3487         return 0;
3488 }
3489
3490 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
3491                                unsigned int pin_type)
3492 {
3493         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3494                             pin_type);
3495         /* unmute pin */
3496         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3497                             AMP_OUT_UNMUTE);
3498 }
3499
3500 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
3501                                               hda_nid_t nid, int pin_type,
3502                                               int dac_idx)
3503 {
3504         alc_set_pin_output(codec, nid, pin_type);
3505         /* need the manual connection? */
3506         if (alc880_is_multi_pin(nid)) {
3507                 struct alc_spec *spec = codec->spec;
3508                 int idx = alc880_multi_pin_idx(nid);
3509                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
3510                                     AC_VERB_SET_CONNECT_SEL,
3511                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
3512         }
3513 }
3514
3515 static int get_pin_type(int line_out_type)
3516 {
3517         if (line_out_type == AUTO_PIN_HP_OUT)
3518                 return PIN_HP;
3519         else
3520                 return PIN_OUT;
3521 }
3522
3523 static void alc880_auto_init_multi_out(struct hda_codec *codec)
3524 {
3525         struct alc_spec *spec = codec->spec;
3526         int i;
3527         
3528         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
3529         for (i = 0; i < spec->autocfg.line_outs; i++) {
3530                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3531                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3532                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
3533         }
3534 }
3535
3536 static void alc880_auto_init_extra_out(struct hda_codec *codec)
3537 {
3538         struct alc_spec *spec = codec->spec;
3539         hda_nid_t pin;
3540
3541         pin = spec->autocfg.speaker_pins[0];
3542         if (pin) /* connect to front */
3543                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
3544         pin = spec->autocfg.hp_pins[0];
3545         if (pin) /* connect to front */
3546                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
3547 }
3548
3549 static void alc880_auto_init_analog_input(struct hda_codec *codec)
3550 {
3551         struct alc_spec *spec = codec->spec;
3552         int i;
3553
3554         for (i = 0; i < AUTO_PIN_LAST; i++) {
3555                 hda_nid_t nid = spec->autocfg.input_pins[i];
3556                 if (alc880_is_input_pin(nid)) {
3557                         snd_hda_codec_write(codec, nid, 0,
3558                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
3559                                             i <= AUTO_PIN_FRONT_MIC ?
3560                                             PIN_VREF80 : PIN_IN);
3561                         if (nid != ALC880_PIN_CD_NID)
3562                                 snd_hda_codec_write(codec, nid, 0,
3563                                                     AC_VERB_SET_AMP_GAIN_MUTE,
3564                                                     AMP_OUT_MUTE);
3565                 }
3566         }
3567 }
3568
3569 /* parse the BIOS configuration and set up the alc_spec */
3570 /* return 1 if successful, 0 if the proper config is not found,
3571  * or a negative error code
3572  */
3573 static int alc880_parse_auto_config(struct hda_codec *codec)
3574 {
3575         struct alc_spec *spec = codec->spec;
3576         int err;
3577         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
3578
3579         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
3580                                            alc880_ignore);
3581         if (err < 0)
3582                 return err;
3583         if (!spec->autocfg.line_outs)
3584                 return 0; /* can't find valid BIOS pin config */
3585
3586         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
3587         if (err < 0)
3588                 return err;
3589         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
3590         if (err < 0)
3591                 return err;
3592         err = alc880_auto_create_extra_out(spec,
3593                                            spec->autocfg.speaker_pins[0],
3594                                            "Speaker");
3595         if (err < 0)
3596                 return err;
3597         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
3598                                            "Headphone");
3599         if (err < 0)
3600                 return err;
3601         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
3602         if (err < 0)
3603                 return err;
3604
3605         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3606
3607         if (spec->autocfg.dig_out_pin)
3608                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
3609         if (spec->autocfg.dig_in_pin)
3610                 spec->dig_in_nid = ALC880_DIGIN_NID;
3611
3612         if (spec->kctl_alloc)
3613                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
3614
3615         spec->init_verbs[spec->num_init_verbs++] = alc880_volume_init_verbs;
3616
3617         spec->num_mux_defs = 1;
3618         spec->input_mux = &spec->private_imux;
3619
3620         return 1;
3621 }
3622
3623 /* additional initialization for auto-configuration model */
3624 static void alc880_auto_init(struct hda_codec *codec)
3625 {
3626         struct alc_spec *spec = codec->spec;
3627         alc880_auto_init_multi_out(codec);
3628         alc880_auto_init_extra_out(codec);
3629         alc880_auto_init_analog_input(codec);
3630         if (spec->unsol_event)
3631                 alc_sku_automute(codec);
3632 }
3633
3634 /*
3635  * OK, here we have finally the patch for ALC880
3636  */
3637
3638 static int patch_alc880(struct hda_codec *codec)
3639 {
3640         struct alc_spec *spec;
3641         int board_config;
3642         int err;
3643
3644         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3645         if (spec == NULL)
3646                 return -ENOMEM;
3647
3648         codec->spec = spec;
3649
3650         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
3651                                                   alc880_models,
3652                                                   alc880_cfg_tbl);
3653         if (board_config < 0) {
3654                 printk(KERN_INFO "hda_codec: Unknown model for ALC880, "
3655                        "trying auto-probe from BIOS...\n");
3656                 board_config = ALC880_AUTO;
3657         }
3658
3659         if (board_config == ALC880_AUTO) {
3660                 /* automatic parse from the BIOS config */
3661                 err = alc880_parse_auto_config(codec);
3662                 if (err < 0) {
3663                         alc_free(codec);
3664                         return err;
3665                 } else if (!err) {
3666                         printk(KERN_INFO
3667                                "hda_codec: Cannot set up configuration "
3668                                "from BIOS.  Using 3-stack mode...\n");
3669                         board_config = ALC880_3ST;
3670                 }
3671         }
3672
3673         if (board_config != ALC880_AUTO)
3674                 setup_preset(spec, &alc880_presets[board_config]);
3675
3676         spec->stream_name_analog = "ALC880 Analog";
3677         spec->stream_analog_playback = &alc880_pcm_analog_playback;
3678         spec->stream_analog_capture = &alc880_pcm_analog_capture;
3679         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
3680
3681         spec->stream_name_digital = "ALC880 Digital";
3682         spec->stream_digital_playback = &alc880_pcm_digital_playback;
3683         spec->stream_digital_capture = &alc880_pcm_digital_capture;
3684
3685         if (!spec->adc_nids && spec->input_mux) {
3686                 /* check whether NID 0x07 is valid */
3687                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
3688                 /* get type */
3689                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
3690                 if (wcap != AC_WID_AUD_IN) {
3691                         spec->adc_nids = alc880_adc_nids_alt;
3692                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
3693                         spec->mixers[spec->num_mixers] =
3694                                 alc880_capture_alt_mixer;
3695                         spec->num_mixers++;
3696                 } else {
3697                         spec->adc_nids = alc880_adc_nids;
3698                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
3699                         spec->mixers[spec->num_mixers] = alc880_capture_mixer;
3700                         spec->num_mixers++;
3701                 }
3702         }
3703
3704         spec->vmaster_nid = 0x0c;
3705
3706         codec->patch_ops = alc_patch_ops;
3707         if (board_config == ALC880_AUTO)
3708                 spec->init_hook = alc880_auto_init;
3709 #ifdef CONFIG_SND_HDA_POWER_SAVE
3710         if (!spec->loopback.amplist)
3711                 spec->loopback.amplist = alc880_loopbacks;
3712 #endif
3713
3714         return 0;
3715 }
3716
3717
3718 /*
3719  * ALC260 support
3720  */
3721
3722 static hda_nid_t alc260_dac_nids[1] = {
3723         /* front */
3724         0x02,
3725 };
3726
3727 static hda_nid_t alc260_adc_nids[1] = {
3728         /* ADC0 */
3729         0x04,
3730 };
3731
3732 static hda_nid_t alc260_adc_nids_alt[1] = {
3733         /* ADC1 */
3734         0x05,
3735 };
3736
3737 static hda_nid_t alc260_hp_adc_nids[2] = {
3738         /* ADC1, 0 */
3739         0x05, 0x04
3740 };
3741
3742 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
3743  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
3744  */
3745 static hda_nid_t alc260_dual_adc_nids[2] = {
3746         /* ADC0, ADC1 */
3747         0x04, 0x05
3748 };
3749
3750 #define ALC260_DIGOUT_NID       0x03
3751 #define ALC260_DIGIN_NID        0x06
3752
3753 static struct hda_input_mux alc260_capture_source = {
3754         .num_items = 4,
3755         .items = {
3756                 { "Mic", 0x0 },
3757                 { "Front Mic", 0x1 },
3758                 { "Line", 0x2 },
3759                 { "CD", 0x4 },
3760         },
3761 };
3762
3763 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
3764  * headphone jack and the internal CD lines since these are the only pins at
3765  * which audio can appear.  For flexibility, also allow the option of
3766  * recording the mixer output on the second ADC (ADC0 doesn't have a
3767  * connection to the mixer output).
3768  */
3769 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
3770         {
3771                 .num_items = 3,
3772                 .items = {
3773                         { "Mic/Line", 0x0 },
3774                         { "CD", 0x4 },
3775                         { "Headphone", 0x2 },
3776                 },
3777         },
3778         {
3779                 .num_items = 4,
3780                 .items = {
3781                         { "Mic/Line", 0x0 },
3782                         { "CD", 0x4 },
3783                         { "Headphone", 0x2 },
3784                         { "Mixer", 0x5 },
3785                 },
3786         },
3787
3788 };
3789
3790 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
3791  * the Fujitsu S702x, but jacks are marked differently.
3792  */
3793 static struct hda_input_mux alc260_acer_capture_sources[2] = {
3794         {
3795                 .num_items = 4,
3796                 .items = {
3797                         { "Mic", 0x0 },
3798                         { "Line", 0x2 },
3799                         { "CD", 0x4 },
3800                         { "Headphone", 0x5 },
3801                 },
3802         },
3803         {
3804                 .num_items = 5,
3805                 .items = {
3806                         { "Mic", 0x0 },
3807                         { "Line", 0x2 },
3808                         { "CD", 0x4 },
3809                         { "Headphone", 0x6 },
3810                         { "Mixer", 0x5 },
3811                 },
3812         },
3813 };
3814 /*
3815  * This is just place-holder, so there's something for alc_build_pcms to look
3816  * at when it calculates the maximum number of channels. ALC260 has no mixer
3817  * element which allows changing the channel mode, so the verb list is
3818  * never used.
3819  */
3820 static struct hda_channel_mode alc260_modes[1] = {
3821         { 2, NULL },
3822 };
3823
3824
3825 /* Mixer combinations
3826  *
3827  * basic: base_output + input + pc_beep + capture
3828  * HP: base_output + input + capture_alt
3829  * HP_3013: hp_3013 + input + capture
3830  * fujitsu: fujitsu + capture
3831  * acer: acer + capture
3832  */
3833
3834 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
3835         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3836         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
3837         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
3838         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
3839         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
3840         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
3841         { } /* end */
3842 };
3843
3844 static struct snd_kcontrol_new alc260_input_mixer[] = {
3845         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3846         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3847         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
3848         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
3849         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
3850         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
3851         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
3852         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
3853         { } /* end */
3854 };
3855
3856 static struct snd_kcontrol_new alc260_pc_beep_mixer[] = {
3857         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT),
3858         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT),
3859         { } /* end */
3860 };
3861
3862 /* update HP, line and mono out pins according to the master switch */
3863 static void alc260_hp_master_update(struct hda_codec *codec,
3864                                     hda_nid_t hp, hda_nid_t line,
3865                                     hda_nid_t mono)
3866 {
3867         struct alc_spec *spec = codec->spec;
3868         unsigned int val = spec->master_sw ? PIN_HP : 0;
3869         /* change HP and line-out pins */
3870         snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3871                             val);
3872         snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3873                             val);
3874         /* mono (speaker) depending on the HP jack sense */
3875         val = (val && !spec->jack_present) ? PIN_OUT : 0;
3876         snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3877                             val);
3878 }
3879
3880 static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
3881                                    struct snd_ctl_elem_value *ucontrol)
3882 {
3883         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3884         struct alc_spec *spec = codec->spec;
3885         *ucontrol->value.integer.value = spec->master_sw;
3886         return 0;
3887 }
3888
3889 static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
3890                                    struct snd_ctl_elem_value *ucontrol)
3891 {
3892         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3893         struct alc_spec *spec = codec->spec;
3894         int val = !!*ucontrol->value.integer.value;
3895         hda_nid_t hp, line, mono;
3896
3897         if (val == spec->master_sw)
3898                 return 0;
3899         spec->master_sw = val;
3900         hp = (kcontrol->private_value >> 16) & 0xff;
3901         line = (kcontrol->private_value >> 8) & 0xff;
3902         mono = kcontrol->private_value & 0xff;
3903         alc260_hp_master_update(codec, hp, line, mono);
3904         return 1;
3905 }
3906
3907 static struct snd_kcontrol_new alc260_hp_output_mixer[] = {
3908         {
3909                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3910                 .name = "Master Playback Switch",
3911                 .info = snd_ctl_boolean_mono_info,
3912                 .get = alc260_hp_master_sw_get,
3913                 .put = alc260_hp_master_sw_put,
3914                 .private_value = (0x0f << 16) | (0x10 << 8) | 0x11
3915         },
3916         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3917         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
3918         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
3919         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
3920         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
3921                               HDA_OUTPUT),
3922         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2, HDA_INPUT),
3923         { } /* end */
3924 };
3925
3926 static struct hda_verb alc260_hp_unsol_verbs[] = {
3927         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3928         {},
3929 };
3930
3931 static void alc260_hp_automute(struct hda_codec *codec)
3932 {
3933         struct alc_spec *spec = codec->spec;
3934         unsigned int present;
3935
3936         present = snd_hda_codec_read(codec, 0x10, 0,
3937                                      AC_VERB_GET_PIN_SENSE, 0);
3938         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
3939         alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
3940 }
3941
3942 static void alc260_hp_unsol_event(struct hda_codec *codec, unsigned int res)
3943 {
3944         if ((res >> 26) == ALC880_HP_EVENT)
3945                 alc260_hp_automute(codec);
3946 }
3947
3948 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
3949         {
3950                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3951                 .name = "Master Playback Switch",
3952                 .info = snd_ctl_boolean_mono_info,
3953                 .get = alc260_hp_master_sw_get,
3954                 .put = alc260_hp_master_sw_put,
3955                 .private_value = (0x10 << 16) | (0x15 << 8) | 0x11
3956         },
3957         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
3958         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
3959         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
3960         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
3961         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3962         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
3963         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
3964         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
3965         { } /* end */
3966 };
3967
3968 static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
3969         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3970         {},
3971 };
3972
3973 static void alc260_hp_3013_automute(struct hda_codec *codec)
3974 {
3975         struct alc_spec *spec = codec->spec;
3976         unsigned int present;
3977
3978         present = snd_hda_codec_read(codec, 0x15, 0,
3979                                      AC_VERB_GET_PIN_SENSE, 0);
3980         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
3981         alc260_hp_master_update(codec, 0x10, 0x15, 0x11);
3982 }
3983
3984 static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
3985                                        unsigned int res)
3986 {
3987         if ((res >> 26) == ALC880_HP_EVENT)
3988                 alc260_hp_3013_automute(codec);
3989 }
3990
3991 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12, 
3992  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
3993  */
3994 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
3995         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3996         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
3997         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
3998         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3999         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4000         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
4001         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
4002         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
4003         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4004         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4005         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4006         HDA_BIND_MUTE("Speaker Playback Switch", 0x09, 2, HDA_INPUT),
4007         { } /* end */
4008 };
4009
4010 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
4011  * versions of the ALC260 don't act on requests to enable mic bias from NID
4012  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
4013  * datasheet doesn't mention this restriction.  At this stage it's not clear
4014  * whether this behaviour is intentional or is a hardware bug in chip
4015  * revisions available in early 2006.  Therefore for now allow the
4016  * "Headphone Jack Mode" control to span all choices, but if it turns out
4017  * that the lack of mic bias for this NID is intentional we could change the
4018  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4019  *
4020  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
4021  * don't appear to make the mic bias available from the "line" jack, even
4022  * though the NID used for this jack (0x14) can supply it.  The theory is
4023  * that perhaps Acer have included blocking capacitors between the ALC260
4024  * and the output jack.  If this turns out to be the case for all such
4025  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
4026  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
4027  *
4028  * The C20x Tablet series have a mono internal speaker which is controlled
4029  * via the chip's Mono sum widget and pin complex, so include the necessary
4030  * controls for such models.  On models without a "mono speaker" the control
4031  * won't do anything.
4032  */
4033 static struct snd_kcontrol_new alc260_acer_mixer[] = {
4034         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4035         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
4036         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
4037         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4038                               HDA_OUTPUT),
4039         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2,
4040                            HDA_INPUT),
4041         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4042         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4043         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4044         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4045         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4046         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4047         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4048         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4049         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4050         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4051         { } /* end */
4052 };
4053
4054 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
4055  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
4056  */
4057 static struct snd_kcontrol_new alc260_will_mixer[] = {
4058         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4059         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4060         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4061         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4062         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4063         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4064         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4065         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4066         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4067         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4068         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4069         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4070         { } /* end */
4071 };
4072
4073 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
4074  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
4075  */
4076 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
4077         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4078         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4079         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4080         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4081         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4082         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
4083         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
4084         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4085         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4086         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4087         { } /* end */
4088 };
4089
4090 /* capture mixer elements */
4091 static struct snd_kcontrol_new alc260_capture_mixer[] = {
4092         HDA_CODEC_VOLUME("Capture Volume", 0x04, 0x0, HDA_INPUT),
4093         HDA_CODEC_MUTE("Capture Switch", 0x04, 0x0, HDA_INPUT),
4094         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x05, 0x0, HDA_INPUT),
4095         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x05, 0x0, HDA_INPUT),
4096         {
4097                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4098                 /* The multiple "Capture Source" controls confuse alsamixer
4099                  * So call somewhat different..
4100                  */
4101                 /* .name = "Capture Source", */
4102                 .name = "Input Source",
4103                 .count = 2,
4104                 .info = alc_mux_enum_info,
4105                 .get = alc_mux_enum_get,
4106                 .put = alc_mux_enum_put,
4107         },
4108         { } /* end */
4109 };
4110
4111 static struct snd_kcontrol_new alc260_capture_alt_mixer[] = {
4112         HDA_CODEC_VOLUME("Capture Volume", 0x05, 0x0, HDA_INPUT),
4113         HDA_CODEC_MUTE("Capture Switch", 0x05, 0x0, HDA_INPUT),
4114         {
4115                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4116                 /* The multiple "Capture Source" controls confuse alsamixer
4117                  * So call somewhat different..
4118                  */
4119                 /* .name = "Capture Source", */
4120                 .name = "Input Source",
4121                 .count = 1,
4122                 .info = alc_mux_enum_info,
4123                 .get = alc_mux_enum_get,
4124                 .put = alc_mux_enum_put,
4125         },
4126         { } /* end */
4127 };
4128
4129 /*
4130  * initialization verbs
4131  */
4132 static struct hda_verb alc260_init_verbs[] = {
4133         /* Line In pin widget for input */
4134         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4135         /* CD pin widget for input */
4136         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4137         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4138         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4139         /* Mic2 (front panel) pin widget for input and vref at 80% */
4140         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4141         /* LINE-2 is used for line-out in rear */
4142         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4143         /* select line-out */
4144         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
4145         /* LINE-OUT pin */
4146         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4147         /* enable HP */
4148         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4149         /* enable Mono */
4150         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4151         /* mute capture amp left and right */
4152         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4153         /* set connection select to line in (default select for this ADC) */
4154         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4155         /* mute capture amp left and right */
4156         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4157         /* set connection select to line in (default select for this ADC) */
4158         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
4159         /* set vol=0 Line-Out mixer amp left and right */
4160         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4161         /* unmute pin widget amp left and right (no gain on this amp) */
4162         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4163         /* set vol=0 HP mixer amp left and right */
4164         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4165         /* unmute pin widget amp left and right (no gain on this amp) */
4166         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4167         /* set vol=0 Mono mixer amp left and right */
4168         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4169         /* unmute pin widget amp left and right (no gain on this amp) */
4170         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4171         /* unmute LINE-2 out pin */
4172         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4173         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4174          * Line In 2 = 0x03
4175          */
4176         /* mute analog inputs */
4177         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4178         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4179         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4180         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4181         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4182         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4183         /* mute Front out path */
4184         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4185         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4186         /* mute Headphone out path */
4187         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4188         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4189         /* mute Mono out path */
4190         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4191         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4192         { }
4193 };
4194
4195 #if 0 /* should be identical with alc260_init_verbs? */
4196 static struct hda_verb alc260_hp_init_verbs[] = {
4197         /* Headphone and output */
4198         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4199         /* mono output */
4200         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4201         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4202         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4203         /* Mic2 (front panel) pin widget for input and vref at 80% */
4204         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4205         /* Line In pin widget for input */
4206         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4207         /* Line-2 pin widget for output */
4208         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4209         /* CD pin widget for input */
4210         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4211         /* unmute amp left and right */
4212         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4213         /* set connection select to line in (default select for this ADC) */
4214         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4215         /* unmute Line-Out mixer amp left and right (volume = 0) */
4216         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4217         /* mute pin widget amp left and right (no gain on this amp) */
4218         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4219         /* unmute HP mixer amp left and right (volume = 0) */
4220         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4221         /* mute pin widget amp left and right (no gain on this amp) */
4222         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4223         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4224          * Line In 2 = 0x03
4225          */
4226         /* mute analog inputs */
4227         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4228         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4229         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4230         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4231         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4232         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4233         /* Unmute Front out path */
4234         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4235         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4236         /* Unmute Headphone out path */
4237         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4238         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4239         /* Unmute Mono out path */
4240         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4241         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4242         { }
4243 };
4244 #endif
4245
4246 static struct hda_verb alc260_hp_3013_init_verbs[] = {
4247         /* Line out and output */
4248         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4249         /* mono output */
4250         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4251         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4252         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4253         /* Mic2 (front panel) pin widget for input and vref at 80% */
4254         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4255         /* Line In pin widget for input */
4256         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4257         /* Headphone pin widget for output */
4258         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4259         /* CD pin widget for input */
4260         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4261         /* unmute amp left and right */
4262         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4263         /* set connection select to line in (default select for this ADC) */
4264         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4265         /* unmute Line-Out mixer amp left and right (volume = 0) */
4266         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4267         /* mute pin widget amp left and right (no gain on this amp) */
4268         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4269         /* unmute HP mixer amp left and right (volume = 0) */
4270         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4271         /* mute pin widget amp left and right (no gain on this amp) */
4272         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4273         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4274          * Line In 2 = 0x03
4275          */
4276         /* mute analog inputs */
4277         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4278         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4279         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4280         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4281         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4282         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4283         /* Unmute Front out path */
4284         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4285         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4286         /* Unmute Headphone out path */
4287         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4288         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4289         /* Unmute Mono out path */
4290         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4291         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4292         { }
4293 };
4294
4295 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
4296  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
4297  * audio = 0x16, internal speaker = 0x10.
4298  */
4299 static struct hda_verb alc260_fujitsu_init_verbs[] = {
4300         /* Disable all GPIOs */
4301         {0x01, AC_VERB_SET_GPIO_MASK, 0},
4302         /* Internal speaker is connected to headphone pin */
4303         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4304         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
4305         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4306         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
4307         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4308         /* Ensure all other unused pins are disabled and muted. */
4309         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4310         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4311         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4312         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4313         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4314         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4315         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4316         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4317
4318         /* Disable digital (SPDIF) pins */
4319         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4320         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4321
4322         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus 
4323          * when acting as an output.
4324          */
4325         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4326
4327         /* Start with output sum widgets muted and their output gains at min */
4328         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4329         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4330         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4331         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4332         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4333         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4334         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4335         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4336         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4337
4338         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
4339         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4340         /* Unmute Line1 pin widget output buffer since it starts as an output.
4341          * If the pin mode is changed by the user the pin mode control will
4342          * take care of enabling the pin's input/output buffers as needed.
4343          * Therefore there's no need to enable the input buffer at this
4344          * stage.
4345          */
4346         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4347         /* Unmute input buffer of pin widget used for Line-in (no equiv 
4348          * mixer ctrl)
4349          */
4350         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4351
4352         /* Mute capture amp left and right */
4353         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4354         /* Set ADC connection select to match default mixer setting - line 
4355          * in (on mic1 pin)
4356          */
4357         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4358
4359         /* Do the same for the second ADC: mute capture input amp and
4360          * set ADC connection to line in (on mic1 pin)
4361          */
4362         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4363         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4364
4365         /* Mute all inputs to mixer widget (even unconnected ones) */
4366         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4367         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4368         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4369         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4370         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4371         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4372         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4373         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4374
4375         { }
4376 };
4377
4378 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
4379  * similar laptops (adapted from Fujitsu init verbs).
4380  */
4381 static struct hda_verb alc260_acer_init_verbs[] = {
4382         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
4383          * the headphone jack.  Turn this on and rely on the standard mute
4384          * methods whenever the user wants to turn these outputs off.
4385          */
4386         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
4387         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4388         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
4389         /* Internal speaker/Headphone jack is connected to Line-out pin */
4390         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4391         /* Internal microphone/Mic jack is connected to Mic1 pin */
4392         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
4393         /* Line In jack is connected to Line1 pin */
4394         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4395         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
4396         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4397         /* Ensure all other unused pins are disabled and muted. */
4398         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4399         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4400         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4401         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4402         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4403         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4404         /* Disable digital (SPDIF) pins */
4405         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4406         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4407
4408         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum 
4409          * bus when acting as outputs.
4410          */
4411         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
4412         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4413
4414         /* Start with output sum widgets muted and their output gains at min */
4415         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4416         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4417         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4418         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4419         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4420         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4421         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4422         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4423         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4424
4425         /* Unmute Line-out pin widget amp left and right
4426          * (no equiv mixer ctrl)
4427          */
4428         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4429         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
4430         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4431         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
4432          * inputs. If the pin mode is changed by the user the pin mode control
4433          * will take care of enabling the pin's input/output buffers as needed.
4434          * Therefore there's no need to enable the input buffer at this
4435          * stage.
4436          */
4437         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4438         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4439
4440         /* Mute capture amp left and right */
4441         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4442         /* Set ADC connection select to match default mixer setting - mic
4443          * (on mic1 pin)
4444          */
4445         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4446
4447         /* Do similar with the second ADC: mute capture input amp and
4448          * set ADC connection to mic to match ALSA's default state.
4449          */
4450         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4451         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4452
4453         /* Mute all inputs to mixer widget (even unconnected ones) */
4454         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4455         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4456         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4457         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4458         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4459         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4460         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4461         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4462
4463         { }
4464 };
4465
4466 static struct hda_verb alc260_will_verbs[] = {
4467         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4468         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
4469         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
4470         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4471         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
4472         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
4473         {}
4474 };
4475
4476 static struct hda_verb alc260_replacer_672v_verbs[] = {
4477         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4478         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
4479         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
4480
4481         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
4482         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4483         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4484
4485         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4486         {}
4487 };
4488
4489 /* toggle speaker-output according to the hp-jack state */
4490 static void alc260_replacer_672v_automute(struct hda_codec *codec)
4491 {
4492         unsigned int present;
4493
4494         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
4495         present = snd_hda_codec_read(codec, 0x0f, 0,
4496                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
4497         if (present) {
4498                 snd_hda_codec_write_cache(codec, 0x01, 0,
4499                                           AC_VERB_SET_GPIO_DATA, 1);
4500                 snd_hda_codec_write_cache(codec, 0x0f, 0,
4501                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4502                                           PIN_HP);
4503         } else {
4504                 snd_hda_codec_write_cache(codec, 0x01, 0,
4505                                           AC_VERB_SET_GPIO_DATA, 0);
4506                 snd_hda_codec_write_cache(codec, 0x0f, 0,
4507                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4508                                           PIN_OUT);
4509         }
4510 }
4511
4512 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
4513                                        unsigned int res)
4514 {
4515         if ((res >> 26) == ALC880_HP_EVENT)
4516                 alc260_replacer_672v_automute(codec);
4517 }
4518
4519 /* Test configuration for debugging, modelled after the ALC880 test
4520  * configuration.
4521  */
4522 #ifdef CONFIG_SND_DEBUG
4523 static hda_nid_t alc260_test_dac_nids[1] = {
4524         0x02,
4525 };
4526 static hda_nid_t alc260_test_adc_nids[2] = {
4527         0x04, 0x05,
4528 };
4529 /* For testing the ALC260, each input MUX needs its own definition since
4530  * the signal assignments are different.  This assumes that the first ADC 
4531  * is NID 0x04.
4532  */
4533 static struct hda_input_mux alc260_test_capture_sources[2] = {
4534         {
4535                 .num_items = 7,
4536                 .items = {
4537                         { "MIC1 pin", 0x0 },
4538                         { "MIC2 pin", 0x1 },
4539                         { "LINE1 pin", 0x2 },
4540                         { "LINE2 pin", 0x3 },
4541                         { "CD pin", 0x4 },
4542                         { "LINE-OUT pin", 0x5 },
4543                         { "HP-OUT pin", 0x6 },
4544                 },
4545         },
4546         {
4547                 .num_items = 8,
4548                 .items = {
4549                         { "MIC1 pin", 0x0 },
4550                         { "MIC2 pin", 0x1 },
4551                         { "LINE1 pin", 0x2 },
4552                         { "LINE2 pin", 0x3 },
4553                         { "CD pin", 0x4 },
4554                         { "Mixer", 0x5 },
4555                         { "LINE-OUT pin", 0x6 },
4556                         { "HP-OUT pin", 0x7 },
4557                 },
4558         },
4559 };
4560 static struct snd_kcontrol_new alc260_test_mixer[] = {
4561         /* Output driver widgets */
4562         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4563         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4564         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4565         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
4566         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4567         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
4568
4569         /* Modes for retasking pin widgets
4570          * Note: the ALC260 doesn't seem to act on requests to enable mic
4571          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
4572          * mention this restriction.  At this stage it's not clear whether
4573          * this behaviour is intentional or is a hardware bug in chip
4574          * revisions available at least up until early 2006.  Therefore for
4575          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
4576          * choices, but if it turns out that the lack of mic bias for these
4577          * NIDs is intentional we could change their modes from
4578          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4579          */
4580         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
4581         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
4582         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
4583         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
4584         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
4585         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
4586
4587         /* Loopback mixer controls */
4588         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
4589         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
4590         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
4591         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
4592         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
4593         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
4594         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
4595         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
4596         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4597         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4598         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4599         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4600         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
4601         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
4602         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
4603         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
4604
4605         /* Controls for GPIO pins, assuming they are configured as outputs */
4606         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
4607         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
4608         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
4609         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
4610
4611         /* Switches to allow the digital IO pins to be enabled.  The datasheet
4612          * is ambigious as to which NID is which; testing on laptops which
4613          * make this output available should provide clarification. 
4614          */
4615         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
4616         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
4617
4618         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
4619          * this output to turn on an external amplifier.
4620          */
4621         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
4622         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
4623
4624         { } /* end */
4625 };
4626 static struct hda_verb alc260_test_init_verbs[] = {
4627         /* Enable all GPIOs as outputs with an initial value of 0 */
4628         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
4629         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4630         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
4631
4632         /* Enable retasking pins as output, initially without power amp */
4633         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4634         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4635         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4636         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4637         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4638         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4639
4640         /* Disable digital (SPDIF) pins initially, but users can enable
4641          * them via a mixer switch.  In the case of SPDIF-out, this initverb
4642          * payload also sets the generation to 0, output to be in "consumer"
4643          * PCM format, copyright asserted, no pre-emphasis and no validity
4644          * control.
4645          */
4646         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4647         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4648
4649         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the 
4650          * OUT1 sum bus when acting as an output.
4651          */
4652         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
4653         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
4654         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4655         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
4656
4657         /* Start with output sum widgets muted and their output gains at min */
4658         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4659         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4660         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4661         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4662         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4663         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4664         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4665         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4666         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4667
4668         /* Unmute retasking pin widget output buffers since the default
4669          * state appears to be output.  As the pin mode is changed by the
4670          * user the pin mode control will take care of enabling the pin's
4671          * input/output buffers as needed.
4672          */
4673         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4674         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4675         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4676         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4677         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4678         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4679         /* Also unmute the mono-out pin widget */
4680         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4681
4682         /* Mute capture amp left and right */
4683         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4684         /* Set ADC connection select to match default mixer setting (mic1
4685          * pin)
4686          */
4687         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4688
4689         /* Do the same for the second ADC: mute capture input amp and
4690          * set ADC connection to mic1 pin
4691          */
4692         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4693         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4694
4695         /* Mute all inputs to mixer widget (even unconnected ones) */
4696         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4697         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4698         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4699         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4700         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4701         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4702         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4703         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4704
4705         { }
4706 };
4707 #endif
4708
4709 #define alc260_pcm_analog_playback      alc880_pcm_analog_alt_playback
4710 #define alc260_pcm_analog_capture       alc880_pcm_analog_capture
4711
4712 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
4713 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
4714
4715 /*
4716  * for BIOS auto-configuration
4717  */
4718
4719 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
4720                                         const char *pfx)
4721 {
4722         hda_nid_t nid_vol;
4723         unsigned long vol_val, sw_val;
4724         char name[32];
4725         int err;
4726
4727         if (nid >= 0x0f && nid < 0x11) {
4728                 nid_vol = nid - 0x7;
4729                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
4730                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
4731         } else if (nid == 0x11) {
4732                 nid_vol = nid - 0x7;
4733                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
4734                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
4735         } else if (nid >= 0x12 && nid <= 0x15) {
4736                 nid_vol = 0x08;
4737                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
4738                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
4739         } else
4740                 return 0; /* N/A */
4741         
4742         snprintf(name, sizeof(name), "%s Playback Volume", pfx);
4743         err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val);
4744         if (err < 0)
4745                 return err;
4746         snprintf(name, sizeof(name), "%s Playback Switch", pfx);
4747         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val);
4748         if (err < 0)
4749                 return err;
4750         return 1;
4751 }
4752
4753 /* add playback controls from the parsed DAC table */
4754 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
4755                                              const struct auto_pin_cfg *cfg)
4756 {
4757         hda_nid_t nid;
4758         int err;
4759
4760         spec->multiout.num_dacs = 1;
4761         spec->multiout.dac_nids = spec->private_dac_nids;
4762         spec->multiout.dac_nids[0] = 0x02;
4763
4764         nid = cfg->line_out_pins[0];
4765         if (nid) {
4766                 err = alc260_add_playback_controls(spec, nid, "Front");
4767                 if (err < 0)
4768                         return err;
4769         }
4770
4771         nid = cfg->speaker_pins[0];
4772         if (nid) {
4773                 err = alc260_add_playback_controls(spec, nid, "Speaker");
4774                 if (err < 0)
4775                         return err;
4776         }
4777
4778         nid = cfg->hp_pins[0];
4779         if (nid) {
4780                 err = alc260_add_playback_controls(spec, nid, "Headphone");
4781                 if (err < 0)
4782                         return err;
4783         }
4784         return 0;
4785 }
4786
4787 /* create playback/capture controls for input pins */
4788 static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec,
4789                                                 const struct auto_pin_cfg *cfg)
4790 {
4791         struct hda_input_mux *imux = &spec->private_imux;
4792         int i, err, idx;
4793
4794         for (i = 0; i < AUTO_PIN_LAST; i++) {
4795                 if (cfg->input_pins[i] >= 0x12) {
4796                         idx = cfg->input_pins[i] - 0x12;
4797                         err = new_analog_input(spec, cfg->input_pins[i],
4798                                                auto_pin_cfg_labels[i], idx,
4799                                                0x07);
4800                         if (err < 0)
4801                                 return err;
4802                         imux->items[imux->num_items].label =
4803                                 auto_pin_cfg_labels[i];
4804                         imux->items[imux->num_items].index = idx;
4805                         imux->num_items++;
4806                 }
4807                 if (cfg->input_pins[i] >= 0x0f && cfg->input_pins[i] <= 0x10){
4808                         idx = cfg->input_pins[i] - 0x09;
4809                         err = new_analog_input(spec, cfg->input_pins[i],
4810                                                auto_pin_cfg_labels[i], idx,
4811                                                0x07);
4812                         if (err < 0)
4813                                 return err;
4814                         imux->items[imux->num_items].label =
4815                                 auto_pin_cfg_labels[i];
4816                         imux->items[imux->num_items].index = idx;
4817                         imux->num_items++;
4818                 }
4819         }
4820         return 0;
4821 }
4822
4823 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
4824                                               hda_nid_t nid, int pin_type,
4825                                               int sel_idx)
4826 {
4827         alc_set_pin_output(codec, nid, pin_type);
4828         /* need the manual connection? */
4829         if (nid >= 0x12) {
4830                 int idx = nid - 0x12;
4831                 snd_hda_codec_write(codec, idx + 0x0b, 0,
4832                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
4833         }
4834 }
4835
4836 static void alc260_auto_init_multi_out(struct hda_codec *codec)
4837 {
4838         struct alc_spec *spec = codec->spec;
4839         hda_nid_t nid;
4840
4841         alc_subsystem_id(codec, 0x10, 0x15, 0x0f);
4842         nid = spec->autocfg.line_out_pins[0];
4843         if (nid) {
4844                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
4845                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
4846         }
4847         
4848         nid = spec->autocfg.speaker_pins[0];
4849         if (nid)
4850                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
4851
4852         nid = spec->autocfg.hp_pins[0];
4853         if (nid)
4854                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
4855 }
4856
4857 #define ALC260_PIN_CD_NID               0x16
4858 static void alc260_auto_init_analog_input(struct hda_codec *codec)
4859 {
4860         struct alc_spec *spec = codec->spec;
4861         int i;
4862
4863         for (i = 0; i < AUTO_PIN_LAST; i++) {
4864                 hda_nid_t nid = spec->autocfg.input_pins[i];
4865                 if (nid >= 0x12) {
4866                         snd_hda_codec_write(codec, nid, 0,
4867                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
4868                                             i <= AUTO_PIN_FRONT_MIC ?
4869                                             PIN_VREF80 : PIN_IN);
4870                         if (nid != ALC260_PIN_CD_NID)
4871                                 snd_hda_codec_write(codec, nid, 0,
4872                                                     AC_VERB_SET_AMP_GAIN_MUTE,
4873                                                     AMP_OUT_MUTE);
4874                 }
4875         }
4876 }
4877
4878 /*
4879  * generic initialization of ADC, input mixers and output mixers
4880  */
4881 static struct hda_verb alc260_volume_init_verbs[] = {
4882         /*
4883          * Unmute ADC0-1 and set the default input to mic-in
4884          */
4885         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4886         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4887         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4888         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4889         
4890         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4891          * mixer widget
4892          * Note: PASD motherboards uses the Line In 2 as the input for
4893          * front panel mic (mic 2)
4894          */
4895         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
4896         /* mute analog inputs */
4897         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4898         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4899         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4900         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4901         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4902
4903         /*
4904          * Set up output mixers (0x08 - 0x0a)
4905          */
4906         /* set vol=0 to output mixers */
4907         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4908         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4909         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4910         /* set up input amps for analog loopback */
4911         /* Amp Indices: DAC = 0, mixer = 1 */
4912         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4913         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4914         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4915         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4916         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4917         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4918         
4919         { }
4920 };
4921
4922 static int alc260_parse_auto_config(struct hda_codec *codec)
4923 {
4924         struct alc_spec *spec = codec->spec;
4925         unsigned int wcap;
4926         int err;
4927         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
4928
4929         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
4930                                            alc260_ignore);
4931         if (err < 0)
4932                 return err;
4933         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
4934         if (err < 0)
4935                 return err;
4936         if (!spec->kctl_alloc)
4937                 return 0; /* can't find valid BIOS pin config */
4938         err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg);
4939         if (err < 0)
4940                 return err;
4941
4942         spec->multiout.max_channels = 2;
4943
4944         if (spec->autocfg.dig_out_pin)
4945                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
4946         if (spec->kctl_alloc)
4947                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
4948
4949         spec->init_verbs[spec->num_init_verbs++] = alc260_volume_init_verbs;
4950
4951         spec->num_mux_defs = 1;
4952         spec->input_mux = &spec->private_imux;
4953
4954         /* check whether NID 0x04 is valid */
4955         wcap = get_wcaps(codec, 0x04);
4956         wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */
4957         if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
4958                 spec->adc_nids = alc260_adc_nids_alt;
4959                 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
4960                 spec->mixers[spec->num_mixers] = alc260_capture_alt_mixer;
4961         } else {
4962                 spec->adc_nids = alc260_adc_nids;
4963                 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
4964                 spec->mixers[spec->num_mixers] = alc260_capture_mixer;
4965         }
4966         spec->num_mixers++;
4967
4968         return 1;
4969 }
4970
4971 /* additional initialization for auto-configuration model */
4972 static void alc260_auto_init(struct hda_codec *codec)
4973 {
4974         struct alc_spec *spec = codec->spec;
4975         alc260_auto_init_multi_out(codec);
4976         alc260_auto_init_analog_input(codec);
4977         if (spec->unsol_event)
4978                 alc_sku_automute(codec);
4979 }
4980
4981 #ifdef CONFIG_SND_HDA_POWER_SAVE
4982 static struct hda_amp_list alc260_loopbacks[] = {
4983         { 0x07, HDA_INPUT, 0 },
4984         { 0x07, HDA_INPUT, 1 },
4985         { 0x07, HDA_INPUT, 2 },
4986         { 0x07, HDA_INPUT, 3 },
4987         { 0x07, HDA_INPUT, 4 },
4988         { } /* end */
4989 };
4990 #endif
4991
4992 /*
4993  * ALC260 configurations
4994  */
4995 static const char *alc260_models[ALC260_MODEL_LAST] = {
4996         [ALC260_BASIC]          = "basic",
4997         [ALC260_HP]             = "hp",
4998         [ALC260_HP_3013]        = "hp-3013",
4999         [ALC260_FUJITSU_S702X]  = "fujitsu",
5000         [ALC260_ACER]           = "acer",
5001         [ALC260_WILL]           = "will",
5002         [ALC260_REPLACER_672V]  = "replacer",
5003 #ifdef CONFIG_SND_DEBUG
5004         [ALC260_TEST]           = "test",
5005 #endif
5006         [ALC260_AUTO]           = "auto",
5007 };
5008
5009 static struct snd_pci_quirk alc260_cfg_tbl[] = {
5010         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
5011         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
5012         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
5013         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013),
5014         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
5015         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP),
5016         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_3013),
5017         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
5018         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
5019         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
5020         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
5021         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
5022         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
5023         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
5024         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
5025         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
5026         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
5027         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
5028         {}
5029 };
5030
5031 static struct alc_config_preset alc260_presets[] = {
5032         [ALC260_BASIC] = {
5033                 .mixers = { alc260_base_output_mixer,
5034                             alc260_input_mixer,
5035                             alc260_pc_beep_mixer,
5036                             alc260_capture_mixer },
5037                 .init_verbs = { alc260_init_verbs },
5038                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5039                 .dac_nids = alc260_dac_nids,
5040                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5041                 .adc_nids = alc260_adc_nids,
5042                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5043                 .channel_mode = alc260_modes,
5044                 .input_mux = &alc260_capture_source,
5045         },
5046         [ALC260_HP] = {
5047                 .mixers = { alc260_hp_output_mixer,
5048                             alc260_input_mixer,
5049                             alc260_capture_alt_mixer },
5050                 .init_verbs = { alc260_init_verbs,
5051                                 alc260_hp_unsol_verbs },
5052                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5053                 .dac_nids = alc260_dac_nids,
5054                 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
5055                 .adc_nids = alc260_hp_adc_nids,
5056                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5057                 .channel_mode = alc260_modes,
5058                 .input_mux = &alc260_capture_source,
5059                 .unsol_event = alc260_hp_unsol_event,
5060                 .init_hook = alc260_hp_automute,
5061         },
5062         [ALC260_HP_3013] = {
5063                 .mixers = { alc260_hp_3013_mixer,
5064                             alc260_input_mixer,
5065                             alc260_capture_alt_mixer },
5066                 .init_verbs = { alc260_hp_3013_init_verbs,
5067                                 alc260_hp_3013_unsol_verbs },
5068                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5069                 .dac_nids = alc260_dac_nids,
5070                 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
5071                 .adc_nids = alc260_hp_adc_nids,
5072                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5073                 .channel_mode = alc260_modes,
5074                 .input_mux = &alc260_capture_source,
5075                 .unsol_event = alc260_hp_3013_unsol_event,
5076                 .init_hook = alc260_hp_3013_automute,
5077         },
5078         [ALC260_FUJITSU_S702X] = {
5079                 .mixers = { alc260_fujitsu_mixer,
5080                             alc260_capture_mixer },
5081                 .init_verbs = { alc260_fujitsu_init_verbs },
5082                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5083                 .dac_nids = alc260_dac_nids,
5084                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5085                 .adc_nids = alc260_dual_adc_nids,
5086                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5087                 .channel_mode = alc260_modes,
5088                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
5089                 .input_mux = alc260_fujitsu_capture_sources,
5090         },
5091         [ALC260_ACER] = {
5092                 .mixers = { alc260_acer_mixer,
5093                             alc260_capture_mixer },
5094                 .init_verbs = { alc260_acer_init_verbs },
5095                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5096                 .dac_nids = alc260_dac_nids,
5097                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5098                 .adc_nids = alc260_dual_adc_nids,
5099                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5100                 .channel_mode = alc260_modes,
5101                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
5102                 .input_mux = alc260_acer_capture_sources,
5103         },
5104         [ALC260_WILL] = {
5105                 .mixers = { alc260_will_mixer,
5106                             alc260_capture_mixer },
5107                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
5108                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5109                 .dac_nids = alc260_dac_nids,
5110                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5111                 .adc_nids = alc260_adc_nids,
5112                 .dig_out_nid = ALC260_DIGOUT_NID,
5113                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5114                 .channel_mode = alc260_modes,
5115                 .input_mux = &alc260_capture_source,
5116         },
5117         [ALC260_REPLACER_672V] = {
5118                 .mixers = { alc260_replacer_672v_mixer,
5119                             alc260_capture_mixer },
5120                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
5121                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5122                 .dac_nids = alc260_dac_nids,
5123                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5124                 .adc_nids = alc260_adc_nids,
5125                 .dig_out_nid = ALC260_DIGOUT_NID,
5126                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5127                 .channel_mode = alc260_modes,
5128                 .input_mux = &alc260_capture_source,
5129                 .unsol_event = alc260_replacer_672v_unsol_event,
5130                 .init_hook = alc260_replacer_672v_automute,
5131         },
5132 #ifdef CONFIG_SND_DEBUG
5133         [ALC260_TEST] = {
5134                 .mixers = { alc260_test_mixer,
5135                             alc260_capture_mixer },
5136                 .init_verbs = { alc260_test_init_verbs },
5137                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
5138                 .dac_nids = alc260_test_dac_nids,
5139                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
5140                 .adc_nids = alc260_test_adc_nids,
5141                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5142                 .channel_mode = alc260_modes,
5143                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
5144                 .input_mux = alc260_test_capture_sources,
5145         },
5146 #endif
5147 };
5148
5149 static int patch_alc260(struct hda_codec *codec)
5150 {
5151         struct alc_spec *spec;
5152         int err, board_config;
5153
5154         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5155         if (spec == NULL)
5156                 return -ENOMEM;
5157
5158         codec->spec = spec;
5159
5160         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
5161                                                   alc260_models,
5162                                                   alc260_cfg_tbl);
5163         if (board_config < 0) {
5164                 snd_printd(KERN_INFO "hda_codec: Unknown model for ALC260, "
5165                            "trying auto-probe from BIOS...\n");
5166                 board_config = ALC260_AUTO;
5167         }
5168
5169         if (board_config == ALC260_AUTO) {
5170                 /* automatic parse from the BIOS config */
5171                 err = alc260_parse_auto_config(codec);
5172                 if (err < 0) {
5173                         alc_free(codec);
5174                         return err;
5175                 } else if (!err) {
5176                         printk(KERN_INFO
5177                                "hda_codec: Cannot set up configuration "
5178                                "from BIOS.  Using base mode...\n");
5179                         board_config = ALC260_BASIC;
5180                 }
5181         }
5182
5183         if (board_config != ALC260_AUTO)
5184                 setup_preset(spec, &alc260_presets[board_config]);
5185
5186         spec->stream_name_analog = "ALC260 Analog";
5187         spec->stream_analog_playback = &alc260_pcm_analog_playback;
5188         spec->stream_analog_capture = &alc260_pcm_analog_capture;
5189
5190         spec->stream_name_digital = "ALC260 Digital";
5191         spec->stream_digital_playback = &alc260_pcm_digital_playback;
5192         spec->stream_digital_capture = &alc260_pcm_digital_capture;
5193
5194         spec->vmaster_nid = 0x08;
5195
5196         codec->patch_ops = alc_patch_ops;
5197         if (board_config == ALC260_AUTO)
5198                 spec->init_hook = alc260_auto_init;
5199 #ifdef CONFIG_SND_HDA_POWER_SAVE
5200         if (!spec->loopback.amplist)
5201                 spec->loopback.amplist = alc260_loopbacks;
5202 #endif
5203
5204         return 0;
5205 }
5206
5207
5208 /*
5209  * ALC882 support
5210  *
5211  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5212  * configuration.  Each pin widget can choose any input DACs and a mixer.
5213  * Each ADC is connected from a mixer of all inputs.  This makes possible
5214  * 6-channel independent captures.
5215  *
5216  * In addition, an independent DAC for the multi-playback (not used in this
5217  * driver yet).
5218  */
5219 #define ALC882_DIGOUT_NID       0x06
5220 #define ALC882_DIGIN_NID        0x0a
5221
5222 static struct hda_channel_mode alc882_ch_modes[1] = {
5223         { 8, NULL }
5224 };
5225
5226 static hda_nid_t alc882_dac_nids[4] = {
5227         /* front, rear, clfe, rear_surr */
5228         0x02, 0x03, 0x04, 0x05
5229 };
5230
5231 /* identical with ALC880 */
5232 #define alc882_adc_nids         alc880_adc_nids
5233 #define alc882_adc_nids_alt     alc880_adc_nids_alt
5234
5235 static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
5236 static hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 };
5237
5238 /* input MUX */
5239 /* FIXME: should be a matrix-type input source selection */
5240
5241 static struct hda_input_mux alc882_capture_source = {
5242         .num_items = 4,
5243         .items = {
5244                 { "Mic", 0x0 },
5245                 { "Front Mic", 0x1 },
5246                 { "Line", 0x2 },
5247                 { "CD", 0x4 },
5248         },
5249 };
5250 #define alc882_mux_enum_info alc_mux_enum_info
5251 #define alc882_mux_enum_get alc_mux_enum_get
5252
5253 static int alc882_mux_enum_put(struct snd_kcontrol *kcontrol,
5254                                struct snd_ctl_elem_value *ucontrol)
5255 {
5256         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5257         struct alc_spec *spec = codec->spec;
5258         const struct hda_input_mux *imux = spec->input_mux;
5259         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
5260         hda_nid_t nid = spec->capsrc_nids ?
5261                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
5262         unsigned int *cur_val = &spec->cur_mux[adc_idx];
5263         unsigned int i, idx;
5264
5265         idx = ucontrol->value.enumerated.item[0];
5266         if (idx >= imux->num_items)
5267                 idx = imux->num_items - 1;
5268         if (*cur_val == idx)
5269                 return 0;
5270         for (i = 0; i < imux->num_items; i++) {
5271                 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
5272                 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
5273                                          imux->items[i].index,
5274                                          HDA_AMP_MUTE, v);
5275         }
5276         *cur_val = idx;
5277         return 1;
5278 }
5279
5280 /*
5281  * 2ch mode
5282  */
5283 static struct hda_verb alc882_3ST_ch2_init[] = {
5284         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
5285         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5286         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5287         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5288         { } /* end */
5289 };
5290
5291 /*
5292  * 6ch mode
5293  */
5294 static struct hda_verb alc882_3ST_ch6_init[] = {
5295         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5296         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5297         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
5298         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5299         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5300         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5301         { } /* end */
5302 };
5303
5304 static struct hda_channel_mode alc882_3ST_6ch_modes[2] = {
5305         { 2, alc882_3ST_ch2_init },
5306         { 6, alc882_3ST_ch6_init },
5307 };
5308
5309 /*
5310  * 6ch mode
5311  */
5312 static struct hda_verb alc882_sixstack_ch6_init[] = {
5313         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
5314         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5315         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5316         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5317         { } /* end */
5318 };
5319
5320 /*
5321  * 8ch mode
5322  */
5323 static struct hda_verb alc882_sixstack_ch8_init[] = {
5324         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5325         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5326         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5327         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5328         { } /* end */
5329 };
5330
5331 static struct hda_channel_mode alc882_sixstack_modes[2] = {
5332         { 6, alc882_sixstack_ch6_init },
5333         { 8, alc882_sixstack_ch8_init },
5334 };
5335
5336 /*
5337  * macbook pro ALC885 can switch LineIn to LineOut without loosing Mic
5338  */
5339
5340 /*
5341  * 2ch mode
5342  */
5343 static struct hda_verb alc885_mbp_ch2_init[] = {
5344         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5345         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5346         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5347         { } /* end */
5348 };
5349
5350 /*
5351  * 6ch mode
5352  */
5353 static struct hda_verb alc885_mbp_ch6_init[] = {
5354         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5355         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5356         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5357         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5358         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5359         { } /* end */
5360 };
5361
5362 static struct hda_channel_mode alc885_mbp_6ch_modes[2] = {
5363         { 2, alc885_mbp_ch2_init },
5364         { 6, alc885_mbp_ch6_init },
5365 };
5366
5367
5368 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
5369  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
5370  */
5371 static struct snd_kcontrol_new alc882_base_mixer[] = {
5372         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5373         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5374         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
5375         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
5376         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
5377         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
5378         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
5379         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
5380         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
5381         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
5382         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5383         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5384         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5385         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5386         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5387         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5388         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5389         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5390         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5391         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5392         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5393         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5394         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5395         { } /* end */
5396 };
5397
5398 static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
5399         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
5400         HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
5401         HDA_CODEC_MUTE  ("Speaker Playback Switch", 0x14, 0x00, HDA_OUTPUT),
5402         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
5403         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5404         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5405         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
5406         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
5407         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
5408         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
5409         { } /* end */
5410 };
5411 static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
5412         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5413         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5414         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5415         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5416         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5417         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5418         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5419         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5420         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5421         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5422         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5423         { } /* end */
5424 };
5425
5426 static struct snd_kcontrol_new alc882_targa_mixer[] = {
5427         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5428         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5429         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5430         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5431         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5432         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5433         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5434         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5435         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5436         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5437         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5438         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5439         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5440         { } /* end */
5441 };
5442
5443 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
5444  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
5445  */
5446 static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
5447         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5448         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
5449         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5450         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
5451         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5452         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5453         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5454         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5455         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
5456         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
5457         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5458         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5459         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5460         { } /* end */
5461 };
5462
5463 static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
5464         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5465         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5466         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5467         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5468         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5469         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5470         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5471         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5472         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5473         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5474         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5475         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5476         { } /* end */
5477 };
5478
5479 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
5480         {
5481                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5482                 .name = "Channel Mode",
5483                 .info = alc_ch_mode_info,
5484                 .get = alc_ch_mode_get,
5485                 .put = alc_ch_mode_put,
5486         },
5487         { } /* end */
5488 };
5489
5490 static struct hda_verb alc882_init_verbs[] = {
5491         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5492         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5493         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5494         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5495         /* Rear mixer */
5496         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5497         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5498         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5499         /* CLFE mixer */
5500         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5501         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5502         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5503         /* Side mixer */
5504         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5505         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5506         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5507
5508         /* Front Pin: output 0 (0x0c) */
5509         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5510         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5511         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5512         /* Rear Pin: output 1 (0x0d) */
5513         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5514         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5515         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5516         /* CLFE Pin: output 2 (0x0e) */
5517         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5518         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5519         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
5520         /* Side Pin: output 3 (0x0f) */
5521         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5522         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5523         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
5524         /* Mic (rear) pin: input vref at 80% */
5525         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5526         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5527         /* Front Mic pin: input vref at 80% */
5528         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5529         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5530         /* Line In pin: input */
5531         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5532         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5533         /* Line-2 In: Headphone output (output 0 - 0x0c) */
5534         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5535         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5536         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
5537         /* CD pin widget for input */
5538         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5539
5540         /* FIXME: use matrix-type input source selection */
5541         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5542         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5543         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5544         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5545         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5546         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5547         /* Input mixer2 */
5548         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5549         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5550         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5551         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5552         /* Input mixer3 */
5553         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5554         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5555         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5556         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5557         /* ADC1: mute amp left and right */
5558         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5559         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5560         /* ADC2: mute amp left and right */
5561         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5562         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5563         /* ADC3: mute amp left and right */
5564         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5565         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5566
5567         { }
5568 };
5569
5570 static struct hda_verb alc882_eapd_verbs[] = {
5571         /* change to EAPD mode */
5572         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
5573         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
5574         { }
5575 };
5576
5577 /* Mac Pro test */
5578 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
5579         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5580         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5581         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
5582         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
5583         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
5584         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT),
5585         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT),
5586         { } /* end */
5587 };
5588
5589 static struct hda_verb alc882_macpro_init_verbs[] = {
5590         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5591         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5592         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5593         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5594         /* Front Pin: output 0 (0x0c) */
5595         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5596         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5597         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
5598         /* Front Mic pin: input vref at 80% */
5599         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5600         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5601         /* Speaker:  output */
5602         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5603         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5604         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
5605         /* Headphone output (output 0 - 0x0c) */
5606         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5607         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5608         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
5609
5610         /* FIXME: use matrix-type input source selection */
5611         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5612         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5613         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5614         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5615         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5616         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5617         /* Input mixer2 */
5618         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5619         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5620         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5621         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5622         /* Input mixer3 */
5623         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5624         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5625         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5626         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5627         /* ADC1: mute amp left and right */
5628         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5629         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5630         /* ADC2: mute amp left and right */
5631         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5632         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5633         /* ADC3: mute amp left and right */
5634         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5635         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5636
5637         { }
5638 };
5639
5640 /* Macbook Pro rev3 */
5641 static struct hda_verb alc885_mbp3_init_verbs[] = {
5642         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5643         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5644         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5645         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5646         /* Rear mixer */
5647         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5648         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5649         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5650         /* Front Pin: output 0 (0x0c) */
5651         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5652         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5653         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5654         /* HP Pin: output 0 (0x0d) */
5655         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
5656         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5657         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
5658         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5659         /* Mic (rear) pin: input vref at 80% */
5660         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5661         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5662         /* Front Mic pin: input vref at 80% */
5663         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5664         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5665         /* Line In pin: use output 1 when in LineOut mode */
5666         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5667         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5668         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
5669
5670         /* FIXME: use matrix-type input source selection */
5671         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5672         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5673         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5674         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5675         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5676         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5677         /* Input mixer2 */
5678         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5679         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5680         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5681         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5682         /* Input mixer3 */
5683         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5684         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5685         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5686         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5687         /* ADC1: mute amp left and right */
5688         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5689         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5690         /* ADC2: mute amp left and right */
5691         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5692         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5693         /* ADC3: mute amp left and right */
5694         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5695         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5696
5697         { }
5698 };
5699
5700 /* iMac 24 mixer. */
5701 static struct snd_kcontrol_new alc885_imac24_mixer[] = {
5702         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
5703         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
5704         { } /* end */
5705 };
5706
5707 /* iMac 24 init verbs. */
5708 static struct hda_verb alc885_imac24_init_verbs[] = {
5709         /* Internal speakers: output 0 (0x0c) */
5710         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5711         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5712         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
5713         /* Internal speakers: output 0 (0x0c) */
5714         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5715         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5716         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
5717         /* Headphone: output 0 (0x0c) */
5718         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5719         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5720         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5721         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5722         /* Front Mic: input vref at 80% */
5723         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5724         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5725         { }
5726 };
5727
5728 /* Toggle speaker-output according to the hp-jack state */
5729 static void alc885_imac24_automute(struct hda_codec *codec)
5730 {
5731         unsigned int present;
5732
5733         present = snd_hda_codec_read(codec, 0x14, 0,
5734                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5735         snd_hda_codec_amp_stereo(codec, 0x18, HDA_OUTPUT, 0,
5736                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5737         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
5738                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5739 }
5740
5741 /* Processes unsolicited events. */
5742 static void alc885_imac24_unsol_event(struct hda_codec *codec,
5743                                       unsigned int res)
5744 {
5745         /* Headphone insertion or removal. */
5746         if ((res >> 26) == ALC880_HP_EVENT)
5747                 alc885_imac24_automute(codec);
5748 }
5749
5750 static void alc885_mbp3_automute(struct hda_codec *codec)
5751 {
5752         unsigned int present;
5753
5754         present = snd_hda_codec_read(codec, 0x15, 0,
5755                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5756         snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
5757                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5758         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
5759                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
5760
5761 }
5762 static void alc885_mbp3_unsol_event(struct hda_codec *codec,
5763                                     unsigned int res)
5764 {
5765         /* Headphone insertion or removal. */
5766         if ((res >> 26) == ALC880_HP_EVENT)
5767                 alc885_mbp3_automute(codec);
5768 }
5769
5770
5771 static struct hda_verb alc882_targa_verbs[] = {
5772         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5773         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5774
5775         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5776         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5777         
5778         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
5779         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
5780         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5781
5782         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5783         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5784         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
5785         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
5786         { } /* end */
5787 };
5788
5789 /* toggle speaker-output according to the hp-jack state */
5790 static void alc882_targa_automute(struct hda_codec *codec)
5791 {
5792         unsigned int present;
5793  
5794         present = snd_hda_codec_read(codec, 0x14, 0,
5795                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5796         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
5797                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5798         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
5799                                   present ? 1 : 3);
5800 }
5801
5802 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
5803 {
5804         /* Looks like the unsol event is incompatible with the standard
5805          * definition.  4bit tag is placed at 26 bit!
5806          */
5807         if (((res >> 26) == ALC880_HP_EVENT)) {
5808                 alc882_targa_automute(codec);
5809         }
5810 }
5811
5812 static struct hda_verb alc882_asus_a7j_verbs[] = {
5813         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5814         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5815
5816         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5817         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5818         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5819         
5820         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5821         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5822         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5823
5824         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
5825         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
5826         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5827         { } /* end */
5828 };
5829
5830 static struct hda_verb alc882_asus_a7m_verbs[] = {
5831         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5832         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5833
5834         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5835         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5836         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5837         
5838         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5839         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5840         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5841
5842         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
5843         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
5844         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5845         { } /* end */
5846 };
5847
5848 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5849 {
5850         unsigned int gpiostate, gpiomask, gpiodir;
5851
5852         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5853                                        AC_VERB_GET_GPIO_DATA, 0);
5854
5855         if (!muted)
5856                 gpiostate |= (1 << pin);
5857         else
5858                 gpiostate &= ~(1 << pin);
5859
5860         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5861                                       AC_VERB_GET_GPIO_MASK, 0);
5862         gpiomask |= (1 << pin);
5863
5864         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5865                                      AC_VERB_GET_GPIO_DIRECTION, 0);
5866         gpiodir |= (1 << pin);
5867
5868
5869         snd_hda_codec_write(codec, codec->afg, 0,
5870                             AC_VERB_SET_GPIO_MASK, gpiomask);
5871         snd_hda_codec_write(codec, codec->afg, 0,
5872                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5873
5874         msleep(1);
5875
5876         snd_hda_codec_write(codec, codec->afg, 0,
5877                             AC_VERB_SET_GPIO_DATA, gpiostate);
5878 }
5879
5880 /* set up GPIO at initialization */
5881 static void alc885_macpro_init_hook(struct hda_codec *codec)
5882 {
5883         alc882_gpio_mute(codec, 0, 0);
5884         alc882_gpio_mute(codec, 1, 0);
5885 }
5886
5887 /* set up GPIO and update auto-muting at initialization */
5888 static void alc885_imac24_init_hook(struct hda_codec *codec)
5889 {
5890         alc885_macpro_init_hook(codec);
5891         alc885_imac24_automute(codec);
5892 }
5893
5894 /*
5895  * generic initialization of ADC, input mixers and output mixers
5896  */
5897 static struct hda_verb alc882_auto_init_verbs[] = {
5898         /*
5899          * Unmute ADC0-2 and set the default input to mic-in
5900          */
5901         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5902         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5903         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5904         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5905         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5906         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5907
5908         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5909          * mixer widget
5910          * Note: PASD motherboards uses the Line In 2 as the input for
5911          * front panel mic (mic 2)
5912          */
5913         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
5914         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5915         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5916         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5917         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5918         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5919
5920         /*
5921          * Set up output mixers (0x0c - 0x0f)
5922          */
5923         /* set vol=0 to output mixers */
5924         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5925         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5926         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5927         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5928         /* set up input amps for analog loopback */
5929         /* Amp Indices: DAC = 0, mixer = 1 */
5930         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5931         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5932         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5933         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5934         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5935         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5936         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5937         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5938         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5939         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5940
5941         /* FIXME: use matrix-type input source selection */
5942         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5943         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5944         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5945         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
5946         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
5947         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
5948         /* Input mixer2 */
5949         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5950         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
5951         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
5952         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
5953         /* Input mixer3 */
5954         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5955         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
5956         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
5957         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
5958
5959         { }
5960 };
5961
5962 /* capture mixer elements */
5963 static struct snd_kcontrol_new alc882_capture_alt_mixer[] = {
5964         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
5965         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
5966         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
5967         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
5968         {
5969                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5970                 /* The multiple "Capture Source" controls confuse alsamixer
5971                  * So call somewhat different..
5972                  */
5973                 /* .name = "Capture Source", */
5974                 .name = "Input Source",
5975                 .count = 2,
5976                 .info = alc882_mux_enum_info,
5977                 .get = alc882_mux_enum_get,
5978                 .put = alc882_mux_enum_put,
5979         },
5980         { } /* end */
5981 };
5982
5983 static struct snd_kcontrol_new alc882_capture_mixer[] = {
5984         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
5985         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
5986         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
5987         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
5988         HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
5989         HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
5990         {
5991                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5992                 /* The multiple "Capture Source" controls confuse alsamixer
5993                  * So call somewhat different..
5994                  */
5995                 /* .name = "Capture Source", */
5996                 .name = "Input Source",
5997                 .count = 3,
5998                 .info = alc882_mux_enum_info,
5999                 .get = alc882_mux_enum_get,
6000                 .put = alc882_mux_enum_put,
6001         },
6002         { } /* end */
6003 };
6004
6005 #ifdef CONFIG_SND_HDA_POWER_SAVE
6006 #define alc882_loopbacks        alc880_loopbacks
6007 #endif
6008
6009 /* pcm configuration: identiacal with ALC880 */
6010 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
6011 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
6012 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
6013 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
6014
6015 /*
6016  * configuration and preset
6017  */
6018 static const char *alc882_models[ALC882_MODEL_LAST] = {
6019         [ALC882_3ST_DIG]        = "3stack-dig",
6020         [ALC882_6ST_DIG]        = "6stack-dig",
6021         [ALC882_ARIMA]          = "arima",
6022         [ALC882_W2JC]           = "w2jc",
6023         [ALC882_TARGA]          = "targa",
6024         [ALC882_ASUS_A7J]       = "asus-a7j",
6025         [ALC882_ASUS_A7M]       = "asus-a7m",
6026         [ALC885_MACPRO]         = "macpro",
6027         [ALC885_MBP3]           = "mbp3",
6028         [ALC885_IMAC24]         = "imac24",
6029         [ALC882_AUTO]           = "auto",
6030 };
6031
6032 static struct snd_pci_quirk alc882_cfg_tbl[] = {
6033         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
6034         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
6035         SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
6036         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
6037         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
6038         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
6039         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
6040         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
6041         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),
6042         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
6043         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
6044         SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA),
6045         {}
6046 };
6047
6048 static struct alc_config_preset alc882_presets[] = {
6049         [ALC882_3ST_DIG] = {
6050                 .mixers = { alc882_base_mixer },
6051                 .init_verbs = { alc882_init_verbs },
6052                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6053                 .dac_nids = alc882_dac_nids,
6054                 .dig_out_nid = ALC882_DIGOUT_NID,
6055                 .dig_in_nid = ALC882_DIGIN_NID,
6056                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6057                 .channel_mode = alc882_ch_modes,
6058                 .need_dac_fix = 1,
6059                 .input_mux = &alc882_capture_source,
6060         },
6061         [ALC882_6ST_DIG] = {
6062                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6063                 .init_verbs = { alc882_init_verbs },
6064                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6065                 .dac_nids = alc882_dac_nids,
6066                 .dig_out_nid = ALC882_DIGOUT_NID,
6067                 .dig_in_nid = ALC882_DIGIN_NID,
6068                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6069                 .channel_mode = alc882_sixstack_modes,
6070                 .input_mux = &alc882_capture_source,
6071         },
6072         [ALC882_ARIMA] = {
6073                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6074                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs },
6075                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6076                 .dac_nids = alc882_dac_nids,
6077                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6078                 .channel_mode = alc882_sixstack_modes,
6079                 .input_mux = &alc882_capture_source,
6080         },
6081         [ALC882_W2JC] = {
6082                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
6083                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6084                                 alc880_gpio1_init_verbs },
6085                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6086                 .dac_nids = alc882_dac_nids,
6087                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6088                 .channel_mode = alc880_threestack_modes,
6089                 .need_dac_fix = 1,
6090                 .input_mux = &alc882_capture_source,
6091                 .dig_out_nid = ALC882_DIGOUT_NID,
6092         },
6093         [ALC885_MBP3] = {
6094                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
6095                 .init_verbs = { alc885_mbp3_init_verbs,
6096                                 alc880_gpio1_init_verbs },
6097                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6098                 .dac_nids = alc882_dac_nids,
6099                 .channel_mode = alc885_mbp_6ch_modes,
6100                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_6ch_modes),
6101                 .input_mux = &alc882_capture_source,
6102                 .dig_out_nid = ALC882_DIGOUT_NID,
6103                 .dig_in_nid = ALC882_DIGIN_NID,
6104                 .unsol_event = alc885_mbp3_unsol_event,
6105                 .init_hook = alc885_mbp3_automute,
6106         },
6107         [ALC885_MACPRO] = {
6108                 .mixers = { alc882_macpro_mixer },
6109                 .init_verbs = { alc882_macpro_init_verbs },
6110                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6111                 .dac_nids = alc882_dac_nids,
6112                 .dig_out_nid = ALC882_DIGOUT_NID,
6113                 .dig_in_nid = ALC882_DIGIN_NID,
6114                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6115                 .channel_mode = alc882_ch_modes,
6116                 .input_mux = &alc882_capture_source,
6117                 .init_hook = alc885_macpro_init_hook,
6118         },
6119         [ALC885_IMAC24] = {
6120                 .mixers = { alc885_imac24_mixer },
6121                 .init_verbs = { alc885_imac24_init_verbs },
6122                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6123                 .dac_nids = alc882_dac_nids,
6124                 .dig_out_nid = ALC882_DIGOUT_NID,
6125                 .dig_in_nid = ALC882_DIGIN_NID,
6126                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6127                 .channel_mode = alc882_ch_modes,
6128                 .input_mux = &alc882_capture_source,
6129                 .unsol_event = alc885_imac24_unsol_event,
6130                 .init_hook = alc885_imac24_init_hook,
6131         },
6132         [ALC882_TARGA] = {
6133                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer,
6134                             alc882_capture_mixer },
6135                 .init_verbs = { alc882_init_verbs, alc882_targa_verbs},
6136                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6137                 .dac_nids = alc882_dac_nids,
6138                 .dig_out_nid = ALC882_DIGOUT_NID,
6139                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6140                 .adc_nids = alc882_adc_nids,
6141                 .capsrc_nids = alc882_capsrc_nids,
6142                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6143                 .channel_mode = alc882_3ST_6ch_modes,
6144                 .need_dac_fix = 1,
6145                 .input_mux = &alc882_capture_source,
6146                 .unsol_event = alc882_targa_unsol_event,
6147                 .init_hook = alc882_targa_automute,
6148         },
6149         [ALC882_ASUS_A7J] = {
6150                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer,
6151                             alc882_capture_mixer },
6152                 .init_verbs = { alc882_init_verbs, alc882_asus_a7j_verbs},
6153                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6154                 .dac_nids = alc882_dac_nids,
6155                 .dig_out_nid = ALC882_DIGOUT_NID,
6156                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6157                 .adc_nids = alc882_adc_nids,
6158                 .capsrc_nids = alc882_capsrc_nids,
6159                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6160                 .channel_mode = alc882_3ST_6ch_modes,
6161                 .need_dac_fix = 1,
6162                 .input_mux = &alc882_capture_source,
6163         },      
6164         [ALC882_ASUS_A7M] = {
6165                 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
6166                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6167                                 alc880_gpio1_init_verbs,
6168                                 alc882_asus_a7m_verbs },
6169                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6170                 .dac_nids = alc882_dac_nids,
6171                 .dig_out_nid = ALC882_DIGOUT_NID,
6172                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6173                 .channel_mode = alc880_threestack_modes,
6174                 .need_dac_fix = 1,
6175                 .input_mux = &alc882_capture_source,
6176         },      
6177 };
6178
6179
6180 /*
6181  * Pin config fixes
6182  */
6183 enum { 
6184         PINFIX_ABIT_AW9D_MAX
6185 };
6186
6187 static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
6188         { 0x15, 0x01080104 }, /* side */
6189         { 0x16, 0x01011012 }, /* rear */
6190         { 0x17, 0x01016011 }, /* clfe */
6191         { }
6192 };
6193
6194 static const struct alc_pincfg *alc882_pin_fixes[] = {
6195         [PINFIX_ABIT_AW9D_MAX] = alc882_abit_aw9d_pinfix,
6196 };
6197
6198 static struct snd_pci_quirk alc882_pinfix_tbl[] = {
6199         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
6200         {}
6201 };
6202
6203 /*
6204  * BIOS auto configuration
6205  */
6206 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
6207                                               hda_nid_t nid, int pin_type,
6208                                               int dac_idx)
6209 {
6210         /* set as output */
6211         struct alc_spec *spec = codec->spec;
6212         int idx;
6213
6214         alc_set_pin_output(codec, nid, pin_type);
6215         if (spec->multiout.dac_nids[dac_idx] == 0x25)
6216                 idx = 4;
6217         else
6218                 idx = spec->multiout.dac_nids[dac_idx] - 2;
6219         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
6220
6221 }
6222
6223 static void alc882_auto_init_multi_out(struct hda_codec *codec)
6224 {
6225         struct alc_spec *spec = codec->spec;
6226         int i;
6227
6228         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
6229         for (i = 0; i <= HDA_SIDE; i++) {
6230                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
6231                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
6232                 if (nid)
6233                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
6234                                                           i);
6235         }
6236 }
6237
6238 static void alc882_auto_init_hp_out(struct hda_codec *codec)
6239 {
6240         struct alc_spec *spec = codec->spec;
6241         hda_nid_t pin;
6242
6243         pin = spec->autocfg.hp_pins[0];
6244         if (pin) /* connect to front */
6245                 /* use dac 0 */
6246                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
6247         pin = spec->autocfg.speaker_pins[0];
6248         if (pin)
6249                 alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
6250 }
6251
6252 #define alc882_is_input_pin(nid)        alc880_is_input_pin(nid)
6253 #define ALC882_PIN_CD_NID               ALC880_PIN_CD_NID
6254
6255 static void alc882_auto_init_analog_input(struct hda_codec *codec)
6256 {
6257         struct alc_spec *spec = codec->spec;
6258         int i;
6259
6260         for (i = 0; i < AUTO_PIN_LAST; i++) {
6261                 hda_nid_t nid = spec->autocfg.input_pins[i];
6262                 unsigned int vref;
6263                 if (!nid)
6264                         continue;
6265                 vref = PIN_IN;
6266                 if (1 /*i <= AUTO_PIN_FRONT_MIC*/) {
6267                         if (snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP) &
6268                             AC_PINCAP_VREF_80)
6269                                 vref = PIN_VREF80;
6270                 }
6271                 snd_hda_codec_write(codec, nid, 0,
6272                                     AC_VERB_SET_PIN_WIDGET_CONTROL, vref);
6273                 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
6274                         snd_hda_codec_write(codec, nid, 0,
6275                                             AC_VERB_SET_AMP_GAIN_MUTE,
6276                                             AMP_OUT_MUTE);
6277         }
6278 }
6279
6280 /* add mic boosts if needed */
6281 static int alc_auto_add_mic_boost(struct hda_codec *codec)
6282 {
6283         struct alc_spec *spec = codec->spec;
6284         int err;
6285         hda_nid_t nid;
6286
6287         nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
6288         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6289                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6290                                   "Mic Boost",
6291                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6292                 if (err < 0)
6293                         return err;
6294         }
6295         nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
6296         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6297                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6298                                   "Front Mic Boost",
6299                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6300                 if (err < 0)
6301                         return err;
6302         }
6303         return 0;
6304 }
6305
6306 /* almost identical with ALC880 parser... */
6307 static int alc882_parse_auto_config(struct hda_codec *codec)
6308 {
6309         struct alc_spec *spec = codec->spec;
6310         int err = alc880_parse_auto_config(codec);
6311
6312         if (err < 0)
6313                 return err;
6314         else if (!err)
6315                 return 0; /* no config found */
6316
6317         err = alc_auto_add_mic_boost(codec);
6318         if (err < 0)
6319                 return err;
6320
6321         /* hack - override the init verbs */
6322         spec->init_verbs[0] = alc882_auto_init_verbs;
6323
6324         return 1; /* config found */
6325 }
6326
6327 /* additional initialization for auto-configuration model */
6328 static void alc882_auto_init(struct hda_codec *codec)
6329 {
6330         struct alc_spec *spec = codec->spec;
6331         alc882_auto_init_multi_out(codec);
6332         alc882_auto_init_hp_out(codec);
6333         alc882_auto_init_analog_input(codec);
6334         if (spec->unsol_event)
6335                 alc_sku_automute(codec);
6336 }
6337
6338 static int patch_alc882(struct hda_codec *codec)
6339 {
6340         struct alc_spec *spec;
6341         int err, board_config;
6342
6343         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6344         if (spec == NULL)
6345                 return -ENOMEM;
6346
6347         codec->spec = spec;
6348
6349         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
6350                                                   alc882_models,
6351                                                   alc882_cfg_tbl);
6352
6353         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
6354                 /* Pick up systems that don't supply PCI SSID */
6355                 switch (codec->subsystem_id) {
6356                 case 0x106b0c00: /* Mac Pro */
6357                         board_config = ALC885_MACPRO;
6358                         break;
6359                 case 0x106b1000: /* iMac 24 */
6360                         board_config = ALC885_IMAC24;
6361                         break;
6362                 case 0x106b00a1: /* Macbook */
6363                 case 0x106b2c00: /* Macbook Pro rev3 */
6364                         board_config = ALC885_MBP3;
6365                         break;
6366                 default:
6367                         printk(KERN_INFO "hda_codec: Unknown model for ALC882, "
6368                                          "trying auto-probe from BIOS...\n");
6369                         board_config = ALC882_AUTO;
6370                 }
6371         }
6372
6373         alc_fix_pincfg(codec, alc882_pinfix_tbl, alc882_pin_fixes);
6374
6375         if (board_config == ALC882_AUTO) {
6376                 /* automatic parse from the BIOS config */
6377                 err = alc882_parse_auto_config(codec);
6378                 if (err < 0) {
6379                         alc_free(codec);
6380                         return err;
6381                 } else if (!err) {
6382                         printk(KERN_INFO
6383                                "hda_codec: Cannot set up configuration "
6384                                "from BIOS.  Using base mode...\n");
6385                         board_config = ALC882_3ST_DIG;
6386                 }
6387         }
6388
6389         if (board_config != ALC882_AUTO)
6390                 setup_preset(spec, &alc882_presets[board_config]);
6391
6392         spec->stream_name_analog = "ALC882 Analog";
6393         spec->stream_analog_playback = &alc882_pcm_analog_playback;
6394         spec->stream_analog_capture = &alc882_pcm_analog_capture;
6395         /* FIXME: setup DAC5 */
6396         /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
6397         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
6398
6399         spec->stream_name_digital = "ALC882 Digital";
6400         spec->stream_digital_playback = &alc882_pcm_digital_playback;
6401         spec->stream_digital_capture = &alc882_pcm_digital_capture;
6402
6403         if (!spec->adc_nids && spec->input_mux) {
6404                 /* check whether NID 0x07 is valid */
6405                 unsigned int wcap = get_wcaps(codec, 0x07);
6406                 /* get type */
6407                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
6408                 if (wcap != AC_WID_AUD_IN) {
6409                         spec->adc_nids = alc882_adc_nids_alt;
6410                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
6411                         spec->capsrc_nids = alc882_capsrc_nids_alt;
6412                         spec->mixers[spec->num_mixers] =
6413                                 alc882_capture_alt_mixer;
6414                         spec->num_mixers++;
6415                 } else {
6416                         spec->adc_nids = alc882_adc_nids;
6417                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
6418                         spec->capsrc_nids = alc882_capsrc_nids;
6419                         spec->mixers[spec->num_mixers] = alc882_capture_mixer;
6420                         spec->num_mixers++;
6421                 }
6422         }
6423
6424         spec->vmaster_nid = 0x0c;
6425
6426         codec->patch_ops = alc_patch_ops;
6427         if (board_config == ALC882_AUTO)
6428                 spec->init_hook = alc882_auto_init;
6429 #ifdef CONFIG_SND_HDA_POWER_SAVE
6430         if (!spec->loopback.amplist)
6431                 spec->loopback.amplist = alc882_loopbacks;
6432 #endif
6433
6434         return 0;
6435 }
6436
6437 /*
6438  * ALC883 support
6439  *
6440  * ALC883 is almost identical with ALC880 but has cleaner and more flexible
6441  * configuration.  Each pin widget can choose any input DACs and a mixer.
6442  * Each ADC is connected from a mixer of all inputs.  This makes possible
6443  * 6-channel independent captures.
6444  *
6445  * In addition, an independent DAC for the multi-playback (not used in this
6446  * driver yet).
6447  */
6448 #define ALC883_DIGOUT_NID       0x06
6449 #define ALC883_DIGIN_NID        0x0a
6450
6451 static hda_nid_t alc883_dac_nids[4] = {
6452         /* front, rear, clfe, rear_surr */
6453         0x02, 0x04, 0x03, 0x05
6454 };
6455
6456 static hda_nid_t alc883_adc_nids[2] = {
6457         /* ADC1-2 */
6458         0x08, 0x09,
6459 };
6460
6461 static hda_nid_t alc883_capsrc_nids[2] = { 0x23, 0x22 };
6462
6463 /* input MUX */
6464 /* FIXME: should be a matrix-type input source selection */
6465
6466 static struct hda_input_mux alc883_capture_source = {
6467         .num_items = 4,
6468         .items = {
6469                 { "Mic", 0x0 },
6470                 { "Front Mic", 0x1 },
6471                 { "Line", 0x2 },
6472                 { "CD", 0x4 },
6473         },
6474 };
6475
6476 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
6477         .num_items = 2,
6478         .items = {
6479                 { "Mic", 0x1 },
6480                 { "Line", 0x2 },
6481         },
6482 };
6483
6484 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
6485         .num_items = 4,
6486         .items = {
6487                 { "Mic", 0x0 },
6488                 { "iMic", 0x1 },
6489                 { "Line", 0x2 },
6490                 { "CD", 0x4 },
6491         },
6492 };
6493
6494 static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
6495         .num_items = 2,
6496         .items = {
6497                 { "Mic", 0x0 },
6498                 { "Int Mic", 0x1 },
6499         },
6500 };
6501
6502 #define alc883_mux_enum_info alc_mux_enum_info
6503 #define alc883_mux_enum_get alc_mux_enum_get
6504 /* ALC883 has the ALC882-type input selection */
6505 #define alc883_mux_enum_put alc882_mux_enum_put
6506
6507 /*
6508  * 2ch mode
6509  */
6510 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
6511         { 2, NULL }
6512 };
6513
6514 /*
6515  * 2ch mode
6516  */
6517 static struct hda_verb alc883_3ST_ch2_init[] = {
6518         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6519         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6520         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6521         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6522         { } /* end */
6523 };
6524
6525 /*
6526  * 4ch mode
6527  */
6528 static struct hda_verb alc883_3ST_ch4_init[] = {
6529         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6530         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6531         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6532         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6533         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6534         { } /* end */
6535 };
6536
6537 /*
6538  * 6ch mode
6539  */
6540 static struct hda_verb alc883_3ST_ch6_init[] = {
6541         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6542         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6543         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6544         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6545         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6546         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6547         { } /* end */
6548 };
6549
6550 static struct hda_channel_mode alc883_3ST_6ch_modes[3] = {
6551         { 2, alc883_3ST_ch2_init },
6552         { 4, alc883_3ST_ch4_init },
6553         { 6, alc883_3ST_ch6_init },
6554 };
6555
6556 /*
6557  * 6ch mode
6558  */
6559 static struct hda_verb alc883_sixstack_ch6_init[] = {
6560         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6561         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6562         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6563         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6564         { } /* end */
6565 };
6566
6567 /*
6568  * 8ch mode
6569  */
6570 static struct hda_verb alc883_sixstack_ch8_init[] = {
6571         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6572         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6573         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6574         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6575         { } /* end */
6576 };
6577
6578 static struct hda_channel_mode alc883_sixstack_modes[2] = {
6579         { 6, alc883_sixstack_ch6_init },
6580         { 8, alc883_sixstack_ch8_init },
6581 };
6582
6583 static struct hda_verb alc883_medion_eapd_verbs[] = {
6584         /* eanable EAPD on medion laptop */
6585         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
6586         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
6587         { }
6588 };
6589
6590 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
6591  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
6592  */
6593
6594 static struct snd_kcontrol_new alc883_base_mixer[] = {
6595         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6596         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6597         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6598         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6599         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6600         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6601         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6602         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6603         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6604         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6605         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6606         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6607         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6608         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6609         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6610         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6611         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6612         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6613         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6614         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6615         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6616         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6617         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6618         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6619         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6620         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6621         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6622         {
6623                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6624                 /* .name = "Capture Source", */
6625                 .name = "Input Source",
6626                 .count = 2,
6627                 .info = alc883_mux_enum_info,
6628                 .get = alc883_mux_enum_get,
6629                 .put = alc883_mux_enum_put,
6630         },
6631         { } /* end */
6632 };
6633
6634 static struct snd_kcontrol_new alc883_mitac_mixer[] = {
6635         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6636         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6637         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6638         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6639         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6640         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6641         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6642         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6643         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6644         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6645         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6646         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6647         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6648         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6649         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6650         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6651         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6652         {
6653                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6654                 /* .name = "Capture Source", */
6655                 .name = "Input Source",
6656                 .count = 2,
6657                 .info = alc883_mux_enum_info,
6658                 .get = alc883_mux_enum_get,
6659                 .put = alc883_mux_enum_put,
6660         },
6661         { } /* end */
6662 };
6663
6664 static struct snd_kcontrol_new alc883_clevo_m720r_mixer[] = {
6665         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6666         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
6667         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6668         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
6669         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6670         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6671         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6672         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6673         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
6674         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6675         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6676         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6677         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6678         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6679         {
6680                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6681                 /* .name = "Capture Source", */
6682                 .name = "Input Source",
6683                 .count = 2,
6684                 .info = alc883_mux_enum_info,
6685                 .get = alc883_mux_enum_get,
6686                 .put = alc883_mux_enum_put,
6687         },
6688         { } /* end */
6689 };
6690
6691 static struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
6692         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6693         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
6694         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6695         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
6696         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6697         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6698         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6699         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6700         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
6701         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6702         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6703         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6704         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6705         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6706         {
6707                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6708                 /* .name = "Capture Source", */
6709                 .name = "Input Source",
6710                 .count = 2,
6711                 .info = alc883_mux_enum_info,
6712                 .get = alc883_mux_enum_get,
6713                 .put = alc883_mux_enum_put,
6714         },
6715         { } /* end */
6716 };
6717
6718 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
6719         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6720         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6721         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6722         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6723         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6724         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6725         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6726         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6727         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6728         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6729         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6730         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6731         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6732         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6733         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6734         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6735         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6736         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6737         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6738         {
6739                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6740                 /* .name = "Capture Source", */
6741                 .name = "Input Source",
6742                 .count = 2,
6743                 .info = alc883_mux_enum_info,
6744                 .get = alc883_mux_enum_get,
6745                 .put = alc883_mux_enum_put,
6746         },
6747         { } /* end */
6748 };
6749
6750 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
6751         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6752         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6753         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6754         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6755         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6756         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6757         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6758         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6759         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6760         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6761         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6762         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6763         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6764         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6765         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6766         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6767         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6768         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6769         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6770         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6771         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6772         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6773         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6774         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6775         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6776         {
6777                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6778                 /* .name = "Capture Source", */
6779                 .name = "Input Source",
6780                 .count = 2,
6781                 .info = alc883_mux_enum_info,
6782                 .get = alc883_mux_enum_get,
6783                 .put = alc883_mux_enum_put,
6784         },
6785         { } /* end */
6786 };
6787
6788 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
6789         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6790         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6791         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6792         HDA_CODEC_MUTE("Surround Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6793         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6794         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6795         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x16, 1, 0x0, HDA_OUTPUT),
6796         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
6797         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6798         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6799         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6800         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6801         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6802         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6803         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6804         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6805         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6806         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6807         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6808         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6809         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6810         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6811         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6812
6813         {
6814                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6815                 /* .name = "Capture Source", */
6816                 .name = "Input Source",
6817                 .count = 1,
6818                 .info = alc883_mux_enum_info,
6819                 .get = alc883_mux_enum_get,
6820                 .put = alc883_mux_enum_put,
6821         },
6822         { } /* end */
6823 };
6824
6825 static struct snd_kcontrol_new alc883_tagra_mixer[] = {
6826         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6827         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6828         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6829         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6830         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6831         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6832         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6833         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6834         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6835         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6836         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6837         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6838         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6839         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6840         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6841         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6842         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6843         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6844         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6845         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6846         {
6847                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6848                 /* .name = "Capture Source", */
6849                 .name = "Input Source",
6850                 .count = 2,
6851                 .info = alc883_mux_enum_info,
6852                 .get = alc883_mux_enum_get,
6853                 .put = alc883_mux_enum_put,
6854         },
6855         { } /* end */
6856 };
6857
6858 static struct snd_kcontrol_new alc883_tagra_2ch_mixer[] = {
6859         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6860         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6861         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6862         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6863         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6864         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6865         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6866         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6867         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6868         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6869         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6870         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6871         {
6872                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6873                 /* .name = "Capture Source", */
6874                 .name = "Input Source",
6875                 .count = 2,
6876                 .info = alc883_mux_enum_info,
6877                 .get = alc883_mux_enum_get,
6878                 .put = alc883_mux_enum_put,
6879         },
6880         { } /* end */
6881 };
6882
6883 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
6884         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6885         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6886         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6887         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
6888         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6889         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6890         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6891         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6892         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6893         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6894         {
6895                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6896                 /* .name = "Capture Source", */
6897                 .name = "Input Source",
6898                 .count = 1,
6899                 .info = alc883_mux_enum_info,
6900                 .get = alc883_mux_enum_get,
6901                 .put = alc883_mux_enum_put,
6902         },
6903         { } /* end */
6904 };
6905
6906 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
6907         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6908         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
6909         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6910         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6911         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6912         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6913         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6914         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6915         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6916         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6917         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6918         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6919         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6920         {
6921                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6922                 /* .name = "Capture Source", */
6923                 .name = "Input Source",
6924                 .count = 2,
6925                 .info = alc883_mux_enum_info,
6926                 .get = alc883_mux_enum_get,
6927                 .put = alc883_mux_enum_put,
6928         },
6929         { } /* end */
6930 };
6931
6932 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
6933         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6934         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6935         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6936         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6937         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6938         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6939         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6940         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6941         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
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                 /* .name = "Capture Source", */
6949                 .name = "Input Source",
6950                 .count = 2,
6951                 .info = alc883_mux_enum_info,
6952                 .get = alc883_mux_enum_get,
6953                 .put = alc883_mux_enum_put,
6954         },
6955         { } /* end */
6956 };      
6957
6958 static struct snd_kcontrol_new alc888_6st_hp_mixer[] = {
6959         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6960         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6961         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
6962         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
6963         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
6964         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
6965         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
6966         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
6967         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6968         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6969         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6970         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6971         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6972         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6973         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6974         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6975         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6976         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6977         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6978         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6979         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6980         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6981         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6982         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6983         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6984         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6985         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6986         {
6987                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6988                 /* .name = "Capture Source", */
6989                 .name = "Input Source",
6990                 .count = 2,
6991                 .info = alc883_mux_enum_info,
6992                 .get = alc883_mux_enum_get,
6993                 .put = alc883_mux_enum_put,
6994         },
6995         { } /* end */
6996 };
6997
6998 static struct snd_kcontrol_new alc888_3st_hp_mixer[] = {
6999         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7000         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7001         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
7002         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
7003         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
7004         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
7005         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
7006         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
7007         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7008         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7009         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7010         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7011         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7012         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7013         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7014         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7015         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7016         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7017         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7018         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7019         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7020         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7021         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7022         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7023         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7024         {
7025                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7026                 /* .name = "Capture Source", */
7027                 .name = "Input Source",
7028                 .count = 2,
7029                 .info = alc883_mux_enum_info,
7030                 .get = alc883_mux_enum_get,
7031                 .put = alc883_mux_enum_put,
7032         },
7033         { } /* end */
7034 };
7035
7036 static struct snd_kcontrol_new alc888_6st_dell_mixer[] = {
7037         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7038         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7039         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
7040         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
7041         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
7042         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
7043         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
7044         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
7045         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7046         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7047         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7048         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7049         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7050         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7051         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7052         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7053         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7054         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7055         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7056         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7057         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7058         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7059         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7060         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7061         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7062         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7063         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7064         {
7065                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7066                 /* .name = "Capture Source", */
7067                 .name = "Input Source",
7068                 .count = 2,
7069                 .info = alc883_mux_enum_info,
7070                 .get = alc883_mux_enum_get,
7071                 .put = alc883_mux_enum_put,
7072         },
7073         { } /* end */
7074 };
7075
7076 static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
7077         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7078         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7079         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7080         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7081         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7082         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7083         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7084         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7085         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7086         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7087         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7088         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7089         {
7090                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7091                 /* .name = "Capture Source", */
7092                 .name = "Input Source",
7093                 .count = 2,
7094                 .info = alc883_mux_enum_info,
7095                 .get = alc883_mux_enum_get,
7096                 .put = alc883_mux_enum_put,
7097         },
7098         { } /* end */
7099 };
7100
7101 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
7102         {
7103                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7104                 .name = "Channel Mode",
7105                 .info = alc_ch_mode_info,
7106                 .get = alc_ch_mode_get,
7107                 .put = alc_ch_mode_put,
7108         },
7109         { } /* end */
7110 };
7111
7112 static struct hda_verb alc883_init_verbs[] = {
7113         /* ADC1: mute amp left and right */
7114         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7115         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7116         /* ADC2: mute amp left and right */
7117         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7118         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7119         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7120         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7121         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7122         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7123         /* Rear mixer */
7124         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7125         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7126         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7127         /* CLFE mixer */
7128         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7129         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7130         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7131         /* Side mixer */
7132         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7133         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7134         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7135
7136         /* mute analog input loopbacks */
7137         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7138         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7139         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7140         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7141         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7142
7143         /* Front Pin: output 0 (0x0c) */
7144         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7145         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7146         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7147         /* Rear Pin: output 1 (0x0d) */
7148         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7149         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7150         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7151         /* CLFE Pin: output 2 (0x0e) */
7152         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7153         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7154         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
7155         /* Side Pin: output 3 (0x0f) */
7156         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7157         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7158         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
7159         /* Mic (rear) pin: input vref at 80% */
7160         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7161         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7162         /* Front Mic pin: input vref at 80% */
7163         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7164         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7165         /* Line In pin: input */
7166         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7167         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7168         /* Line-2 In: Headphone output (output 0 - 0x0c) */
7169         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7170         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7171         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7172         /* CD pin widget for input */
7173         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7174
7175         /* FIXME: use matrix-type input source selection */
7176         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7177         /* Input mixer2 */
7178         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7179         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7180         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7181         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7182         /* Input mixer3 */
7183         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7184         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7185         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7186         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7187         { }
7188 };
7189
7190 /* toggle speaker-output according to the hp-jack state */
7191 static void alc883_mitac_hp_automute(struct hda_codec *codec)
7192 {
7193         unsigned int present;
7194
7195         present = snd_hda_codec_read(codec, 0x15, 0,
7196                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7197         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7198                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7199         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
7200                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7201 }
7202
7203 /* auto-toggle front mic */
7204 /*
7205 static void alc883_mitac_mic_automute(struct hda_codec *codec)
7206 {
7207         unsigned int present;
7208         unsigned char bits;
7209
7210         present = snd_hda_codec_read(codec, 0x18, 0,
7211                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7212         bits = present ? HDA_AMP_MUTE : 0;
7213         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
7214 }
7215 */
7216
7217 static void alc883_mitac_automute(struct hda_codec *codec)
7218 {
7219         alc883_mitac_hp_automute(codec);
7220         /* alc883_mitac_mic_automute(codec); */
7221 }
7222
7223 static void alc883_mitac_unsol_event(struct hda_codec *codec,
7224                                            unsigned int res)
7225 {
7226         switch (res >> 26) {
7227         case ALC880_HP_EVENT:
7228                 alc883_mitac_hp_automute(codec);
7229                 break;
7230         case ALC880_MIC_EVENT:
7231                 /* alc883_mitac_mic_automute(codec); */
7232                 break;
7233         }
7234 }
7235
7236 static struct hda_verb alc883_mitac_verbs[] = {
7237         /* HP */
7238         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7239         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7240         /* Subwoofer */
7241         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
7242         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7243
7244         /* enable unsolicited event */
7245         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7246         /* {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN}, */
7247
7248         { } /* end */
7249 };
7250
7251 static struct hda_verb alc883_clevo_m720r_verbs[] = {
7252         /* HP */
7253         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7254         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7255         /* Int speaker */
7256         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
7257         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7258
7259         /* enable unsolicited event */
7260         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7261
7262         { } /* end */
7263 };
7264
7265 static struct hda_verb alc883_2ch_fujitsu_pi2515_verbs[] = {
7266         /* HP */
7267         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7268         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7269         /* Subwoofer */
7270         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7271         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7272
7273         /* enable unsolicited event */
7274         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7275
7276         { } /* end */
7277 };
7278
7279 static struct hda_verb alc883_tagra_verbs[] = {
7280         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7281         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7282
7283         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7284         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7285         
7286         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7287         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7288         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7289
7290         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7291         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
7292         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
7293         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
7294
7295         { } /* end */
7296 };
7297
7298 static struct hda_verb alc883_lenovo_101e_verbs[] = {
7299         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7300         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
7301         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
7302         { } /* end */
7303 };
7304
7305 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
7306         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7307         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7308         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7309         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7310         { } /* end */
7311 };
7312
7313 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
7314         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7315         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7316         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7317         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
7318         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
7319         { } /* end */
7320 };
7321
7322 static struct hda_verb alc883_haier_w66_verbs[] = {
7323         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7324         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7325
7326         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7327
7328         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7329         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7330         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7331         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7332         { } /* end */
7333 };
7334
7335 static struct hda_verb alc888_6st_hp_verbs[] = {
7336         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
7337         {0x15, AC_VERB_SET_CONNECT_SEL, 0x02},  /* Rear : output 2 (0x0e) */
7338         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* CLFE : output 1 (0x0d) */
7339         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},  /* Side : output 3 (0x0f) */
7340         { }
7341 };
7342
7343 static struct hda_verb alc888_3st_hp_verbs[] = {
7344         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
7345         {0x18, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
7346         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
7347         { }
7348 };
7349
7350 static struct hda_verb alc888_6st_dell_verbs[] = {
7351         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
7352         {0x15, AC_VERB_SET_CONNECT_SEL, 0x02},  /* Rear : output 1 (0x0e) */
7353         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* CLFE : output 2 (0x0d) */
7354         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},  /* Side : output 3 (0x0f) */
7355         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7356         { }
7357 };
7358
7359 static struct hda_verb alc888_3st_hp_2ch_init[] = {
7360         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7361         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7362         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7363         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7364         { }
7365 };
7366
7367 static struct hda_verb alc888_3st_hp_6ch_init[] = {
7368         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7369         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7370         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7371         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7372         { }
7373 };
7374
7375 static struct hda_channel_mode alc888_3st_hp_modes[2] = {
7376         { 2, alc888_3st_hp_2ch_init },
7377         { 6, alc888_3st_hp_6ch_init },
7378 };
7379
7380 /* toggle front-jack and RCA according to the hp-jack state */
7381 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
7382 {
7383         unsigned int present;
7384  
7385         present = snd_hda_codec_read(codec, 0x1b, 0,
7386                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7387         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7388                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7389         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7390                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7391 }
7392
7393 /* toggle RCA according to the front-jack state */
7394 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
7395 {
7396         unsigned int present;
7397  
7398         present = snd_hda_codec_read(codec, 0x14, 0,
7399                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7400         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7401                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7402 }
7403
7404 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
7405                                              unsigned int res)
7406 {
7407         if ((res >> 26) == ALC880_HP_EVENT)
7408                 alc888_lenovo_ms7195_front_automute(codec);
7409         if ((res >> 26) == ALC880_FRONT_EVENT)
7410                 alc888_lenovo_ms7195_rca_automute(codec);
7411 }
7412
7413 static struct hda_verb alc883_medion_md2_verbs[] = {
7414         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7415         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7416
7417         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7418
7419         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7420         { } /* end */
7421 };
7422
7423 /* toggle speaker-output according to the hp-jack state */
7424 static void alc883_medion_md2_automute(struct hda_codec *codec)
7425 {
7426         unsigned int present;
7427  
7428         present = snd_hda_codec_read(codec, 0x14, 0,
7429                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7430         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7431                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7432 }
7433
7434 static void alc883_medion_md2_unsol_event(struct hda_codec *codec,
7435                                           unsigned int res)
7436 {
7437         if ((res >> 26) == ALC880_HP_EVENT)
7438                 alc883_medion_md2_automute(codec);
7439 }
7440
7441 /* toggle speaker-output according to the hp-jack state */
7442 static void alc883_tagra_automute(struct hda_codec *codec)
7443 {
7444         unsigned int present;
7445         unsigned char bits;
7446
7447         present = snd_hda_codec_read(codec, 0x14, 0,
7448                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7449         bits = present ? HDA_AMP_MUTE : 0;
7450         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
7451                                  HDA_AMP_MUTE, bits);
7452         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
7453                                   present ? 1 : 3);
7454 }
7455
7456 static void alc883_tagra_unsol_event(struct hda_codec *codec, unsigned int res)
7457 {
7458         if ((res >> 26) == ALC880_HP_EVENT)
7459                 alc883_tagra_automute(codec);
7460 }
7461
7462 /* toggle speaker-output according to the hp-jack state */
7463 static void alc883_clevo_m720r_automute(struct hda_codec *codec)
7464 {
7465         unsigned int present;
7466         unsigned char bits;
7467
7468         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
7469                 & AC_PINSENSE_PRESENCE;
7470         bits = present ? HDA_AMP_MUTE : 0;
7471         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7472                                  HDA_AMP_MUTE, bits);
7473 }
7474
7475 static void alc883_clevo_m720r_unsol_event(struct hda_codec *codec,
7476                                            unsigned int res)
7477 {
7478         if ((res >> 26) == ALC880_HP_EVENT)
7479                 alc883_clevo_m720r_automute(codec);
7480 }
7481
7482 /* toggle speaker-output according to the hp-jack state */
7483 static void alc883_2ch_fujitsu_pi2515_automute(struct hda_codec *codec)
7484 {
7485         unsigned int present;
7486         unsigned char bits;
7487
7488         present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
7489                 & AC_PINSENSE_PRESENCE;
7490         bits = present ? HDA_AMP_MUTE : 0;
7491         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7492                                  HDA_AMP_MUTE, bits);
7493 }
7494
7495 static void alc883_2ch_fujitsu_pi2515_unsol_event(struct hda_codec *codec,
7496                                                   unsigned int res)
7497 {
7498         if ((res >> 26) == ALC880_HP_EVENT)
7499                 alc883_2ch_fujitsu_pi2515_automute(codec);
7500 }
7501
7502 static void alc883_haier_w66_automute(struct hda_codec *codec)
7503 {
7504         unsigned int present;
7505         unsigned char bits;
7506
7507         present = snd_hda_codec_read(codec, 0x1b, 0,
7508                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7509         bits = present ? 0x80 : 0;
7510         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7511                                  0x80, bits);
7512 }
7513
7514 static void alc883_haier_w66_unsol_event(struct hda_codec *codec,
7515                                          unsigned int res)
7516 {
7517         if ((res >> 26) == ALC880_HP_EVENT)
7518                 alc883_haier_w66_automute(codec);
7519 }
7520
7521 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
7522 {
7523         unsigned int present;
7524         unsigned char bits;
7525
7526         present = snd_hda_codec_read(codec, 0x14, 0,
7527                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7528         bits = present ? HDA_AMP_MUTE : 0;
7529         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7530                                  HDA_AMP_MUTE, bits);
7531 }
7532
7533 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
7534 {
7535         unsigned int present;
7536         unsigned char bits;
7537
7538         present = snd_hda_codec_read(codec, 0x1b, 0,
7539                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7540         bits = present ? HDA_AMP_MUTE : 0;
7541         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7542                                  HDA_AMP_MUTE, bits);
7543         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7544                                  HDA_AMP_MUTE, bits);
7545 }
7546
7547 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
7548                                            unsigned int res)
7549 {
7550         if ((res >> 26) == ALC880_HP_EVENT)
7551                 alc883_lenovo_101e_all_automute(codec);
7552         if ((res >> 26) == ALC880_FRONT_EVENT)
7553                 alc883_lenovo_101e_ispeaker_automute(codec);
7554 }
7555
7556 /* toggle speaker-output according to the hp-jack state */
7557 static void alc883_acer_aspire_automute(struct hda_codec *codec)
7558 {
7559         unsigned int present;
7560  
7561         present = snd_hda_codec_read(codec, 0x14, 0,
7562                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7563         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7564                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7565         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
7566                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7567 }
7568
7569 static void alc883_acer_aspire_unsol_event(struct hda_codec *codec,
7570                                            unsigned int res)
7571 {
7572         if ((res >> 26) == ALC880_HP_EVENT)
7573                 alc883_acer_aspire_automute(codec);
7574 }
7575
7576 static struct hda_verb alc883_acer_eapd_verbs[] = {
7577         /* HP Pin: output 0 (0x0c) */
7578         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7579         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7580         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7581         /* Front Pin: output 0 (0x0c) */
7582         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7583         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7584         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7585         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
7586         /* eanable EAPD on medion laptop */
7587         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7588         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
7589         /* enable unsolicited event */
7590         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7591         { }
7592 };
7593
7594 static void alc888_6st_dell_front_automute(struct hda_codec *codec)
7595 {
7596         unsigned int present;
7597  
7598         present = snd_hda_codec_read(codec, 0x1b, 0,
7599                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7600         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7601                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7602         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7603                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7604         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
7605                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7606         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
7607                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7608 }
7609
7610 static void alc888_6st_dell_unsol_event(struct hda_codec *codec,
7611                                              unsigned int res)
7612 {
7613         switch (res >> 26) {
7614         case ALC880_HP_EVENT:
7615                 printk("hp_event\n");
7616                 alc888_6st_dell_front_automute(codec);
7617                 break;
7618         }
7619 }
7620
7621 /*
7622  * generic initialization of ADC, input mixers and output mixers
7623  */
7624 static struct hda_verb alc883_auto_init_verbs[] = {
7625         /*
7626          * Unmute ADC0-2 and set the default input to mic-in
7627          */
7628         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7629         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7630         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7631         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7632
7633         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
7634          * mixer widget
7635          * Note: PASD motherboards uses the Line In 2 as the input for
7636          * front panel mic (mic 2)
7637          */
7638         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
7639         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7640         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7641         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7642         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7643         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7644
7645         /*
7646          * Set up output mixers (0x0c - 0x0f)
7647          */
7648         /* set vol=0 to output mixers */
7649         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7650         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7651         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7652         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7653         /* set up input amps for analog loopback */
7654         /* Amp Indices: DAC = 0, mixer = 1 */
7655         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7656         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7657         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7658         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7659         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7660         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7661         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7662         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7663         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7664         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7665
7666         /* FIXME: use matrix-type input source selection */
7667         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7668         /* Input mixer1 */
7669         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7670         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7671         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7672         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
7673         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7674         /* Input mixer2 */
7675         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7676         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7677         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7678         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
7679         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7680
7681         { }
7682 };
7683
7684 /* capture mixer elements */
7685 static struct snd_kcontrol_new alc883_capture_mixer[] = {
7686         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7687         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7688         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7689         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7690         {
7691                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7692                 /* The multiple "Capture Source" controls confuse alsamixer
7693                  * So call somewhat different..
7694                  */
7695                 /* .name = "Capture Source", */
7696                 .name = "Input Source",
7697                 .count = 2,
7698                 .info = alc882_mux_enum_info,
7699                 .get = alc882_mux_enum_get,
7700                 .put = alc882_mux_enum_put,
7701         },
7702         { } /* end */
7703 };
7704
7705 #ifdef CONFIG_SND_HDA_POWER_SAVE
7706 #define alc883_loopbacks        alc880_loopbacks
7707 #endif
7708
7709 /* pcm configuration: identiacal with ALC880 */
7710 #define alc883_pcm_analog_playback      alc880_pcm_analog_playback
7711 #define alc883_pcm_analog_capture       alc880_pcm_analog_capture
7712 #define alc883_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
7713 #define alc883_pcm_digital_playback     alc880_pcm_digital_playback
7714 #define alc883_pcm_digital_capture      alc880_pcm_digital_capture
7715
7716 /*
7717  * configuration and preset
7718  */
7719 static const char *alc883_models[ALC883_MODEL_LAST] = {
7720         [ALC883_3ST_2ch_DIG]    = "3stack-dig",
7721         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
7722         [ALC883_3ST_6ch]        = "3stack-6ch",
7723         [ALC883_6ST_DIG]        = "6stack-dig",
7724         [ALC883_TARGA_DIG]      = "targa-dig",
7725         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
7726         [ALC883_ACER]           = "acer",
7727         [ALC883_ACER_ASPIRE]    = "acer-aspire",
7728         [ALC883_MEDION]         = "medion",
7729         [ALC883_MEDION_MD2]     = "medion-md2",
7730         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
7731         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
7732         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
7733         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
7734         [ALC883_HAIER_W66]      = "haier-w66",
7735         [ALC888_6ST_HP]         = "6stack-hp",
7736         [ALC888_3ST_HP]         = "3stack-hp",
7737         [ALC888_6ST_DELL]       = "6stack-dell",
7738         [ALC883_MITAC]          = "mitac",
7739         [ALC883_CLEVO_M720R]    = "clevo-m720r",
7740         [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
7741         [ALC883_AUTO]           = "auto",
7742 };
7743
7744 static struct snd_pci_quirk alc883_cfg_tbl[] = {
7745         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG),
7746         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
7747         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
7748         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
7749         SND_PCI_QUIRK(0x1025, 0, "Acer laptop", ALC883_ACER), /* default Acer */
7750         SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
7751         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
7752         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
7753         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
7754         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC888_6ST_HP),
7755         SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
7756         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
7757         SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
7758         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
7759         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
7760         SND_PCI_QUIRK(0x1458, 0xa002, "MSI", ALC883_6ST_DIG),
7761         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
7762         SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
7763         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
7764         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
7765         SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
7766         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
7767         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
7768         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
7769         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
7770         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
7771         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
7772         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
7773         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
7774         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
7775         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
7776         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
7777         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
7778         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
7779         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
7780         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
7781         SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
7782         SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720R),
7783         SND_PCI_QUIRK(0x1558, 0, "Clevo laptop", ALC883_LAPTOP_EAPD),
7784         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
7785         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
7786         SND_PCI_QUIRK(0x1734, 0x1108, "Fujitsu AMILO Pi2515", ALC883_FUJITSU_PI2515),
7787         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
7788         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
7789         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
7790         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
7791         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
7792         SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
7793         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
7794         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
7795         {}
7796 };
7797
7798 static struct alc_config_preset alc883_presets[] = {
7799         [ALC883_3ST_2ch_DIG] = {
7800                 .mixers = { alc883_3ST_2ch_mixer },
7801                 .init_verbs = { alc883_init_verbs },
7802                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7803                 .dac_nids = alc883_dac_nids,
7804                 .dig_out_nid = ALC883_DIGOUT_NID,
7805                 .dig_in_nid = ALC883_DIGIN_NID,
7806                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7807                 .channel_mode = alc883_3ST_2ch_modes,
7808                 .input_mux = &alc883_capture_source,
7809         },
7810         [ALC883_3ST_6ch_DIG] = {
7811                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
7812                 .init_verbs = { alc883_init_verbs },
7813                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7814                 .dac_nids = alc883_dac_nids,
7815                 .dig_out_nid = ALC883_DIGOUT_NID,
7816                 .dig_in_nid = ALC883_DIGIN_NID,
7817                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7818                 .channel_mode = alc883_3ST_6ch_modes,
7819                 .need_dac_fix = 1,
7820                 .input_mux = &alc883_capture_source,
7821         },
7822         [ALC883_3ST_6ch] = {
7823                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
7824                 .init_verbs = { alc883_init_verbs },
7825                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7826                 .dac_nids = alc883_dac_nids,
7827                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7828                 .channel_mode = alc883_3ST_6ch_modes,
7829                 .need_dac_fix = 1,
7830                 .input_mux = &alc883_capture_source,
7831         },
7832         [ALC883_6ST_DIG] = {
7833                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
7834                 .init_verbs = { alc883_init_verbs },
7835                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7836                 .dac_nids = alc883_dac_nids,
7837                 .dig_out_nid = ALC883_DIGOUT_NID,
7838                 .dig_in_nid = ALC883_DIGIN_NID,
7839                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7840                 .channel_mode = alc883_sixstack_modes,
7841                 .input_mux = &alc883_capture_source,
7842         },
7843         [ALC883_TARGA_DIG] = {
7844                 .mixers = { alc883_tagra_mixer, alc883_chmode_mixer },
7845                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
7846                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7847                 .dac_nids = alc883_dac_nids,
7848                 .dig_out_nid = ALC883_DIGOUT_NID,
7849                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7850                 .channel_mode = alc883_3ST_6ch_modes,
7851                 .need_dac_fix = 1,
7852                 .input_mux = &alc883_capture_source,
7853                 .unsol_event = alc883_tagra_unsol_event,
7854                 .init_hook = alc883_tagra_automute,
7855         },
7856         [ALC883_TARGA_2ch_DIG] = {
7857                 .mixers = { alc883_tagra_2ch_mixer},
7858                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
7859                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7860                 .dac_nids = alc883_dac_nids,
7861                 .dig_out_nid = ALC883_DIGOUT_NID,
7862                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7863                 .channel_mode = alc883_3ST_2ch_modes,
7864                 .input_mux = &alc883_capture_source,
7865                 .unsol_event = alc883_tagra_unsol_event,
7866                 .init_hook = alc883_tagra_automute,
7867         },
7868         [ALC883_ACER] = {
7869                 .mixers = { alc883_base_mixer },
7870                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
7871                  * and the headphone jack.  Turn this on and rely on the
7872                  * standard mute methods whenever the user wants to turn
7873                  * these outputs off.
7874                  */
7875                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
7876                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7877                 .dac_nids = alc883_dac_nids,
7878                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7879                 .channel_mode = alc883_3ST_2ch_modes,
7880                 .input_mux = &alc883_capture_source,
7881         },
7882         [ALC883_ACER_ASPIRE] = {
7883                 .mixers = { alc883_acer_aspire_mixer },
7884                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
7885                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7886                 .dac_nids = alc883_dac_nids,
7887                 .dig_out_nid = ALC883_DIGOUT_NID,
7888                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7889                 .channel_mode = alc883_3ST_2ch_modes,
7890                 .input_mux = &alc883_capture_source,
7891                 .unsol_event = alc883_acer_aspire_unsol_event,
7892                 .init_hook = alc883_acer_aspire_automute,
7893         },
7894         [ALC883_MEDION] = {
7895                 .mixers = { alc883_fivestack_mixer,
7896                             alc883_chmode_mixer },
7897                 .init_verbs = { alc883_init_verbs,
7898                                 alc883_medion_eapd_verbs },
7899                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7900                 .dac_nids = alc883_dac_nids,
7901                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7902                 .channel_mode = alc883_sixstack_modes,
7903                 .input_mux = &alc883_capture_source,
7904         },
7905         [ALC883_MEDION_MD2] = {
7906                 .mixers = { alc883_medion_md2_mixer},
7907                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
7908                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7909                 .dac_nids = alc883_dac_nids,
7910                 .dig_out_nid = ALC883_DIGOUT_NID,
7911                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7912                 .channel_mode = alc883_3ST_2ch_modes,
7913                 .input_mux = &alc883_capture_source,
7914                 .unsol_event = alc883_medion_md2_unsol_event,
7915                 .init_hook = alc883_medion_md2_automute,
7916         },      
7917         [ALC883_LAPTOP_EAPD] = {
7918                 .mixers = { alc883_base_mixer },
7919                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
7920                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7921                 .dac_nids = alc883_dac_nids,
7922                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7923                 .channel_mode = alc883_3ST_2ch_modes,
7924                 .input_mux = &alc883_capture_source,
7925         },
7926         [ALC883_CLEVO_M720R] = {
7927                 .mixers = { alc883_clevo_m720r_mixer },
7928                 .init_verbs = { alc883_init_verbs, alc883_clevo_m720r_verbs },
7929                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7930                 .dac_nids = alc883_dac_nids,
7931                 .dig_out_nid = ALC883_DIGOUT_NID,
7932                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7933                 .channel_mode = alc883_3ST_2ch_modes,
7934                 .input_mux = &alc883_capture_source,
7935                 .unsol_event = alc883_clevo_m720r_unsol_event,
7936                 .init_hook = alc883_clevo_m720r_automute,
7937         },
7938         [ALC883_LENOVO_101E_2ch] = {
7939                 .mixers = { alc883_lenovo_101e_2ch_mixer},
7940                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
7941                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7942                 .dac_nids = alc883_dac_nids,
7943                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7944                 .channel_mode = alc883_3ST_2ch_modes,
7945                 .input_mux = &alc883_lenovo_101e_capture_source,
7946                 .unsol_event = alc883_lenovo_101e_unsol_event,
7947                 .init_hook = alc883_lenovo_101e_all_automute,
7948         },
7949         [ALC883_LENOVO_NB0763] = {
7950                 .mixers = { alc883_lenovo_nb0763_mixer },
7951                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
7952                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7953                 .dac_nids = alc883_dac_nids,
7954                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7955                 .channel_mode = alc883_3ST_2ch_modes,
7956                 .need_dac_fix = 1,
7957                 .input_mux = &alc883_lenovo_nb0763_capture_source,
7958                 .unsol_event = alc883_medion_md2_unsol_event,
7959                 .init_hook = alc883_medion_md2_automute,
7960         },
7961         [ALC888_LENOVO_MS7195_DIG] = {
7962                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
7963                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
7964                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7965                 .dac_nids = alc883_dac_nids,
7966                 .dig_out_nid = ALC883_DIGOUT_NID,
7967                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7968                 .channel_mode = alc883_3ST_6ch_modes,
7969                 .need_dac_fix = 1,
7970                 .input_mux = &alc883_capture_source,
7971                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
7972                 .init_hook = alc888_lenovo_ms7195_front_automute,
7973         },
7974         [ALC883_HAIER_W66] = {
7975                 .mixers = { alc883_tagra_2ch_mixer},
7976                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
7977                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7978                 .dac_nids = alc883_dac_nids,
7979                 .dig_out_nid = ALC883_DIGOUT_NID,
7980                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7981                 .channel_mode = alc883_3ST_2ch_modes,
7982                 .input_mux = &alc883_capture_source,
7983                 .unsol_event = alc883_haier_w66_unsol_event,
7984                 .init_hook = alc883_haier_w66_automute,
7985         },      
7986         [ALC888_6ST_HP] = {
7987                 .mixers = { alc888_6st_hp_mixer, alc883_chmode_mixer },
7988                 .init_verbs = { alc883_init_verbs, alc888_6st_hp_verbs },
7989                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7990                 .dac_nids = alc883_dac_nids,
7991                 .dig_out_nid = ALC883_DIGOUT_NID,
7992                 .dig_in_nid = ALC883_DIGIN_NID,
7993                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7994                 .channel_mode = alc883_sixstack_modes,
7995                 .input_mux = &alc883_capture_source,
7996         },
7997         [ALC888_3ST_HP] = {
7998                 .mixers = { alc888_3st_hp_mixer, alc883_chmode_mixer },
7999                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
8000                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8001                 .dac_nids = alc883_dac_nids,
8002                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
8003                 .channel_mode = alc888_3st_hp_modes,
8004                 .need_dac_fix = 1,
8005                 .input_mux = &alc883_capture_source,
8006         },
8007         [ALC888_6ST_DELL] = {
8008                 .mixers = { alc888_6st_dell_mixer, alc883_chmode_mixer },
8009                 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
8010                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8011                 .dac_nids = alc883_dac_nids,
8012                 .dig_out_nid = ALC883_DIGOUT_NID,
8013                 .dig_in_nid = ALC883_DIGIN_NID,
8014                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8015                 .channel_mode = alc883_sixstack_modes,
8016                 .input_mux = &alc883_capture_source,
8017                 .unsol_event = alc888_6st_dell_unsol_event,
8018                 .init_hook = alc888_6st_dell_front_automute,
8019         },
8020         [ALC883_MITAC] = {
8021                 .mixers = { alc883_mitac_mixer },
8022                 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
8023                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8024                 .dac_nids = alc883_dac_nids,
8025                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8026                 .channel_mode = alc883_3ST_2ch_modes,
8027                 .input_mux = &alc883_capture_source,
8028                 .unsol_event = alc883_mitac_unsol_event,
8029                 .init_hook = alc883_mitac_automute,
8030         },
8031         [ALC883_FUJITSU_PI2515] = {
8032                 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
8033                 .init_verbs = { alc883_init_verbs,
8034                                 alc883_2ch_fujitsu_pi2515_verbs},
8035                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8036                 .dac_nids = alc883_dac_nids,
8037                 .dig_out_nid = ALC883_DIGOUT_NID,
8038                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8039                 .channel_mode = alc883_3ST_2ch_modes,
8040                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
8041                 .unsol_event = alc883_2ch_fujitsu_pi2515_unsol_event,
8042                 .init_hook = alc883_2ch_fujitsu_pi2515_automute,
8043         },
8044 };
8045
8046
8047 /*
8048  * BIOS auto configuration
8049  */
8050 static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
8051                                               hda_nid_t nid, int pin_type,
8052                                               int dac_idx)
8053 {
8054         /* set as output */
8055         struct alc_spec *spec = codec->spec;
8056         int idx;
8057
8058         alc_set_pin_output(codec, nid, pin_type);
8059         if (spec->multiout.dac_nids[dac_idx] == 0x25)
8060                 idx = 4;
8061         else
8062                 idx = spec->multiout.dac_nids[dac_idx] - 2;
8063         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
8064
8065 }
8066
8067 static void alc883_auto_init_multi_out(struct hda_codec *codec)
8068 {
8069         struct alc_spec *spec = codec->spec;
8070         int i;
8071
8072         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
8073         for (i = 0; i <= HDA_SIDE; i++) {
8074                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
8075                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
8076                 if (nid)
8077                         alc883_auto_set_output_and_unmute(codec, nid, pin_type,
8078                                                           i);
8079         }
8080 }
8081
8082 static void alc883_auto_init_hp_out(struct hda_codec *codec)
8083 {
8084         struct alc_spec *spec = codec->spec;
8085         hda_nid_t pin;
8086
8087         pin = spec->autocfg.hp_pins[0];
8088         if (pin) /* connect to front */
8089                 /* use dac 0 */
8090                 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
8091         pin = spec->autocfg.speaker_pins[0];
8092         if (pin)
8093                 alc883_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
8094 }
8095
8096 #define alc883_is_input_pin(nid)        alc880_is_input_pin(nid)
8097 #define ALC883_PIN_CD_NID               ALC880_PIN_CD_NID
8098
8099 static void alc883_auto_init_analog_input(struct hda_codec *codec)
8100 {
8101         struct alc_spec *spec = codec->spec;
8102         int i;
8103
8104         for (i = 0; i < AUTO_PIN_LAST; i++) {
8105                 hda_nid_t nid = spec->autocfg.input_pins[i];
8106                 if (alc883_is_input_pin(nid)) {
8107                         snd_hda_codec_write(codec, nid, 0,
8108                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
8109                                             (i <= AUTO_PIN_FRONT_MIC ?
8110                                              PIN_VREF80 : PIN_IN));
8111                         if (nid != ALC883_PIN_CD_NID)
8112                                 snd_hda_codec_write(codec, nid, 0,
8113                                                     AC_VERB_SET_AMP_GAIN_MUTE,
8114                                                     AMP_OUT_MUTE);
8115                 }
8116         }
8117 }
8118
8119 /* almost identical with ALC880 parser... */
8120 static int alc883_parse_auto_config(struct hda_codec *codec)
8121 {
8122         struct alc_spec *spec = codec->spec;
8123         int err = alc880_parse_auto_config(codec);
8124
8125         if (err < 0)
8126                 return err;
8127         else if (!err)
8128                 return 0; /* no config found */
8129
8130         err = alc_auto_add_mic_boost(codec);
8131         if (err < 0)
8132                 return err;
8133
8134         /* hack - override the init verbs */
8135         spec->init_verbs[0] = alc883_auto_init_verbs;
8136         spec->mixers[spec->num_mixers] = alc883_capture_mixer;
8137         spec->num_mixers++;
8138
8139         return 1; /* config found */
8140 }
8141
8142 /* additional initialization for auto-configuration model */
8143 static void alc883_auto_init(struct hda_codec *codec)
8144 {
8145         struct alc_spec *spec = codec->spec;
8146         alc883_auto_init_multi_out(codec);
8147         alc883_auto_init_hp_out(codec);
8148         alc883_auto_init_analog_input(codec);
8149         if (spec->unsol_event)
8150                 alc_sku_automute(codec);
8151 }
8152
8153 static int patch_alc883(struct hda_codec *codec)
8154 {
8155         struct alc_spec *spec;
8156         int err, board_config;
8157
8158         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
8159         if (spec == NULL)
8160                 return -ENOMEM;
8161
8162         codec->spec = spec;
8163
8164         board_config = snd_hda_check_board_config(codec, ALC883_MODEL_LAST,
8165                                                   alc883_models,
8166                                                   alc883_cfg_tbl);
8167         if (board_config < 0) {
8168                 printk(KERN_INFO "hda_codec: Unknown model for ALC883, "
8169                        "trying auto-probe from BIOS...\n");
8170                 board_config = ALC883_AUTO;
8171         }
8172
8173         if (board_config == ALC883_AUTO) {
8174                 /* automatic parse from the BIOS config */
8175                 err = alc883_parse_auto_config(codec);
8176                 if (err < 0) {
8177                         alc_free(codec);
8178                         return err;
8179                 } else if (!err) {
8180                         printk(KERN_INFO
8181                                "hda_codec: Cannot set up configuration "
8182                                "from BIOS.  Using base mode...\n");
8183                         board_config = ALC883_3ST_2ch_DIG;
8184                 }
8185         }
8186
8187         if (board_config != ALC883_AUTO)
8188                 setup_preset(spec, &alc883_presets[board_config]);
8189
8190         spec->stream_name_analog = "ALC883 Analog";
8191         spec->stream_analog_playback = &alc883_pcm_analog_playback;
8192         spec->stream_analog_capture = &alc883_pcm_analog_capture;
8193         spec->stream_analog_alt_capture = &alc883_pcm_analog_alt_capture;
8194
8195         spec->stream_name_digital = "ALC883 Digital";
8196         spec->stream_digital_playback = &alc883_pcm_digital_playback;
8197         spec->stream_digital_capture = &alc883_pcm_digital_capture;
8198
8199         spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
8200         spec->adc_nids = alc883_adc_nids;
8201         spec->capsrc_nids = alc883_capsrc_nids;
8202
8203         spec->vmaster_nid = 0x0c;
8204
8205         codec->patch_ops = alc_patch_ops;
8206         if (board_config == ALC883_AUTO)
8207                 spec->init_hook = alc883_auto_init;
8208 #ifdef CONFIG_SND_HDA_POWER_SAVE
8209         if (!spec->loopback.amplist)
8210                 spec->loopback.amplist = alc883_loopbacks;
8211 #endif
8212
8213         return 0;
8214 }
8215
8216 /*
8217  * ALC262 support
8218  */
8219
8220 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
8221 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
8222
8223 #define alc262_dac_nids         alc260_dac_nids
8224 #define alc262_adc_nids         alc882_adc_nids
8225 #define alc262_adc_nids_alt     alc882_adc_nids_alt
8226 #define alc262_capsrc_nids      alc882_capsrc_nids
8227 #define alc262_capsrc_nids_alt  alc882_capsrc_nids_alt
8228
8229 #define alc262_modes            alc260_modes
8230 #define alc262_capture_source   alc882_capture_source
8231
8232 static struct snd_kcontrol_new alc262_base_mixer[] = {
8233         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8234         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8235         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8236         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8237         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8238         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8239         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8240         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8241         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8242         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8243         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8244         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8245         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8246            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
8247         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
8248         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8249         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
8250         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
8251         { } /* end */
8252 };
8253
8254 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
8255         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8256         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8257         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8258         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8259         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8260         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8261         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8262         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8263         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8264         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8265         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8266         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8267         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8268            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
8269         /*HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),*/
8270         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8271         { } /* end */
8272 };
8273
8274 /* update HP, line and mono-out pins according to the master switch */
8275 static void alc262_hp_master_update(struct hda_codec *codec)
8276 {
8277         struct alc_spec *spec = codec->spec;
8278         int val = spec->master_sw;
8279
8280         /* HP & line-out */
8281         snd_hda_codec_write_cache(codec, 0x1b, 0,
8282                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
8283                                   val ? PIN_HP : 0);
8284         snd_hda_codec_write_cache(codec, 0x15, 0,
8285                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
8286                                   val ? PIN_HP : 0);
8287         /* mono (speaker) depending on the HP jack sense */
8288         val = val && !spec->jack_present;
8289         snd_hda_codec_write_cache(codec, 0x16, 0,
8290                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
8291                                   val ? PIN_OUT : 0);
8292 }
8293
8294 static void alc262_hp_bpc_automute(struct hda_codec *codec)
8295 {
8296         struct alc_spec *spec = codec->spec;
8297         unsigned int presence;
8298         presence = snd_hda_codec_read(codec, 0x1b, 0,
8299                                       AC_VERB_GET_PIN_SENSE, 0);
8300         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
8301         alc262_hp_master_update(codec);
8302 }
8303
8304 static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res)
8305 {
8306         if ((res >> 26) != ALC880_HP_EVENT)
8307                 return;
8308         alc262_hp_bpc_automute(codec);
8309 }
8310
8311 static void alc262_hp_wildwest_automute(struct hda_codec *codec)
8312 {
8313         struct alc_spec *spec = codec->spec;
8314         unsigned int presence;
8315         presence = snd_hda_codec_read(codec, 0x15, 0,
8316                                       AC_VERB_GET_PIN_SENSE, 0);
8317         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
8318         alc262_hp_master_update(codec);
8319 }
8320
8321 static void alc262_hp_wildwest_unsol_event(struct hda_codec *codec,
8322                                            unsigned int res)
8323 {
8324         if ((res >> 26) != ALC880_HP_EVENT)
8325                 return;
8326         alc262_hp_wildwest_automute(codec);
8327 }
8328
8329 static int alc262_hp_master_sw_get(struct snd_kcontrol *kcontrol,
8330                                    struct snd_ctl_elem_value *ucontrol)
8331 {
8332         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8333         struct alc_spec *spec = codec->spec;
8334         *ucontrol->value.integer.value = spec->master_sw;
8335         return 0;
8336 }
8337
8338 static int alc262_hp_master_sw_put(struct snd_kcontrol *kcontrol,
8339                                    struct snd_ctl_elem_value *ucontrol)
8340 {
8341         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8342         struct alc_spec *spec = codec->spec;
8343         int val = !!*ucontrol->value.integer.value;
8344
8345         if (val == spec->master_sw)
8346                 return 0;
8347         spec->master_sw = val;
8348         alc262_hp_master_update(codec);
8349         return 1;
8350 }
8351
8352 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
8353         {
8354                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8355                 .name = "Master Playback Switch",
8356                 .info = snd_ctl_boolean_mono_info,
8357                 .get = alc262_hp_master_sw_get,
8358                 .put = alc262_hp_master_sw_put,
8359         },
8360         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8361         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8362         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8363         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
8364                               HDA_OUTPUT),
8365         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
8366                             HDA_OUTPUT),
8367         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8368         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8369         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8370         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8371         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8372         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8373         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8374         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8375         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8376         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8377         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8378         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
8379         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
8380         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
8381         { } /* end */
8382 };
8383
8384 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
8385         {
8386                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8387                 .name = "Master Playback Switch",
8388                 .info = snd_ctl_boolean_mono_info,
8389                 .get = alc262_hp_master_sw_get,
8390                 .put = alc262_hp_master_sw_put,
8391         },
8392         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8393         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8394         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8395         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8396         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
8397                               HDA_OUTPUT),
8398         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
8399                             HDA_OUTPUT),
8400         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
8401         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
8402         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
8403         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
8404         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
8405         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8406         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8407         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8408         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
8409         { } /* end */
8410 };
8411
8412 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
8413         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8414         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8415         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
8416         { } /* end */
8417 };
8418
8419 /* mute/unmute internal speaker according to the hp jack and mute state */
8420 static void alc262_hp_t5735_automute(struct hda_codec *codec, int force)
8421 {
8422         struct alc_spec *spec = codec->spec;
8423
8424         if (force || !spec->sense_updated) {
8425                 unsigned int present;
8426                 present = snd_hda_codec_read(codec, 0x15, 0,
8427                                              AC_VERB_GET_PIN_SENSE, 0);
8428                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
8429                 spec->sense_updated = 1;
8430         }
8431         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0, HDA_AMP_MUTE,
8432                                  spec->jack_present ? HDA_AMP_MUTE : 0);
8433 }
8434
8435 static void alc262_hp_t5735_unsol_event(struct hda_codec *codec,
8436                                         unsigned int res)
8437 {
8438         if ((res >> 26) != ALC880_HP_EVENT)
8439                 return;
8440         alc262_hp_t5735_automute(codec, 1);
8441 }
8442
8443 static void alc262_hp_t5735_init_hook(struct hda_codec *codec)
8444 {
8445         alc262_hp_t5735_automute(codec, 1);
8446 }
8447
8448 static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
8449         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8450         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8451         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8452         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8453         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8454         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8455         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8456         { } /* end */
8457 };
8458
8459 static struct hda_verb alc262_hp_t5735_verbs[] = {
8460         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8461         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8462
8463         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8464         { }
8465 };
8466
8467 static struct snd_kcontrol_new alc262_hp_rp5700_mixer[] = {
8468         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8469         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8470         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
8471         HDA_CODEC_MUTE("Speaker Playback Switch", 0x16, 0x0, HDA_OUTPUT),
8472         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
8473         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
8474         { } /* end */
8475 };
8476
8477 static struct hda_verb alc262_hp_rp5700_verbs[] = {
8478         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8479         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8480         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8481         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8482         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8483         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8484         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8485         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8486         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
8487         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
8488         {}
8489 };
8490
8491 static struct hda_input_mux alc262_hp_rp5700_capture_source = {
8492         .num_items = 1,
8493         .items = {
8494                 { "Line", 0x1 },
8495         },
8496 };
8497
8498 /* bind hp and internal speaker mute (with plug check) */
8499 static int alc262_sony_master_sw_put(struct snd_kcontrol *kcontrol,
8500                                      struct snd_ctl_elem_value *ucontrol)
8501 {
8502         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8503         long *valp = ucontrol->value.integer.value;
8504         int change;
8505
8506         /* change hp mute */
8507         change = snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
8508                                           HDA_AMP_MUTE,
8509                                           valp[0] ? 0 : HDA_AMP_MUTE);
8510         change |= snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
8511                                            HDA_AMP_MUTE,
8512                                            valp[1] ? 0 : HDA_AMP_MUTE);
8513         if (change) {
8514                 /* change speaker according to HP jack state */
8515                 struct alc_spec *spec = codec->spec;
8516                 unsigned int mute;
8517                 if (spec->jack_present)
8518                         mute = HDA_AMP_MUTE;
8519                 else
8520                         mute = snd_hda_codec_amp_read(codec, 0x15, 0,
8521                                                       HDA_OUTPUT, 0);
8522                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8523                                          HDA_AMP_MUTE, mute);
8524         }
8525         return change;
8526 }
8527
8528 static struct snd_kcontrol_new alc262_sony_mixer[] = {
8529         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8530         {
8531                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8532                 .name = "Master Playback Switch",
8533                 .info = snd_hda_mixer_amp_switch_info,
8534                 .get = snd_hda_mixer_amp_switch_get,
8535                 .put = alc262_sony_master_sw_put,
8536                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
8537         },
8538         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8539         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8540         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8541         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8542         { } /* end */
8543 };
8544
8545 static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
8546         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8547         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8548         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8549         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8550         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8551         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8552         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8553         { } /* end */
8554 };
8555
8556 #define alc262_capture_mixer            alc882_capture_mixer
8557 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
8558
8559 /*
8560  * generic initialization of ADC, input mixers and output mixers
8561  */
8562 static struct hda_verb alc262_init_verbs[] = {
8563         /*
8564          * Unmute ADC0-2 and set the default input to mic-in
8565          */
8566         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
8567         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8568         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8569         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8570         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8571         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8572
8573         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8574          * mixer widget
8575          * Note: PASD motherboards uses the Line In 2 as the input for
8576          * front panel mic (mic 2)
8577          */
8578         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8579         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8580         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8581         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8582         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8583         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8584
8585         /*
8586          * Set up output mixers (0x0c - 0x0e)
8587          */
8588         /* set vol=0 to output mixers */
8589         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8590         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8591         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8592         /* set up input amps for analog loopback */
8593         /* Amp Indices: DAC = 0, mixer = 1 */
8594         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8595         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8596         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8597         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8598         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8599         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8600
8601         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
8602         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8603         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
8604         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8605         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8606         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8607
8608         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8609         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8610         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8611         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8612         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8613         
8614         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8615         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
8616         
8617         /* FIXME: use matrix-type input source selection */
8618         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8619         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
8620         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8621         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8622         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8623         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8624         /* Input mixer2 */
8625         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8626         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8627         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8628         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8629         /* Input mixer3 */
8630         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8631         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8632         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8633         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8634
8635         { }
8636 };
8637
8638 static struct hda_verb alc262_hippo_unsol_verbs[] = {
8639         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8640         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8641         {}
8642 };
8643
8644 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
8645         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8646         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8647         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8648
8649         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8650         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8651         {}
8652 };
8653
8654 static struct hda_verb alc262_sony_unsol_verbs[] = {
8655         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8656         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8657         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
8658
8659         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8660         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8661 };
8662
8663 /* mute/unmute internal speaker according to the hp jack and mute state */
8664 static void alc262_hippo_automute(struct hda_codec *codec)
8665 {
8666         struct alc_spec *spec = codec->spec;
8667         unsigned int mute;
8668         unsigned int present;
8669
8670         /* need to execute and sync at first */
8671         snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
8672         present = snd_hda_codec_read(codec, 0x15, 0,
8673                                      AC_VERB_GET_PIN_SENSE, 0);
8674         spec->jack_present = (present & 0x80000000) != 0;
8675         if (spec->jack_present) {
8676                 /* mute internal speaker */
8677                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8678                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8679         } else {
8680                 /* unmute internal speaker if necessary */
8681                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
8682                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8683                                          HDA_AMP_MUTE, mute);
8684         }
8685 }
8686
8687 /* unsolicited event for HP jack sensing */
8688 static void alc262_hippo_unsol_event(struct hda_codec *codec,
8689                                        unsigned int res)
8690 {
8691         if ((res >> 26) != ALC880_HP_EVENT)
8692                 return;
8693         alc262_hippo_automute(codec);
8694 }
8695
8696 static void alc262_hippo1_automute(struct hda_codec *codec)
8697 {
8698         unsigned int mute;
8699         unsigned int present;
8700
8701         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
8702         present = snd_hda_codec_read(codec, 0x1b, 0,
8703                                      AC_VERB_GET_PIN_SENSE, 0);
8704         present = (present & 0x80000000) != 0;
8705         if (present) {
8706                 /* mute internal speaker */
8707                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8708                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8709         } else {
8710                 /* unmute internal speaker if necessary */
8711                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
8712                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8713                                          HDA_AMP_MUTE, mute);
8714         }
8715 }
8716
8717 /* unsolicited event for HP jack sensing */
8718 static void alc262_hippo1_unsol_event(struct hda_codec *codec,
8719                                        unsigned int res)
8720 {
8721         if ((res >> 26) != ALC880_HP_EVENT)
8722                 return;
8723         alc262_hippo1_automute(codec);
8724 }
8725
8726 /*
8727  * fujitsu model
8728  *  0x14 = headphone/spdif-out, 0x15 = internal speaker
8729  */
8730
8731 #define ALC_HP_EVENT    0x37
8732
8733 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
8734         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
8735         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8736         {}
8737 };
8738
8739 static struct hda_input_mux alc262_fujitsu_capture_source = {
8740         .num_items = 3,
8741         .items = {
8742                 { "Mic", 0x0 },
8743                 { "Int Mic", 0x1 },
8744                 { "CD", 0x4 },
8745         },
8746 };
8747
8748 static struct hda_input_mux alc262_HP_capture_source = {
8749         .num_items = 5,
8750         .items = {
8751                 { "Mic", 0x0 },
8752                 { "Front Mic", 0x1 },
8753                 { "Line", 0x2 },
8754                 { "CD", 0x4 },
8755                 { "AUX IN", 0x6 },
8756         },
8757 };
8758
8759 static struct hda_input_mux alc262_HP_D7000_capture_source = {
8760         .num_items = 4,
8761         .items = {
8762                 { "Mic", 0x0 },
8763                 { "Front Mic", 0x2 },
8764                 { "Line", 0x1 },
8765                 { "CD", 0x4 },
8766         },
8767 };
8768
8769 /* mute/unmute internal speaker according to the hp jack and mute state */
8770 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
8771 {
8772         struct alc_spec *spec = codec->spec;
8773         unsigned int mute;
8774
8775         if (force || !spec->sense_updated) {
8776                 unsigned int present;
8777                 /* need to execute and sync at first */
8778                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
8779                 present = snd_hda_codec_read(codec, 0x14, 0,
8780                                          AC_VERB_GET_PIN_SENSE, 0);
8781                 spec->jack_present = (present & 0x80000000) != 0;
8782                 spec->sense_updated = 1;
8783         }
8784         if (spec->jack_present) {
8785                 /* mute internal speaker */
8786                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8787                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8788         } else {
8789                 /* unmute internal speaker if necessary */
8790                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
8791                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8792                                          HDA_AMP_MUTE, mute);
8793         }
8794 }
8795
8796 /* unsolicited event for HP jack sensing */
8797 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
8798                                        unsigned int res)
8799 {
8800         if ((res >> 26) != ALC_HP_EVENT)
8801                 return;
8802         alc262_fujitsu_automute(codec, 1);
8803 }
8804
8805 /* bind volumes of both NID 0x0c and 0x0d */
8806 static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
8807         .ops = &snd_hda_bind_vol,
8808         .values = {
8809                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
8810                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
8811                 0
8812         },
8813 };
8814
8815 /* bind hp and internal speaker mute (with plug check) */
8816 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
8817                                          struct snd_ctl_elem_value *ucontrol)
8818 {
8819         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8820         long *valp = ucontrol->value.integer.value;
8821         int change;
8822
8823         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
8824                                           HDA_AMP_MUTE,
8825                                           valp[0] ? 0 : HDA_AMP_MUTE);
8826         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
8827                                            HDA_AMP_MUTE,
8828                                            valp[1] ? 0 : HDA_AMP_MUTE);
8829         if (change)
8830                 alc262_fujitsu_automute(codec, 0);
8831         return change;
8832 }
8833
8834 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
8835         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
8836         {
8837                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8838                 .name = "Master Playback Switch",
8839                 .info = snd_hda_mixer_amp_switch_info,
8840                 .get = snd_hda_mixer_amp_switch_get,
8841                 .put = alc262_fujitsu_master_sw_put,
8842                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
8843         },
8844         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8845         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8846         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8847         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8848         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8849         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
8850         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8851         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8852         { } /* end */
8853 };
8854
8855 /* additional init verbs for Benq laptops */
8856 static struct hda_verb alc262_EAPD_verbs[] = {
8857         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
8858         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
8859         {}
8860 };
8861
8862 static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
8863         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8864         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8865
8866         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
8867         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
8868         {}
8869 };
8870
8871 /* Samsung Q1 Ultra Vista model setup */
8872 static struct snd_kcontrol_new alc262_ultra_mixer[] = {
8873         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8874         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
8875         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8876         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8877         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
8878         HDA_CODEC_VOLUME("Headphone Mic Boost", 0x15, 0, HDA_INPUT),
8879         { } /* end */
8880 };
8881
8882 static struct hda_verb alc262_ultra_verbs[] = {
8883         /* output mixer */
8884         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8885         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8886         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8887         /* speaker */
8888         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8889         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8890         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8891         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8892         /* HP */
8893         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8894         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8895         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8896         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8897         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8898         /* internal mic */
8899         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8900         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8901         /* ADC, choose mic */
8902         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8903         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8904         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8905         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8906         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8907         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8908         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
8909         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
8910         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
8911         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(8)},
8912         {}
8913 };
8914
8915 /* mute/unmute internal speaker according to the hp jack and mute state */
8916 static void alc262_ultra_automute(struct hda_codec *codec)
8917 {
8918         struct alc_spec *spec = codec->spec;
8919         unsigned int mute;
8920
8921         mute = 0;
8922         /* auto-mute only when HP is used as HP */
8923         if (!spec->cur_mux[0]) {
8924                 unsigned int present;
8925                 /* need to execute and sync at first */
8926                 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
8927                 present = snd_hda_codec_read(codec, 0x15, 0,
8928                                              AC_VERB_GET_PIN_SENSE, 0);
8929                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
8930                 if (spec->jack_present)
8931                         mute = HDA_AMP_MUTE;
8932         }
8933         /* mute/unmute internal speaker */
8934         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8935                                  HDA_AMP_MUTE, mute);
8936         /* mute/unmute HP */
8937         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8938                                  HDA_AMP_MUTE, mute ? 0 : HDA_AMP_MUTE);
8939 }
8940
8941 /* unsolicited event for HP jack sensing */
8942 static void alc262_ultra_unsol_event(struct hda_codec *codec,
8943                                        unsigned int res)
8944 {
8945         if ((res >> 26) != ALC880_HP_EVENT)
8946                 return;
8947         alc262_ultra_automute(codec);
8948 }
8949
8950 static struct hda_input_mux alc262_ultra_capture_source = {
8951         .num_items = 2,
8952         .items = {
8953                 { "Mic", 0x1 },
8954                 { "Headphone", 0x7 },
8955         },
8956 };
8957
8958 static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
8959                                      struct snd_ctl_elem_value *ucontrol)
8960 {
8961         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8962         struct alc_spec *spec = codec->spec;
8963         int ret;
8964
8965         ret = alc882_mux_enum_put(kcontrol, ucontrol);
8966         if (!ret)
8967                 return 0;
8968         /* reprogram the HP pin as mic or HP according to the input source */
8969         snd_hda_codec_write_cache(codec, 0x15, 0,
8970                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
8971                                   spec->cur_mux[0] ? PIN_VREF80 : PIN_HP);
8972         alc262_ultra_automute(codec); /* mute/unmute HP */
8973         return ret;
8974 }
8975
8976 static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
8977         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
8978         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
8979         {
8980                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8981                 .name = "Capture Source",
8982                 .info = alc882_mux_enum_info,
8983                 .get = alc882_mux_enum_get,
8984                 .put = alc262_ultra_mux_enum_put,
8985         },
8986         { } /* end */
8987 };
8988
8989 /* add playback controls from the parsed DAC table */
8990 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
8991                                              const struct auto_pin_cfg *cfg)
8992 {
8993         hda_nid_t nid;
8994         int err;
8995
8996         spec->multiout.num_dacs = 1;    /* only use one dac */
8997         spec->multiout.dac_nids = spec->private_dac_nids;
8998         spec->multiout.dac_nids[0] = 2;
8999
9000         nid = cfg->line_out_pins[0];
9001         if (nid) {
9002                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
9003                                   "Front Playback Volume",
9004                                   HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT));
9005                 if (err < 0)
9006                         return err;
9007                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9008                                   "Front Playback Switch",
9009                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
9010                 if (err < 0)
9011                         return err;
9012         }
9013
9014         nid = cfg->speaker_pins[0];
9015         if (nid) {
9016                 if (nid == 0x16) {
9017                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
9018                                           "Speaker Playback Volume",
9019                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
9020                                                               HDA_OUTPUT));
9021                         if (err < 0)
9022                                 return err;
9023                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9024                                           "Speaker Playback Switch",
9025                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
9026                                                               HDA_OUTPUT));
9027                         if (err < 0)
9028                                 return err;
9029                 } else {
9030                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9031                                           "Speaker Playback Switch",
9032                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
9033                                                               HDA_OUTPUT));
9034                         if (err < 0)
9035                                 return err;
9036                 }
9037         }
9038         nid = cfg->hp_pins[0];
9039         if (nid) {
9040                 /* spec->multiout.hp_nid = 2; */
9041                 if (nid == 0x16) {
9042                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
9043                                           "Headphone Playback Volume",
9044                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
9045                                                               HDA_OUTPUT));
9046                         if (err < 0)
9047                                 return err;
9048                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9049                                           "Headphone Playback Switch",
9050                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
9051                                                               HDA_OUTPUT));
9052                         if (err < 0)
9053                                 return err;
9054                 } else {
9055                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9056                                           "Headphone Playback Switch",
9057                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
9058                                                               HDA_OUTPUT));
9059                         if (err < 0)
9060                                 return err;
9061                 }
9062         }
9063         return 0;
9064 }
9065
9066 /* identical with ALC880 */
9067 #define alc262_auto_create_analog_input_ctls \
9068         alc880_auto_create_analog_input_ctls
9069
9070 /*
9071  * generic initialization of ADC, input mixers and output mixers
9072  */
9073 static struct hda_verb alc262_volume_init_verbs[] = {
9074         /*
9075          * Unmute ADC0-2 and set the default input to mic-in
9076          */
9077         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9078         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9079         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9080         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9081         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9082         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9083
9084         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9085          * mixer widget
9086          * Note: PASD motherboards uses the Line In 2 as the input for
9087          * front panel mic (mic 2)
9088          */
9089         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9090         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9091         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9092         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9093         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9094         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9095
9096         /*
9097          * Set up output mixers (0x0c - 0x0f)
9098          */
9099         /* set vol=0 to output mixers */
9100         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9101         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9102         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9103         
9104         /* set up input amps for analog loopback */
9105         /* Amp Indices: DAC = 0, mixer = 1 */
9106         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9107         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9108         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9109         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9110         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9111         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9112
9113         /* FIXME: use matrix-type input source selection */
9114         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9115         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9116         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9117         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9118         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9119         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9120         /* Input mixer2 */
9121         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9122         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9123         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9124         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9125         /* Input mixer3 */
9126         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9127         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9128         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9129         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9130
9131         { }
9132 };
9133
9134 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
9135         /*
9136          * Unmute ADC0-2 and set the default input to mic-in
9137          */
9138         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9139         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9140         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9141         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9142         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9143         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9144
9145         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9146          * mixer widget
9147          * Note: PASD motherboards uses the Line In 2 as the input for
9148          * front panel mic (mic 2)
9149          */
9150         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9151         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9152         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9153         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9154         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9155         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9156         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
9157         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
9158         
9159         /*
9160          * Set up output mixers (0x0c - 0x0e)
9161          */
9162         /* set vol=0 to output mixers */
9163         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9164         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9165         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9166
9167         /* set up input amps for analog loopback */
9168         /* Amp Indices: DAC = 0, mixer = 1 */
9169         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9170         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9171         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9172         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9173         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9174         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9175
9176         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9177         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9178         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9179
9180         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9181         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9182
9183         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9184         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9185
9186         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9187         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9188         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9189         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9190         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9191
9192         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
9193         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9194         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9195         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
9196         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9197         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9198
9199
9200         /* FIXME: use matrix-type input source selection */
9201         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9202         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9203         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9204         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9205         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9206         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9207         /* Input mixer2 */
9208         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9209         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9210         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9211         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9212         /* Input mixer3 */
9213         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9214         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9215         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9216         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9217
9218         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9219
9220         { }
9221 };
9222
9223 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
9224         /*
9225          * Unmute ADC0-2 and set the default input to mic-in
9226          */
9227         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9228         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9229         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9230         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9231         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9232         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9233
9234         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9235          * mixer widget
9236          * Note: PASD motherboards uses the Line In 2 as the input for front
9237          * panel mic (mic 2)
9238          */
9239         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9240         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9241         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9242         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9243         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9244         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9245         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
9246         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
9247         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
9248         /*
9249          * Set up output mixers (0x0c - 0x0e)
9250          */
9251         /* set vol=0 to output mixers */
9252         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9253         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9254         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9255
9256         /* set up input amps for analog loopback */
9257         /* Amp Indices: DAC = 0, mixer = 1 */
9258         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9259         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9260         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9261         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9262         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9263         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9264
9265
9266         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
9267         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
9268         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
9269         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
9270         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
9271         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
9272         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
9273
9274         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9275         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9276
9277         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9278         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
9279
9280         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
9281         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9282         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9283         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
9284         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9285         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9286
9287         /* FIXME: use matrix-type input source selection */
9288         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9289         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9290         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
9291         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
9292         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
9293         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
9294         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
9295         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
9296         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
9297         /* Input mixer2 */
9298         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9299         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9300         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9301         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9302         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9303         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
9304         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
9305         /* Input mixer3 */
9306         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9307         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9308         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9309         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9310         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9311         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
9312         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
9313
9314         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9315
9316         { }
9317 };
9318
9319 #ifdef CONFIG_SND_HDA_POWER_SAVE
9320 #define alc262_loopbacks        alc880_loopbacks
9321 #endif
9322
9323 /* pcm configuration: identiacal with ALC880 */
9324 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
9325 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
9326 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
9327 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
9328
9329 /*
9330  * BIOS auto configuration
9331  */
9332 static int alc262_parse_auto_config(struct hda_codec *codec)
9333 {
9334         struct alc_spec *spec = codec->spec;
9335         int err;
9336         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
9337
9338         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
9339                                            alc262_ignore);
9340         if (err < 0)
9341                 return err;
9342         if (!spec->autocfg.line_outs)
9343                 return 0; /* can't find valid BIOS pin config */
9344         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
9345         if (err < 0)
9346                 return err;
9347         err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg);
9348         if (err < 0)
9349                 return err;
9350
9351         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
9352
9353         if (spec->autocfg.dig_out_pin)
9354                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
9355         if (spec->autocfg.dig_in_pin)
9356                 spec->dig_in_nid = ALC262_DIGIN_NID;
9357
9358         if (spec->kctl_alloc)
9359                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
9360
9361         spec->init_verbs[spec->num_init_verbs++] = alc262_volume_init_verbs;
9362         spec->num_mux_defs = 1;
9363         spec->input_mux = &spec->private_imux;
9364
9365         err = alc_auto_add_mic_boost(codec);
9366         if (err < 0)
9367                 return err;
9368
9369         return 1;
9370 }
9371
9372 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
9373 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
9374 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
9375
9376
9377 /* init callback for auto-configuration model -- overriding the default init */
9378 static void alc262_auto_init(struct hda_codec *codec)
9379 {
9380         struct alc_spec *spec = codec->spec;
9381         alc262_auto_init_multi_out(codec);
9382         alc262_auto_init_hp_out(codec);
9383         alc262_auto_init_analog_input(codec);
9384         if (spec->unsol_event)
9385                 alc_sku_automute(codec);
9386 }
9387
9388 /*
9389  * configuration and preset
9390  */
9391 static const char *alc262_models[ALC262_MODEL_LAST] = {
9392         [ALC262_BASIC]          = "basic",
9393         [ALC262_HIPPO]          = "hippo",
9394         [ALC262_HIPPO_1]        = "hippo_1",
9395         [ALC262_FUJITSU]        = "fujitsu",
9396         [ALC262_HP_BPC]         = "hp-bpc",
9397         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
9398         [ALC262_HP_TC_T5735]    = "hp-tc-t5735",
9399         [ALC262_HP_RP5700]      = "hp-rp5700",
9400         [ALC262_BENQ_ED8]       = "benq",
9401         [ALC262_BENQ_T31]       = "benq-t31",
9402         [ALC262_SONY_ASSAMD]    = "sony-assamd",
9403         [ALC262_ULTRA]          = "ultra",
9404         [ALC262_AUTO]           = "auto",
9405 };
9406
9407 static struct snd_pci_quirk alc262_cfg_tbl[] = {
9408         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
9409         SND_PCI_QUIRK(0x103c, 0x12fe, "HP xw9400", ALC262_HP_BPC),
9410         SND_PCI_QUIRK(0x103c, 0x12ff, "HP xw4550", ALC262_HP_BPC),
9411         SND_PCI_QUIRK(0x103c, 0x1306, "HP xw8600", ALC262_HP_BPC),
9412         SND_PCI_QUIRK(0x103c, 0x1307, "HP xw6600", ALC262_HP_BPC),
9413         SND_PCI_QUIRK(0x103c, 0x1308, "HP xw4600", ALC262_HP_BPC),
9414         SND_PCI_QUIRK(0x103c, 0x1309, "HP xw4*00", ALC262_HP_BPC),
9415         SND_PCI_QUIRK(0x103c, 0x130a, "HP xw6*00", ALC262_HP_BPC),
9416         SND_PCI_QUIRK(0x103c, 0x130b, "HP xw8*00", ALC262_HP_BPC),
9417         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
9418         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
9419         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
9420         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
9421         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
9422         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
9423         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
9424         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
9425         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
9426         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
9427         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
9428         SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
9429                       ALC262_HP_TC_T5735),
9430         SND_PCI_QUIRK(0x103c, 0x2817, "HP RP5700", ALC262_HP_RP5700),
9431         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
9432         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
9433         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
9434         SND_PCI_QUIRK(0x104d, 0x900e, "Sony ASSAMD", ALC262_SONY_ASSAMD),
9435         SND_PCI_QUIRK(0x104d, 0x9015, "Sony 0x9015", ALC262_SONY_ASSAMD),
9436         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
9437         SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
9438         SND_PCI_QUIRK(0x144d, 0xc032, "Samsung Q1 Ultra", ALC262_ULTRA),
9439         SND_PCI_QUIRK(0x144d, 0xc039, "Samsung Q1U EL", ALC262_ULTRA),
9440         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
9441         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
9442         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
9443         {}
9444 };
9445
9446 static struct alc_config_preset alc262_presets[] = {
9447         [ALC262_BASIC] = {
9448                 .mixers = { alc262_base_mixer },
9449                 .init_verbs = { alc262_init_verbs },
9450                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9451                 .dac_nids = alc262_dac_nids,
9452                 .hp_nid = 0x03,
9453                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9454                 .channel_mode = alc262_modes,
9455                 .input_mux = &alc262_capture_source,
9456         },
9457         [ALC262_HIPPO] = {
9458                 .mixers = { alc262_base_mixer },
9459                 .init_verbs = { alc262_init_verbs, alc262_hippo_unsol_verbs},
9460                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9461                 .dac_nids = alc262_dac_nids,
9462                 .hp_nid = 0x03,
9463                 .dig_out_nid = ALC262_DIGOUT_NID,
9464                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9465                 .channel_mode = alc262_modes,
9466                 .input_mux = &alc262_capture_source,
9467                 .unsol_event = alc262_hippo_unsol_event,
9468                 .init_hook = alc262_hippo_automute,
9469         },
9470         [ALC262_HIPPO_1] = {
9471                 .mixers = { alc262_hippo1_mixer },
9472                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
9473                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9474                 .dac_nids = alc262_dac_nids,
9475                 .hp_nid = 0x02,
9476                 .dig_out_nid = ALC262_DIGOUT_NID,
9477                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9478                 .channel_mode = alc262_modes,
9479                 .input_mux = &alc262_capture_source,
9480                 .unsol_event = alc262_hippo1_unsol_event,
9481                 .init_hook = alc262_hippo1_automute,
9482         },
9483         [ALC262_FUJITSU] = {
9484                 .mixers = { alc262_fujitsu_mixer },
9485                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
9486                                 alc262_fujitsu_unsol_verbs },
9487                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9488                 .dac_nids = alc262_dac_nids,
9489                 .hp_nid = 0x03,
9490                 .dig_out_nid = ALC262_DIGOUT_NID,
9491                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9492                 .channel_mode = alc262_modes,
9493                 .input_mux = &alc262_fujitsu_capture_source,
9494                 .unsol_event = alc262_fujitsu_unsol_event,
9495         },
9496         [ALC262_HP_BPC] = {
9497                 .mixers = { alc262_HP_BPC_mixer },
9498                 .init_verbs = { alc262_HP_BPC_init_verbs },
9499                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9500                 .dac_nids = alc262_dac_nids,
9501                 .hp_nid = 0x03,
9502                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9503                 .channel_mode = alc262_modes,
9504                 .input_mux = &alc262_HP_capture_source,
9505                 .unsol_event = alc262_hp_bpc_unsol_event,
9506                 .init_hook = alc262_hp_bpc_automute,
9507         },
9508         [ALC262_HP_BPC_D7000_WF] = {
9509                 .mixers = { alc262_HP_BPC_WildWest_mixer },
9510                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
9511                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9512                 .dac_nids = alc262_dac_nids,
9513                 .hp_nid = 0x03,
9514                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9515                 .channel_mode = alc262_modes,
9516                 .input_mux = &alc262_HP_D7000_capture_source,
9517                 .unsol_event = alc262_hp_wildwest_unsol_event,
9518                 .init_hook = alc262_hp_wildwest_automute,
9519         },
9520         [ALC262_HP_BPC_D7000_WL] = {
9521                 .mixers = { alc262_HP_BPC_WildWest_mixer,
9522                             alc262_HP_BPC_WildWest_option_mixer },
9523                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
9524                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9525                 .dac_nids = alc262_dac_nids,
9526                 .hp_nid = 0x03,
9527                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9528                 .channel_mode = alc262_modes,
9529                 .input_mux = &alc262_HP_D7000_capture_source,
9530                 .unsol_event = alc262_hp_wildwest_unsol_event,
9531                 .init_hook = alc262_hp_wildwest_automute,
9532         },
9533         [ALC262_HP_TC_T5735] = {
9534                 .mixers = { alc262_hp_t5735_mixer },
9535                 .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
9536                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9537                 .dac_nids = alc262_dac_nids,
9538                 .hp_nid = 0x03,
9539                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9540                 .channel_mode = alc262_modes,
9541                 .input_mux = &alc262_capture_source,
9542                 .unsol_event = alc262_hp_t5735_unsol_event,
9543                 .init_hook = alc262_hp_t5735_init_hook,
9544         },
9545         [ALC262_HP_RP5700] = {
9546                 .mixers = { alc262_hp_rp5700_mixer },
9547                 .init_verbs = { alc262_init_verbs, alc262_hp_rp5700_verbs },
9548                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9549                 .dac_nids = alc262_dac_nids,
9550                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9551                 .channel_mode = alc262_modes,
9552                 .input_mux = &alc262_hp_rp5700_capture_source,
9553         },
9554         [ALC262_BENQ_ED8] = {
9555                 .mixers = { alc262_base_mixer },
9556                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
9557                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9558                 .dac_nids = alc262_dac_nids,
9559                 .hp_nid = 0x03,
9560                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9561                 .channel_mode = alc262_modes,
9562                 .input_mux = &alc262_capture_source,
9563         },
9564         [ALC262_SONY_ASSAMD] = {
9565                 .mixers = { alc262_sony_mixer },
9566                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
9567                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9568                 .dac_nids = alc262_dac_nids,
9569                 .hp_nid = 0x02,
9570                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9571                 .channel_mode = alc262_modes,
9572                 .input_mux = &alc262_capture_source,
9573                 .unsol_event = alc262_hippo_unsol_event,
9574                 .init_hook = alc262_hippo_automute,
9575         },
9576         [ALC262_BENQ_T31] = {
9577                 .mixers = { alc262_benq_t31_mixer },
9578                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs, alc262_hippo_unsol_verbs },
9579                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9580                 .dac_nids = alc262_dac_nids,
9581                 .hp_nid = 0x03,
9582                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9583                 .channel_mode = alc262_modes,
9584                 .input_mux = &alc262_capture_source,
9585                 .unsol_event = alc262_hippo_unsol_event,
9586                 .init_hook = alc262_hippo_automute,
9587         },      
9588         [ALC262_ULTRA] = {
9589                 .mixers = { alc262_ultra_mixer, alc262_ultra_capture_mixer },
9590                 .init_verbs = { alc262_ultra_verbs },
9591                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9592                 .dac_nids = alc262_dac_nids,
9593                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9594                 .channel_mode = alc262_modes,
9595                 .input_mux = &alc262_ultra_capture_source,
9596                 .adc_nids = alc262_adc_nids, /* ADC0 */
9597                 .capsrc_nids = alc262_capsrc_nids,
9598                 .num_adc_nids = 1, /* single ADC */
9599                 .unsol_event = alc262_ultra_unsol_event,
9600                 .init_hook = alc262_ultra_automute,
9601         },
9602 };
9603
9604 static int patch_alc262(struct hda_codec *codec)
9605 {
9606         struct alc_spec *spec;
9607         int board_config;
9608         int err;
9609
9610         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
9611         if (spec == NULL)
9612                 return -ENOMEM;
9613
9614         codec->spec = spec;
9615 #if 0
9616         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
9617          * under-run
9618          */
9619         {
9620         int tmp;
9621         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
9622         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
9623         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
9624         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
9625         }
9626 #endif
9627
9628         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
9629                                                   alc262_models,
9630                                                   alc262_cfg_tbl);
9631
9632         if (board_config < 0) {
9633                 printk(KERN_INFO "hda_codec: Unknown model for ALC262, "
9634                        "trying auto-probe from BIOS...\n");
9635                 board_config = ALC262_AUTO;
9636         }
9637
9638         if (board_config == ALC262_AUTO) {
9639                 /* automatic parse from the BIOS config */
9640                 err = alc262_parse_auto_config(codec);
9641                 if (err < 0) {
9642                         alc_free(codec);
9643                         return err;
9644                 } else if (!err) {
9645                         printk(KERN_INFO
9646                                "hda_codec: Cannot set up configuration "
9647                                "from BIOS.  Using base mode...\n");
9648                         board_config = ALC262_BASIC;
9649                 }
9650         }
9651
9652         if (board_config != ALC262_AUTO)
9653                 setup_preset(spec, &alc262_presets[board_config]);
9654
9655         spec->stream_name_analog = "ALC262 Analog";
9656         spec->stream_analog_playback = &alc262_pcm_analog_playback;
9657         spec->stream_analog_capture = &alc262_pcm_analog_capture;
9658                 
9659         spec->stream_name_digital = "ALC262 Digital";
9660         spec->stream_digital_playback = &alc262_pcm_digital_playback;
9661         spec->stream_digital_capture = &alc262_pcm_digital_capture;
9662
9663         if (!spec->adc_nids && spec->input_mux) {
9664                 /* check whether NID 0x07 is valid */
9665                 unsigned int wcap = get_wcaps(codec, 0x07);
9666
9667                 /* get type */
9668                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
9669                 if (wcap != AC_WID_AUD_IN) {
9670                         spec->adc_nids = alc262_adc_nids_alt;
9671                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
9672                         spec->capsrc_nids = alc262_capsrc_nids_alt;
9673                         spec->mixers[spec->num_mixers] =
9674                                 alc262_capture_alt_mixer;
9675                         spec->num_mixers++;
9676                 } else {
9677                         spec->adc_nids = alc262_adc_nids;
9678                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
9679                         spec->capsrc_nids = alc262_capsrc_nids;
9680                         spec->mixers[spec->num_mixers] = alc262_capture_mixer;
9681                         spec->num_mixers++;
9682                 }
9683         }
9684
9685         spec->vmaster_nid = 0x0c;
9686
9687         codec->patch_ops = alc_patch_ops;
9688         if (board_config == ALC262_AUTO)
9689                 spec->init_hook = alc262_auto_init;
9690 #ifdef CONFIG_SND_HDA_POWER_SAVE
9691         if (!spec->loopback.amplist)
9692                 spec->loopback.amplist = alc262_loopbacks;
9693 #endif
9694                 
9695         return 0;
9696 }
9697
9698 /*
9699  *  ALC268 channel source setting (2 channel)
9700  */
9701 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
9702 #define alc268_modes            alc260_modes
9703         
9704 static hda_nid_t alc268_dac_nids[2] = {
9705         /* front, hp */
9706         0x02, 0x03
9707 };
9708
9709 static hda_nid_t alc268_adc_nids[2] = {
9710         /* ADC0-1 */
9711         0x08, 0x07
9712 };
9713
9714 static hda_nid_t alc268_adc_nids_alt[1] = {
9715         /* ADC0 */
9716         0x08
9717 };
9718
9719 static hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
9720
9721 static struct snd_kcontrol_new alc268_base_mixer[] = {
9722         /* output mixer control */
9723         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
9724         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9725         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
9726         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9727         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9728         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9729         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
9730         { }
9731 };
9732
9733 /* bind Beep switches of both NID 0x0f and 0x10 */
9734 static struct hda_bind_ctls alc268_bind_beep_sw = {
9735         .ops = &snd_hda_bind_sw,
9736         .values = {
9737                 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
9738                 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
9739                 0
9740         },
9741 };
9742
9743 static struct snd_kcontrol_new alc268_beep_mixer[] = {
9744         HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
9745         HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
9746         { }
9747 };
9748
9749 static struct hda_verb alc268_eapd_verbs[] = {
9750         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
9751         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
9752         { }
9753 };
9754
9755 /* Toshiba specific */
9756 #define alc268_toshiba_automute alc262_hippo_automute
9757
9758 static struct hda_verb alc268_toshiba_verbs[] = {
9759         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9760         { } /* end */
9761 };
9762
9763 /* Acer specific */
9764 /* bind volumes of both NID 0x02 and 0x03 */
9765 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
9766         .ops = &snd_hda_bind_vol,
9767         .values = {
9768                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
9769                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
9770                 0
9771         },
9772 };
9773
9774 /* mute/unmute internal speaker according to the hp jack and mute state */
9775 static void alc268_acer_automute(struct hda_codec *codec, int force)
9776 {
9777         struct alc_spec *spec = codec->spec;
9778         unsigned int mute;
9779
9780         if (force || !spec->sense_updated) {
9781                 unsigned int present;
9782                 present = snd_hda_codec_read(codec, 0x14, 0,
9783                                          AC_VERB_GET_PIN_SENSE, 0);
9784                 spec->jack_present = (present & 0x80000000) != 0;
9785                 spec->sense_updated = 1;
9786         }
9787         if (spec->jack_present)
9788                 mute = HDA_AMP_MUTE; /* mute internal speaker */
9789         else /* unmute internal speaker if necessary */
9790                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
9791         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9792                                  HDA_AMP_MUTE, mute);
9793 }
9794
9795
9796 /* bind hp and internal speaker mute (with plug check) */
9797 static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
9798                                      struct snd_ctl_elem_value *ucontrol)
9799 {
9800         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9801         long *valp = ucontrol->value.integer.value;
9802         int change;
9803
9804         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
9805                                           HDA_AMP_MUTE,
9806                                           valp[0] ? 0 : HDA_AMP_MUTE);
9807         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
9808                                            HDA_AMP_MUTE,
9809                                            valp[1] ? 0 : HDA_AMP_MUTE);
9810         if (change)
9811                 alc268_acer_automute(codec, 0);
9812         return change;
9813 }
9814
9815 static struct snd_kcontrol_new alc268_acer_mixer[] = {
9816         /* output mixer control */
9817         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
9818         {
9819                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9820                 .name = "Master Playback Switch",
9821                 .info = snd_hda_mixer_amp_switch_info,
9822                 .get = snd_hda_mixer_amp_switch_get,
9823                 .put = alc268_acer_master_sw_put,
9824                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
9825         },
9826         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9827         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
9828         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
9829         { }
9830 };
9831
9832 static struct hda_verb alc268_acer_verbs[] = {
9833         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
9834         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9835         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9836         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9837         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
9838         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
9839
9840         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9841         { }
9842 };
9843
9844 /* unsolicited event for HP jack sensing */
9845 static void alc268_toshiba_unsol_event(struct hda_codec *codec,
9846                                        unsigned int res)
9847 {
9848         if ((res >> 26) != ALC880_HP_EVENT)
9849                 return;
9850         alc268_toshiba_automute(codec);
9851 }
9852
9853 static void alc268_acer_unsol_event(struct hda_codec *codec,
9854                                        unsigned int res)
9855 {
9856         if ((res >> 26) != ALC880_HP_EVENT)
9857                 return;
9858         alc268_acer_automute(codec, 1);
9859 }
9860
9861 static void alc268_acer_init_hook(struct hda_codec *codec)
9862 {
9863         alc268_acer_automute(codec, 1);
9864 }
9865
9866 static struct snd_kcontrol_new alc268_dell_mixer[] = {
9867         /* output mixer control */
9868         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
9869         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9870         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
9871         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9872         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9873         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
9874         { }
9875 };
9876
9877 static struct hda_verb alc268_dell_verbs[] = {
9878         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9879         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9880         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9881         { }
9882 };
9883
9884 /* mute/unmute internal speaker according to the hp jack and mute state */
9885 static void alc268_dell_automute(struct hda_codec *codec)
9886 {
9887         unsigned int present;
9888         unsigned int mute;
9889
9890         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0);
9891         if (present & 0x80000000)
9892                 mute = HDA_AMP_MUTE;
9893         else
9894                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
9895         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9896                                  HDA_AMP_MUTE, mute);
9897 }
9898
9899 static void alc268_dell_unsol_event(struct hda_codec *codec,
9900                                     unsigned int res)
9901 {
9902         if ((res >> 26) != ALC880_HP_EVENT)
9903                 return;
9904         alc268_dell_automute(codec);
9905 }
9906
9907 #define alc268_dell_init_hook   alc268_dell_automute
9908
9909 /*
9910  * generic initialization of ADC, input mixers and output mixers
9911  */
9912 static struct hda_verb alc268_base_init_verbs[] = {
9913         /* Unmute DAC0-1 and set vol = 0 */
9914         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9915         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9916         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9917         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9918         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9919         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9920
9921         /*
9922          * Set up output mixers (0x0c - 0x0e)
9923          */
9924         /* set vol=0 to output mixers */
9925         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9926         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9927         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9928         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
9929
9930         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9931         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9932
9933         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9934         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9935         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9936         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9937         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9938         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9939         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9940         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9941
9942         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9943         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9944         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9945         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9946         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9947         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9948         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9949
9950         /* set PCBEEP vol = 0, mute connections */
9951         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9952         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9953         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9954
9955         /* Unmute Selector 23h,24h and set the default input to mic-in */
9956         
9957         {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
9958         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9959         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
9960         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9961
9962         { }
9963 };
9964
9965 /*
9966  * generic initialization of ADC, input mixers and output mixers
9967  */
9968 static struct hda_verb alc268_volume_init_verbs[] = {
9969         /* set output DAC */
9970         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9971         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9972         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9973         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9974
9975         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9976         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9977         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9978         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9979         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9980
9981         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9982         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9983         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9984         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9985         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9986
9987         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9988         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9989         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9990         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9991
9992         /* set PCBEEP vol = 0, mute connections */
9993         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9994         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9995         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9996
9997         { }
9998 };
9999
10000 #define alc268_mux_enum_info alc_mux_enum_info
10001 #define alc268_mux_enum_get alc_mux_enum_get
10002 #define alc268_mux_enum_put alc_mux_enum_put
10003
10004 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
10005         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
10006         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
10007         {
10008                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10009                 /* The multiple "Capture Source" controls confuse alsamixer
10010                  * So call somewhat different..
10011                  */
10012                 /* .name = "Capture Source", */
10013                 .name = "Input Source",
10014                 .count = 1,
10015                 .info = alc268_mux_enum_info,
10016                 .get = alc268_mux_enum_get,
10017                 .put = alc268_mux_enum_put,
10018         },
10019         { } /* end */
10020 };
10021
10022 static struct snd_kcontrol_new alc268_capture_mixer[] = {
10023         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
10024         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
10025         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
10026         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
10027         {
10028                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10029                 /* The multiple "Capture Source" controls confuse alsamixer
10030                  * So call somewhat different..
10031                  */
10032                 /* .name = "Capture Source", */
10033                 .name = "Input Source",
10034                 .count = 2,
10035                 .info = alc268_mux_enum_info,
10036                 .get = alc268_mux_enum_get,
10037                 .put = alc268_mux_enum_put,
10038         },
10039         { } /* end */
10040 };
10041
10042 static struct hda_input_mux alc268_capture_source = {
10043         .num_items = 4,
10044         .items = {
10045                 { "Mic", 0x0 },
10046                 { "Front Mic", 0x1 },
10047                 { "Line", 0x2 },
10048                 { "CD", 0x3 },
10049         },
10050 };
10051
10052 static struct hda_input_mux alc268_acer_capture_source = {
10053         .num_items = 3,
10054         .items = {
10055                 { "Mic", 0x0 },
10056                 { "Internal Mic", 0x6 },
10057                 { "Line", 0x2 },
10058         },
10059 };
10060
10061 #ifdef CONFIG_SND_DEBUG
10062 static struct snd_kcontrol_new alc268_test_mixer[] = {
10063         /* Volume widgets */
10064         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10065         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
10066         HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
10067         HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
10068         HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
10069         HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
10070         HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
10071         HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
10072         HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
10073         HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
10074         HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
10075         HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
10076         HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
10077         /* The below appears problematic on some hardwares */
10078         /*HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),*/
10079         HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
10080         HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
10081         HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
10082         HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),
10083
10084         /* Modes for retasking pin widgets */
10085         ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
10086         ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
10087         ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
10088         ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),
10089
10090         /* Controls for GPIO pins, assuming they are configured as outputs */
10091         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
10092         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
10093         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
10094         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
10095
10096         /* Switches to allow the digital SPDIF output pin to be enabled.
10097          * The ALC268 does not have an SPDIF input.
10098          */
10099         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),
10100
10101         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
10102          * this output to turn on an external amplifier.
10103          */
10104         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
10105         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
10106
10107         { } /* end */
10108 };
10109 #endif
10110
10111 /* create input playback/capture controls for the given pin */
10112 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
10113                                     const char *ctlname, int idx)
10114 {
10115         char name[32];
10116         int err;
10117
10118         sprintf(name, "%s Playback Volume", ctlname);
10119         if (nid == 0x14) {
10120                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
10121                                   HDA_COMPOSE_AMP_VAL(0x02, 3, idx,
10122                                                       HDA_OUTPUT));
10123                 if (err < 0)
10124                         return err;
10125         } else if (nid == 0x15) {
10126                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
10127                                   HDA_COMPOSE_AMP_VAL(0x03, 3, idx,
10128                                                       HDA_OUTPUT));
10129                 if (err < 0)
10130                         return err;
10131         } else
10132                 return -1;
10133         sprintf(name, "%s Playback Switch", ctlname);
10134         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
10135                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
10136         if (err < 0)
10137                 return err;
10138         return 0;
10139 }
10140
10141 /* add playback controls from the parsed DAC table */
10142 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
10143                                              const struct auto_pin_cfg *cfg)
10144 {
10145         hda_nid_t nid;
10146         int err;
10147
10148         spec->multiout.num_dacs = 2;    /* only use one dac */
10149         spec->multiout.dac_nids = spec->private_dac_nids;
10150         spec->multiout.dac_nids[0] = 2;
10151         spec->multiout.dac_nids[1] = 3;
10152
10153         nid = cfg->line_out_pins[0];
10154         if (nid)
10155                 alc268_new_analog_output(spec, nid, "Front", 0);        
10156
10157         nid = cfg->speaker_pins[0];
10158         if (nid == 0x1d) {
10159                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
10160                                   "Speaker Playback Volume",
10161                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
10162                 if (err < 0)
10163                         return err;
10164         }
10165         nid = cfg->hp_pins[0];
10166         if (nid)
10167                 alc268_new_analog_output(spec, nid, "Headphone", 0);
10168
10169         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
10170         if (nid == 0x16) {
10171                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10172                                   "Mono Playback Switch",
10173                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_INPUT));
10174                 if (err < 0)
10175                         return err;
10176         }
10177         return 0;       
10178 }
10179
10180 /* create playback/capture controls for input pins */
10181 static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
10182                                                 const struct auto_pin_cfg *cfg)
10183 {
10184         struct hda_input_mux *imux = &spec->private_imux;
10185         int i, idx1;
10186
10187         for (i = 0; i < AUTO_PIN_LAST; i++) {
10188                 switch(cfg->input_pins[i]) {
10189                 case 0x18:
10190                         idx1 = 0;       /* Mic 1 */
10191                         break;
10192                 case 0x19:
10193                         idx1 = 1;       /* Mic 2 */
10194                         break;
10195                 case 0x1a:
10196                         idx1 = 2;       /* Line In */
10197                         break;
10198                 case 0x1c:      
10199                         idx1 = 3;       /* CD */
10200                         break;
10201                 case 0x12:
10202                 case 0x13:
10203                         idx1 = 6;       /* digital mics */
10204                         break;
10205                 default:
10206                         continue;
10207                 }
10208                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
10209                 imux->items[imux->num_items].index = idx1;
10210                 imux->num_items++;      
10211         }
10212         return 0;
10213 }
10214
10215 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
10216 {
10217         struct alc_spec *spec = codec->spec;
10218         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
10219         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
10220         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
10221         unsigned int    dac_vol1, dac_vol2;
10222
10223         if (speaker_nid) {
10224                 snd_hda_codec_write(codec, speaker_nid, 0,
10225                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
10226                 snd_hda_codec_write(codec, 0x0f, 0,
10227                                     AC_VERB_SET_AMP_GAIN_MUTE,
10228                                     AMP_IN_UNMUTE(1));
10229                 snd_hda_codec_write(codec, 0x10, 0,
10230                                     AC_VERB_SET_AMP_GAIN_MUTE,
10231                                     AMP_IN_UNMUTE(1));
10232         } else {
10233                 snd_hda_codec_write(codec, 0x0f, 0,
10234                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
10235                 snd_hda_codec_write(codec, 0x10, 0,
10236                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
10237         }
10238
10239         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
10240         if (line_nid == 0x14)   
10241                 dac_vol2 = AMP_OUT_ZERO;
10242         else if (line_nid == 0x15)
10243                 dac_vol1 = AMP_OUT_ZERO;
10244         if (hp_nid == 0x14)     
10245                 dac_vol2 = AMP_OUT_ZERO;
10246         else if (hp_nid == 0x15)
10247                 dac_vol1 = AMP_OUT_ZERO;
10248         if (line_nid != 0x16 || hp_nid != 0x16 ||
10249             spec->autocfg.line_out_pins[1] != 0x16 ||
10250             spec->autocfg.line_out_pins[2] != 0x16)
10251                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
10252
10253         snd_hda_codec_write(codec, 0x02, 0,
10254                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
10255         snd_hda_codec_write(codec, 0x03, 0,
10256                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
10257 }
10258
10259 /* pcm configuration: identiacal with ALC880 */
10260 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
10261 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
10262 #define alc268_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
10263 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
10264
10265 /*
10266  * BIOS auto configuration
10267  */
10268 static int alc268_parse_auto_config(struct hda_codec *codec)
10269 {
10270         struct alc_spec *spec = codec->spec;
10271         int err;
10272         static hda_nid_t alc268_ignore[] = { 0 };
10273
10274         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
10275                                            alc268_ignore);
10276         if (err < 0)
10277                 return err;
10278         if (!spec->autocfg.line_outs)
10279                 return 0; /* can't find valid BIOS pin config */
10280
10281         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
10282         if (err < 0)
10283                 return err;
10284         err = alc268_auto_create_analog_input_ctls(spec, &spec->autocfg);
10285         if (err < 0)
10286                 return err;
10287
10288         spec->multiout.max_channels = 2;
10289
10290         /* digital only support output */
10291         if (spec->autocfg.dig_out_pin)
10292                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
10293
10294         if (spec->kctl_alloc)
10295                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
10296
10297         if (spec->autocfg.speaker_pins[0] != 0x1d)
10298                 spec->mixers[spec->num_mixers++] = alc268_beep_mixer;
10299
10300         spec->init_verbs[spec->num_init_verbs++] = alc268_volume_init_verbs;
10301         spec->num_mux_defs = 1;
10302         spec->input_mux = &spec->private_imux;
10303
10304         err = alc_auto_add_mic_boost(codec);
10305         if (err < 0)
10306                 return err;
10307
10308         return 1;
10309 }
10310
10311 #define alc268_auto_init_multi_out      alc882_auto_init_multi_out
10312 #define alc268_auto_init_hp_out         alc882_auto_init_hp_out
10313 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
10314
10315 /* init callback for auto-configuration model -- overriding the default init */
10316 static void alc268_auto_init(struct hda_codec *codec)
10317 {
10318         struct alc_spec *spec = codec->spec;
10319         alc268_auto_init_multi_out(codec);
10320         alc268_auto_init_hp_out(codec);
10321         alc268_auto_init_mono_speaker_out(codec);
10322         alc268_auto_init_analog_input(codec);
10323         if (spec->unsol_event)
10324                 alc_sku_automute(codec);
10325 }
10326
10327 /*
10328  * configuration and preset
10329  */
10330 static const char *alc268_models[ALC268_MODEL_LAST] = {
10331         [ALC268_3ST]            = "3stack",
10332         [ALC268_TOSHIBA]        = "toshiba",
10333         [ALC268_ACER]           = "acer",
10334         [ALC268_DELL]           = "dell",
10335         [ALC268_ZEPTO]          = "zepto",
10336 #ifdef CONFIG_SND_DEBUG
10337         [ALC268_TEST]           = "test",
10338 #endif
10339         [ALC268_AUTO]           = "auto",
10340 };
10341
10342 static struct snd_pci_quirk alc268_cfg_tbl[] = {
10343         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
10344         SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
10345         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
10346         SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER),
10347         SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
10348         SND_PCI_QUIRK(0x103c, 0x30cc, "TOSHIBA", ALC268_TOSHIBA),
10349         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
10350         SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA),
10351         SND_PCI_QUIRK(0x1179, 0xff50, "TOSHIBA A305", ALC268_TOSHIBA),
10352         SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
10353         SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
10354         {}
10355 };
10356
10357 static struct alc_config_preset alc268_presets[] = {
10358         [ALC268_3ST] = {
10359                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
10360                             alc268_beep_mixer },
10361                 .init_verbs = { alc268_base_init_verbs },
10362                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10363                 .dac_nids = alc268_dac_nids,
10364                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10365                 .adc_nids = alc268_adc_nids_alt,
10366                 .capsrc_nids = alc268_capsrc_nids,
10367                 .hp_nid = 0x03,
10368                 .dig_out_nid = ALC268_DIGOUT_NID,
10369                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10370                 .channel_mode = alc268_modes,
10371                 .input_mux = &alc268_capture_source,
10372         },
10373         [ALC268_TOSHIBA] = {
10374                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
10375                             alc268_beep_mixer },
10376                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10377                                 alc268_toshiba_verbs },
10378                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10379                 .dac_nids = alc268_dac_nids,
10380                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10381                 .adc_nids = alc268_adc_nids_alt,
10382                 .capsrc_nids = alc268_capsrc_nids,
10383                 .hp_nid = 0x03,
10384                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10385                 .channel_mode = alc268_modes,
10386                 .input_mux = &alc268_capture_source,
10387                 .unsol_event = alc268_toshiba_unsol_event,
10388                 .init_hook = alc268_toshiba_automute,
10389         },
10390         [ALC268_ACER] = {
10391                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
10392                             alc268_beep_mixer },
10393                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10394                                 alc268_acer_verbs },
10395                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10396                 .dac_nids = alc268_dac_nids,
10397                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10398                 .adc_nids = alc268_adc_nids_alt,
10399                 .capsrc_nids = alc268_capsrc_nids,
10400                 .hp_nid = 0x02,
10401                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10402                 .channel_mode = alc268_modes,
10403                 .input_mux = &alc268_acer_capture_source,
10404                 .unsol_event = alc268_acer_unsol_event,
10405                 .init_hook = alc268_acer_init_hook,
10406         },
10407         [ALC268_DELL] = {
10408                 .mixers = { alc268_dell_mixer, alc268_beep_mixer },
10409                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10410                                 alc268_dell_verbs },
10411                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10412                 .dac_nids = alc268_dac_nids,
10413                 .hp_nid = 0x02,
10414                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10415                 .channel_mode = alc268_modes,
10416                 .unsol_event = alc268_dell_unsol_event,
10417                 .init_hook = alc268_dell_init_hook,
10418                 .input_mux = &alc268_capture_source,
10419         },
10420         [ALC268_ZEPTO] = {
10421                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
10422                             alc268_beep_mixer },
10423                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10424                                 alc268_toshiba_verbs },
10425                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10426                 .dac_nids = alc268_dac_nids,
10427                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10428                 .adc_nids = alc268_adc_nids_alt,
10429                 .capsrc_nids = alc268_capsrc_nids,
10430                 .hp_nid = 0x03,
10431                 .dig_out_nid = ALC268_DIGOUT_NID,
10432                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10433                 .channel_mode = alc268_modes,
10434                 .input_mux = &alc268_capture_source,
10435                 .unsol_event = alc268_toshiba_unsol_event,
10436                 .init_hook = alc268_toshiba_automute
10437         },
10438 #ifdef CONFIG_SND_DEBUG
10439         [ALC268_TEST] = {
10440                 .mixers = { alc268_test_mixer, alc268_capture_mixer },
10441                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10442                                 alc268_volume_init_verbs },
10443                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10444                 .dac_nids = alc268_dac_nids,
10445                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10446                 .adc_nids = alc268_adc_nids_alt,
10447                 .capsrc_nids = alc268_capsrc_nids,
10448                 .hp_nid = 0x03,
10449                 .dig_out_nid = ALC268_DIGOUT_NID,
10450                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10451                 .channel_mode = alc268_modes,
10452                 .input_mux = &alc268_capture_source,
10453         },
10454 #endif
10455 };
10456
10457 static int patch_alc268(struct hda_codec *codec)
10458 {
10459         struct alc_spec *spec;
10460         int board_config;
10461         int err;
10462
10463         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
10464         if (spec == NULL)
10465                 return -ENOMEM;
10466
10467         codec->spec = spec;
10468
10469         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
10470                                                   alc268_models,
10471                                                   alc268_cfg_tbl);
10472
10473         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
10474                 printk(KERN_INFO "hda_codec: Unknown model for ALC268, "
10475                        "trying auto-probe from BIOS...\n");
10476                 board_config = ALC268_AUTO;
10477         }
10478
10479         if (board_config == ALC268_AUTO) {
10480                 /* automatic parse from the BIOS config */
10481                 err = alc268_parse_auto_config(codec);
10482                 if (err < 0) {
10483                         alc_free(codec);
10484                         return err;
10485                 } else if (!err) {
10486                         printk(KERN_INFO
10487                                "hda_codec: Cannot set up configuration "
10488                                "from BIOS.  Using base mode...\n");
10489                         board_config = ALC268_3ST;
10490                 }
10491         }
10492
10493         if (board_config != ALC268_AUTO)
10494                 setup_preset(spec, &alc268_presets[board_config]);
10495
10496         spec->stream_name_analog = "ALC268 Analog";
10497         spec->stream_analog_playback = &alc268_pcm_analog_playback;
10498         spec->stream_analog_capture = &alc268_pcm_analog_capture;
10499         spec->stream_analog_alt_capture = &alc268_pcm_analog_alt_capture;
10500
10501         spec->stream_name_digital = "ALC268 Digital";
10502         spec->stream_digital_playback = &alc268_pcm_digital_playback;
10503
10504         if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
10505                 /* override the amp caps for beep generator */
10506                 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
10507                                           (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
10508                                           (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
10509                                           (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
10510                                           (0 << AC_AMPCAP_MUTE_SHIFT));
10511
10512         if (!spec->adc_nids && spec->input_mux) {
10513                 /* check whether NID 0x07 is valid */
10514                 unsigned int wcap = get_wcaps(codec, 0x07);
10515                 int i;
10516
10517                 /* get type */
10518                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
10519                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
10520                         spec->adc_nids = alc268_adc_nids_alt;
10521                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
10522                         spec->mixers[spec->num_mixers] =
10523                                         alc268_capture_alt_mixer;
10524                         spec->num_mixers++;
10525                 } else {
10526                         spec->adc_nids = alc268_adc_nids;
10527                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
10528                         spec->mixers[spec->num_mixers] =
10529                                 alc268_capture_mixer;
10530                         spec->num_mixers++;
10531                 }
10532                 spec->capsrc_nids = alc268_capsrc_nids;
10533                 /* set default input source */
10534                 for (i = 0; i < spec->num_adc_nids; i++)
10535                         snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
10536                                 0, AC_VERB_SET_CONNECT_SEL,
10537                                 spec->input_mux->items[0].index);
10538         }
10539
10540         spec->vmaster_nid = 0x02;
10541
10542         codec->patch_ops = alc_patch_ops;
10543         if (board_config == ALC268_AUTO)
10544                 spec->init_hook = alc268_auto_init;
10545                 
10546         return 0;
10547 }
10548
10549 /*
10550  *  ALC269 channel source setting (2 channel)
10551  */
10552 #define ALC269_DIGOUT_NID       ALC880_DIGOUT_NID
10553
10554 #define alc269_dac_nids         alc260_dac_nids
10555
10556 static hda_nid_t alc269_adc_nids[1] = {
10557         /* ADC1 */
10558         0x07,
10559 };
10560
10561 #define alc269_modes            alc260_modes
10562 #define alc269_capture_source   alc880_lg_lw_capture_source
10563
10564 static struct snd_kcontrol_new alc269_base_mixer[] = {
10565         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10566         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10567         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10568         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10569         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10570         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10571         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10572         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10573         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10574         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10575         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10576         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
10577         { } /* end */
10578 };
10579
10580 /* capture mixer elements */
10581 static struct snd_kcontrol_new alc269_capture_mixer[] = {
10582         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
10583         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
10584         {
10585                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10586                 /* The multiple "Capture Source" controls confuse alsamixer
10587                  * So call somewhat different..
10588                  */
10589                 /* .name = "Capture Source", */
10590                 .name = "Input Source",
10591                 .count = 1,
10592                 .info = alc_mux_enum_info,
10593                 .get = alc_mux_enum_get,
10594                 .put = alc_mux_enum_put,
10595         },
10596         { } /* end */
10597 };
10598
10599 /*
10600  * generic initialization of ADC, input mixers and output mixers
10601  */
10602 static struct hda_verb alc269_init_verbs[] = {
10603         /*
10604          * Unmute ADC0 and set the default input to mic-in
10605          */
10606         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10607
10608         /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the
10609          * analog-loopback mixer widget
10610          * Note: PASD motherboards uses the Line In 2 as the input for
10611          * front panel mic (mic 2)
10612          */
10613         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10614         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10615         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10616         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10617         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10618         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10619
10620         /*
10621          * Set up output mixers (0x0c - 0x0e)
10622          */
10623         /* set vol=0 to output mixers */
10624         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10625         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10626
10627         /* set up input amps for analog loopback */
10628         /* Amp Indices: DAC = 0, mixer = 1 */
10629         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10630         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10631         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10632         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10633         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10634         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10635
10636         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10637         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10638         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10639         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10640         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10641         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10642         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10643
10644         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10645         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10646         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10647         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10648         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10649         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10650         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10651
10652         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
10653         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10654
10655         /* FIXME: use matrix-type input source selection */
10656         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
10657         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10658         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10659         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10660         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10661         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10662
10663         /* set EAPD */
10664         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
10665         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
10666         { }
10667 };
10668
10669 /* add playback controls from the parsed DAC table */
10670 static int alc269_auto_create_multi_out_ctls(struct alc_spec *spec,
10671                                              const struct auto_pin_cfg *cfg)
10672 {
10673         hda_nid_t nid;
10674         int err;
10675
10676         spec->multiout.num_dacs = 1;    /* only use one dac */
10677         spec->multiout.dac_nids = spec->private_dac_nids;
10678         spec->multiout.dac_nids[0] = 2;
10679
10680         nid = cfg->line_out_pins[0];
10681         if (nid) {
10682                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
10683                                   "Front Playback Volume",
10684                                   HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT));
10685                 if (err < 0)
10686                         return err;
10687                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10688                                   "Front Playback Switch",
10689                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
10690                 if (err < 0)
10691                         return err;
10692         }
10693
10694         nid = cfg->speaker_pins[0];
10695         if (nid) {
10696                 if (!cfg->line_out_pins[0]) {
10697                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10698                                           "Speaker Playback Volume",
10699                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
10700                                                               HDA_OUTPUT));
10701                         if (err < 0)
10702                                 return err;
10703                 }
10704                 if (nid == 0x16) {
10705                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10706                                           "Speaker Playback Switch",
10707                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10708                                                               HDA_OUTPUT));
10709                         if (err < 0)
10710                                 return err;
10711                 } else {
10712                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10713                                           "Speaker Playback Switch",
10714                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10715                                                               HDA_OUTPUT));
10716                         if (err < 0)
10717                                 return err;
10718                 }
10719         }
10720         nid = cfg->hp_pins[0];
10721         if (nid) {
10722                 /* spec->multiout.hp_nid = 2; */
10723                 if (!cfg->line_out_pins[0] && !cfg->speaker_pins[0]) {
10724                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10725                                           "Headphone Playback Volume",
10726                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
10727                                                               HDA_OUTPUT));
10728                         if (err < 0)
10729                                 return err;
10730                 }
10731                 if (nid == 0x16) {
10732                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10733                                           "Headphone Playback Switch",
10734                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10735                                                               HDA_OUTPUT));
10736                         if (err < 0)
10737                                 return err;
10738                 } else {
10739                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10740                                           "Headphone Playback Switch",
10741                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10742                                                               HDA_OUTPUT));
10743                         if (err < 0)
10744                                 return err;
10745                 }
10746         }
10747         return 0;
10748 }
10749
10750 #define alc269_auto_create_analog_input_ctls \
10751         alc880_auto_create_analog_input_ctls
10752
10753 #ifdef CONFIG_SND_HDA_POWER_SAVE
10754 #define alc269_loopbacks        alc880_loopbacks
10755 #endif
10756
10757 /* pcm configuration: identiacal with ALC880 */
10758 #define alc269_pcm_analog_playback      alc880_pcm_analog_playback
10759 #define alc269_pcm_analog_capture       alc880_pcm_analog_capture
10760 #define alc269_pcm_digital_playback     alc880_pcm_digital_playback
10761 #define alc269_pcm_digital_capture      alc880_pcm_digital_capture
10762
10763 /*
10764  * BIOS auto configuration
10765  */
10766 static int alc269_parse_auto_config(struct hda_codec *codec)
10767 {
10768         struct alc_spec *spec = codec->spec;
10769         int err;
10770         static hda_nid_t alc269_ignore[] = { 0x1d, 0 };
10771
10772         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
10773                                            alc269_ignore);
10774         if (err < 0)
10775                 return err;
10776
10777         err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
10778         if (err < 0)
10779                 return err;
10780         err = alc269_auto_create_analog_input_ctls(spec, &spec->autocfg);
10781         if (err < 0)
10782                 return err;
10783
10784         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
10785
10786         if (spec->autocfg.dig_out_pin)
10787                 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;
10788
10789         if (spec->kctl_alloc)
10790                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
10791
10792         spec->init_verbs[spec->num_init_verbs++] = alc269_init_verbs;
10793         spec->num_mux_defs = 1;
10794         spec->input_mux = &spec->private_imux;
10795
10796         err = alc_auto_add_mic_boost(codec);
10797         if (err < 0)
10798                 return err;
10799
10800         return 1;
10801 }
10802
10803 #define alc269_auto_init_multi_out      alc882_auto_init_multi_out
10804 #define alc269_auto_init_hp_out         alc882_auto_init_hp_out
10805 #define alc269_auto_init_analog_input   alc882_auto_init_analog_input
10806
10807
10808 /* init callback for auto-configuration model -- overriding the default init */
10809 static void alc269_auto_init(struct hda_codec *codec)
10810 {
10811         struct alc_spec *spec = codec->spec;
10812         alc269_auto_init_multi_out(codec);
10813         alc269_auto_init_hp_out(codec);
10814         alc269_auto_init_analog_input(codec);
10815         if (spec->unsol_event)
10816                 alc_sku_automute(codec);
10817 }
10818
10819 /*
10820  * configuration and preset
10821  */
10822 static const char *alc269_models[ALC269_MODEL_LAST] = {
10823         [ALC269_BASIC]          = "basic",
10824 };
10825
10826 static struct snd_pci_quirk alc269_cfg_tbl[] = {
10827         {}
10828 };
10829
10830 static struct alc_config_preset alc269_presets[] = {
10831         [ALC269_BASIC] = {
10832                 .mixers = { alc269_base_mixer },
10833                 .init_verbs = { alc269_init_verbs },
10834                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
10835                 .dac_nids = alc269_dac_nids,
10836                 .hp_nid = 0x03,
10837                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
10838                 .channel_mode = alc269_modes,
10839                 .input_mux = &alc269_capture_source,
10840         },
10841 };
10842
10843 static int patch_alc269(struct hda_codec *codec)
10844 {
10845         struct alc_spec *spec;
10846         int board_config;
10847         int err;
10848
10849         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
10850         if (spec == NULL)
10851                 return -ENOMEM;
10852
10853         codec->spec = spec;
10854
10855         board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
10856                                                   alc269_models,
10857                                                   alc269_cfg_tbl);
10858
10859         if (board_config < 0) {
10860                 printk(KERN_INFO "hda_codec: Unknown model for ALC269, "
10861                        "trying auto-probe from BIOS...\n");
10862                 board_config = ALC269_AUTO;
10863         }
10864
10865         if (board_config == ALC269_AUTO) {
10866                 /* automatic parse from the BIOS config */
10867                 err = alc269_parse_auto_config(codec);
10868                 if (err < 0) {
10869                         alc_free(codec);
10870                         return err;
10871                 } else if (!err) {
10872                         printk(KERN_INFO
10873                                "hda_codec: Cannot set up configuration "
10874                                "from BIOS.  Using base mode...\n");
10875                         board_config = ALC269_BASIC;
10876                 }
10877         }
10878
10879         if (board_config != ALC269_AUTO)
10880                 setup_preset(spec, &alc269_presets[board_config]);
10881
10882         spec->stream_name_analog = "ALC269 Analog";
10883         spec->stream_analog_playback = &alc269_pcm_analog_playback;
10884         spec->stream_analog_capture = &alc269_pcm_analog_capture;
10885
10886         spec->stream_name_digital = "ALC269 Digital";
10887         spec->stream_digital_playback = &alc269_pcm_digital_playback;
10888         spec->stream_digital_capture = &alc269_pcm_digital_capture;
10889
10890         spec->adc_nids = alc269_adc_nids;
10891         spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
10892         spec->mixers[spec->num_mixers] = alc269_capture_mixer;
10893         spec->num_mixers++;
10894
10895         codec->patch_ops = alc_patch_ops;
10896         if (board_config == ALC269_AUTO)
10897                 spec->init_hook = alc269_auto_init;
10898 #ifdef CONFIG_SND_HDA_POWER_SAVE
10899         if (!spec->loopback.amplist)
10900                 spec->loopback.amplist = alc269_loopbacks;
10901 #endif
10902
10903         return 0;
10904 }
10905
10906 /*
10907  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
10908  */
10909
10910 /*
10911  * set the path ways for 2 channel output
10912  * need to set the codec line out and mic 1 pin widgets to inputs
10913  */
10914 static struct hda_verb alc861_threestack_ch2_init[] = {
10915         /* set pin widget 1Ah (line in) for input */
10916         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
10917         /* set pin widget 18h (mic1/2) for input, for mic also enable
10918          * the vref
10919          */
10920         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10921
10922         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
10923 #if 0
10924         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
10925         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
10926 #endif
10927         { } /* end */
10928 };
10929 /*
10930  * 6ch mode
10931  * need to set the codec line out and mic 1 pin widgets to outputs
10932  */
10933 static struct hda_verb alc861_threestack_ch6_init[] = {
10934         /* set pin widget 1Ah (line in) for output (Back Surround)*/
10935         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10936         /* set pin widget 18h (mic1) for output (CLFE)*/
10937         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10938
10939         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
10940         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
10941
10942         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
10943 #if 0
10944         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
10945         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
10946 #endif
10947         { } /* end */
10948 };
10949
10950 static struct hda_channel_mode alc861_threestack_modes[2] = {
10951         { 2, alc861_threestack_ch2_init },
10952         { 6, alc861_threestack_ch6_init },
10953 };
10954 /* Set mic1 as input and unmute the mixer */
10955 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
10956         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10957         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
10958         { } /* end */
10959 };
10960 /* Set mic1 as output and mute mixer */
10961 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
10962         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10963         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
10964         { } /* end */
10965 };
10966
10967 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
10968         { 2, alc861_uniwill_m31_ch2_init },
10969         { 4, alc861_uniwill_m31_ch4_init },
10970 };
10971
10972 /* Set mic1 and line-in as input and unmute the mixer */
10973 static struct hda_verb alc861_asus_ch2_init[] = {
10974         /* set pin widget 1Ah (line in) for input */
10975         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
10976         /* set pin widget 18h (mic1/2) for input, for mic also enable
10977          * the vref
10978          */
10979         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10980
10981         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
10982 #if 0
10983         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
10984         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
10985 #endif
10986         { } /* end */
10987 };
10988 /* Set mic1 nad line-in as output and mute mixer */
10989 static struct hda_verb alc861_asus_ch6_init[] = {
10990         /* set pin widget 1Ah (line in) for output (Back Surround)*/
10991         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10992         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
10993         /* set pin widget 18h (mic1) for output (CLFE)*/
10994         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10995         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
10996         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
10997         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
10998
10999         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
11000 #if 0
11001         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
11002         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
11003 #endif
11004         { } /* end */
11005 };
11006
11007 static struct hda_channel_mode alc861_asus_modes[2] = {
11008         { 2, alc861_asus_ch2_init },
11009         { 6, alc861_asus_ch6_init },
11010 };
11011
11012 /* patch-ALC861 */
11013
11014 static struct snd_kcontrol_new alc861_base_mixer[] = {
11015         /* output mixer control */
11016         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11017         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
11018         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
11019         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
11020         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
11021
11022         /*Input mixer control */
11023         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
11024            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
11025         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11026         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11027         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
11028         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
11029         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11030         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11031         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
11032         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
11033
11034         /* Capture mixer control */
11035         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11036         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11037         {
11038                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11039                 .name = "Capture Source",
11040                 .count = 1,
11041                 .info = alc_mux_enum_info,
11042                 .get = alc_mux_enum_get,
11043                 .put = alc_mux_enum_put,
11044         },
11045         { } /* end */
11046 };
11047
11048 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
11049         /* output mixer control */
11050         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11051         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
11052         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
11053         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
11054         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
11055
11056         /* Input mixer control */
11057         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
11058            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
11059         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11060         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11061         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
11062         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
11063         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11064         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11065         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
11066         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
11067
11068         /* Capture mixer control */
11069         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11070         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11071         {
11072                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11073                 .name = "Capture Source",
11074                 .count = 1,
11075                 .info = alc_mux_enum_info,
11076                 .get = alc_mux_enum_get,
11077                 .put = alc_mux_enum_put,
11078         },
11079         {
11080                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11081                 .name = "Channel Mode",
11082                 .info = alc_ch_mode_info,
11083                 .get = alc_ch_mode_get,
11084                 .put = alc_ch_mode_put,
11085                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
11086         },
11087         { } /* end */
11088 };
11089
11090 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
11091         /* output mixer control */
11092         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11093         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11094         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11095         
11096         /*Capture mixer control */
11097         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11098         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11099         {
11100                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11101                 .name = "Capture Source",
11102                 .count = 1,
11103                 .info = alc_mux_enum_info,
11104                 .get = alc_mux_enum_get,
11105                 .put = alc_mux_enum_put,
11106         },
11107
11108         { } /* end */
11109 };
11110
11111 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
11112         /* output mixer control */
11113         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11114         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
11115         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
11116         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
11117         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
11118
11119         /* Input mixer control */
11120         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
11121            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
11122         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11123         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11124         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
11125         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
11126         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11127         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11128         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
11129         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
11130
11131         /* Capture mixer control */
11132         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11133         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11134         {
11135                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11136                 .name = "Capture Source",
11137                 .count = 1,
11138                 .info = alc_mux_enum_info,
11139                 .get = alc_mux_enum_get,
11140                 .put = alc_mux_enum_put,
11141         },
11142         {
11143                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11144                 .name = "Channel Mode",
11145                 .info = alc_ch_mode_info,
11146                 .get = alc_ch_mode_get,
11147                 .put = alc_ch_mode_put,
11148                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
11149         },
11150         { } /* end */
11151 };
11152
11153 static struct snd_kcontrol_new alc861_asus_mixer[] = {
11154         /* output mixer control */
11155         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11156         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
11157         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
11158         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
11159         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
11160
11161         /* Input mixer control */
11162         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
11163         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11164         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11165         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11166         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
11167         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
11168         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11169         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11170         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
11171         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
11172
11173         /* Capture mixer control */
11174         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11175         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11176         {
11177                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11178                 .name = "Capture Source",
11179                 .count = 1,
11180                 .info = alc_mux_enum_info,
11181                 .get = alc_mux_enum_get,
11182                 .put = alc_mux_enum_put,
11183         },
11184         {
11185                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11186                 .name = "Channel Mode",
11187                 .info = alc_ch_mode_info,
11188                 .get = alc_ch_mode_get,
11189                 .put = alc_ch_mode_put,
11190                 .private_value = ARRAY_SIZE(alc861_asus_modes),
11191         },
11192         { }
11193 };
11194
11195 /* additional mixer */
11196 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
11197         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11198         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11199         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x23, 0x0, HDA_OUTPUT),
11200         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x23, 0x0, HDA_OUTPUT),
11201         { }
11202 };
11203
11204 /*
11205  * generic initialization of ADC, input mixers and output mixers
11206  */
11207 static struct hda_verb alc861_base_init_verbs[] = {
11208         /*
11209          * Unmute ADC0 and set the default input to mic-in
11210          */
11211         /* port-A for surround (rear panel) */
11212         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11213         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
11214         /* port-B for mic-in (rear panel) with vref */
11215         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11216         /* port-C for line-in (rear panel) */
11217         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11218         /* port-D for Front */
11219         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11220         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
11221         /* port-E for HP out (front panel) */
11222         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
11223         /* route front PCM to HP */
11224         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
11225         /* port-F for mic-in (front panel) with vref */
11226         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11227         /* port-G for CLFE (rear panel) */
11228         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11229         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
11230         /* port-H for side (rear panel) */
11231         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11232         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
11233         /* CD-in */
11234         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11235         /* route front mic to ADC1*/
11236         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11237         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11238         
11239         /* Unmute DAC0~3 & spdif out*/
11240         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11241         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11242         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11243         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11244         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11245         
11246         /* Unmute Mixer 14 (mic) 1c (Line in)*/
11247         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11248         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11249         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11250         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11251         
11252         /* Unmute Stereo Mixer 15 */
11253         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11254         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11255         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11256         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
11257
11258         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11259         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11260         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11261         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11262         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11263         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11264         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11265         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11266         /* hp used DAC 3 (Front) */
11267         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
11268         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11269
11270         { }
11271 };
11272
11273 static struct hda_verb alc861_threestack_init_verbs[] = {
11274         /*
11275          * Unmute ADC0 and set the default input to mic-in
11276          */
11277         /* port-A for surround (rear panel) */
11278         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11279         /* port-B for mic-in (rear panel) with vref */
11280         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11281         /* port-C for line-in (rear panel) */
11282         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11283         /* port-D for Front */
11284         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11285         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
11286         /* port-E for HP out (front panel) */
11287         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
11288         /* route front PCM to HP */
11289         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
11290         /* port-F for mic-in (front panel) with vref */
11291         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11292         /* port-G for CLFE (rear panel) */
11293         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11294         /* port-H for side (rear panel) */
11295         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11296         /* CD-in */
11297         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11298         /* route front mic to ADC1*/
11299         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11300         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11301         /* Unmute DAC0~3 & spdif out*/
11302         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11303         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11304         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11305         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11306         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11307         
11308         /* Unmute Mixer 14 (mic) 1c (Line in)*/
11309         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11310         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11311         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11312         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11313         
11314         /* Unmute Stereo Mixer 15 */
11315         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11316         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11317         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11318         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
11319
11320         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11321         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11322         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11323         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11324         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11325         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11326         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11327         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11328         /* hp used DAC 3 (Front) */
11329         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
11330         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11331         { }
11332 };
11333
11334 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
11335         /*
11336          * Unmute ADC0 and set the default input to mic-in
11337          */
11338         /* port-A for surround (rear panel) */
11339         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11340         /* port-B for mic-in (rear panel) with vref */
11341         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11342         /* port-C for line-in (rear panel) */
11343         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11344         /* port-D for Front */
11345         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11346         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
11347         /* port-E for HP out (front panel) */
11348         /* this has to be set to VREF80 */
11349         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11350         /* route front PCM to HP */
11351         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
11352         /* port-F for mic-in (front panel) with vref */
11353         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11354         /* port-G for CLFE (rear panel) */
11355         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11356         /* port-H for side (rear panel) */
11357         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11358         /* CD-in */
11359         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11360         /* route front mic to ADC1*/
11361         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11362         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11363         /* Unmute DAC0~3 & spdif out*/
11364         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11365         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11366         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11367         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11368         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11369         
11370         /* Unmute Mixer 14 (mic) 1c (Line in)*/
11371         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11372         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11373         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11374         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11375         
11376         /* Unmute Stereo Mixer 15 */
11377         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11378         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11379         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11380         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
11381
11382         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11383         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11384         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11385         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11386         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11387         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11388         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11389         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11390         /* hp used DAC 3 (Front) */
11391         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
11392         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11393         { }
11394 };
11395
11396 static struct hda_verb alc861_asus_init_verbs[] = {
11397         /*
11398          * Unmute ADC0 and set the default input to mic-in
11399          */
11400         /* port-A for surround (rear panel)
11401          * according to codec#0 this is the HP jack
11402          */
11403         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
11404         /* route front PCM to HP */
11405         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
11406         /* port-B for mic-in (rear panel) with vref */
11407         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11408         /* port-C for line-in (rear panel) */
11409         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11410         /* port-D for Front */
11411         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11412         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
11413         /* port-E for HP out (front panel) */
11414         /* this has to be set to VREF80 */
11415         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11416         /* route front PCM to HP */
11417         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
11418         /* port-F for mic-in (front panel) with vref */
11419         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11420         /* port-G for CLFE (rear panel) */
11421         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11422         /* port-H for side (rear panel) */
11423         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11424         /* CD-in */
11425         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11426         /* route front mic to ADC1*/
11427         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11428         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11429         /* Unmute DAC0~3 & spdif out*/
11430         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11431         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11432         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11433         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11434         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11435         /* Unmute Mixer 14 (mic) 1c (Line in)*/
11436         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11437         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11438         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11439         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11440         
11441         /* Unmute Stereo Mixer 15 */
11442         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11443         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11444         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11445         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
11446
11447         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11448         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11449         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11450         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11451         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11452         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11453         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11454         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11455         /* hp used DAC 3 (Front) */
11456         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
11457         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11458         { }
11459 };
11460
11461 /* additional init verbs for ASUS laptops */
11462 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
11463         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
11464         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
11465         { }
11466 };
11467
11468 /*
11469  * generic initialization of ADC, input mixers and output mixers
11470  */
11471 static struct hda_verb alc861_auto_init_verbs[] = {
11472         /*
11473          * Unmute ADC0 and set the default input to mic-in
11474          */
11475         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
11476         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11477         
11478         /* Unmute DAC0~3 & spdif out*/
11479         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11480         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11481         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11482         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11483         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11484         
11485         /* Unmute Mixer 14 (mic) 1c (Line in)*/
11486         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11487         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11488         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11489         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11490         
11491         /* Unmute Stereo Mixer 15 */
11492         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11493         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11494         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11495         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
11496
11497         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11498         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11499         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11500         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11501         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11502         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11503         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11504         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11505
11506         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11507         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11508         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11509         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
11510         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11511         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11512         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11513         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
11514
11515         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
11516
11517         { }
11518 };
11519
11520 static struct hda_verb alc861_toshiba_init_verbs[] = {
11521         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11522
11523         { }
11524 };
11525
11526 /* toggle speaker-output according to the hp-jack state */
11527 static void alc861_toshiba_automute(struct hda_codec *codec)
11528 {
11529         unsigned int present;
11530
11531         present = snd_hda_codec_read(codec, 0x0f, 0,
11532                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11533         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
11534                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
11535         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
11536                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
11537 }
11538
11539 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
11540                                        unsigned int res)
11541 {
11542         if ((res >> 26) == ALC880_HP_EVENT)
11543                 alc861_toshiba_automute(codec);
11544 }
11545
11546 /* pcm configuration: identiacal with ALC880 */
11547 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
11548 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
11549 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
11550 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
11551
11552
11553 #define ALC861_DIGOUT_NID       0x07
11554
11555 static struct hda_channel_mode alc861_8ch_modes[1] = {
11556         { 8, NULL }
11557 };
11558
11559 static hda_nid_t alc861_dac_nids[4] = {
11560         /* front, surround, clfe, side */
11561         0x03, 0x06, 0x05, 0x04
11562 };
11563
11564 static hda_nid_t alc660_dac_nids[3] = {
11565         /* front, clfe, surround */
11566         0x03, 0x05, 0x06
11567 };
11568
11569 static hda_nid_t alc861_adc_nids[1] = {
11570         /* ADC0-2 */
11571         0x08,
11572 };
11573
11574 static struct hda_input_mux alc861_capture_source = {
11575         .num_items = 5,
11576         .items = {
11577                 { "Mic", 0x0 },
11578                 { "Front Mic", 0x3 },
11579                 { "Line", 0x1 },
11580                 { "CD", 0x4 },
11581                 { "Mixer", 0x5 },
11582         },
11583 };
11584
11585 /* fill in the dac_nids table from the parsed pin configuration */
11586 static int alc861_auto_fill_dac_nids(struct alc_spec *spec,
11587                                      const struct auto_pin_cfg *cfg)
11588 {
11589         int i;
11590         hda_nid_t nid;
11591
11592         spec->multiout.dac_nids = spec->private_dac_nids;
11593         for (i = 0; i < cfg->line_outs; i++) {
11594                 nid = cfg->line_out_pins[i];
11595                 if (nid) {
11596                         if (i >= ARRAY_SIZE(alc861_dac_nids))
11597                                 continue;
11598                         spec->multiout.dac_nids[i] = alc861_dac_nids[i];
11599                 }
11600         }
11601         spec->multiout.num_dacs = cfg->line_outs;
11602         return 0;
11603 }
11604
11605 /* add playback controls from the parsed DAC table */
11606 static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
11607                                              const struct auto_pin_cfg *cfg)
11608 {
11609         char name[32];
11610         static const char *chname[4] = {
11611                 "Front", "Surround", NULL /*CLFE*/, "Side"
11612         };
11613         hda_nid_t nid;
11614         int i, idx, err;
11615
11616         for (i = 0; i < cfg->line_outs; i++) {
11617                 nid = spec->multiout.dac_nids[i];
11618                 if (!nid)
11619                         continue;
11620                 if (nid == 0x05) {
11621                         /* Center/LFE */
11622                         err = add_control(spec, ALC_CTL_BIND_MUTE,
11623                                           "Center Playback Switch",
11624                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
11625                                                               HDA_OUTPUT));
11626                         if (err < 0)
11627                                 return err;
11628                         err = add_control(spec, ALC_CTL_BIND_MUTE,
11629                                           "LFE Playback Switch",
11630                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
11631                                                               HDA_OUTPUT));
11632                         if (err < 0)
11633                                 return err;
11634                 } else {
11635                         for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1;
11636                              idx++)
11637                                 if (nid == alc861_dac_nids[idx])
11638                                         break;
11639                         sprintf(name, "%s Playback Switch", chname[idx]);
11640                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
11641                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
11642                                                               HDA_OUTPUT));
11643                         if (err < 0)
11644                                 return err;
11645                 }
11646         }
11647         return 0;
11648 }
11649
11650 static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
11651 {
11652         int err;
11653         hda_nid_t nid;
11654
11655         if (!pin)
11656                 return 0;
11657
11658         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
11659                 nid = 0x03;
11660                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11661                                   "Headphone Playback Switch",
11662                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
11663                 if (err < 0)
11664                         return err;
11665                 spec->multiout.hp_nid = nid;
11666         }
11667         return 0;
11668 }
11669
11670 /* create playback/capture controls for input pins */
11671 static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec,
11672                                                 const struct auto_pin_cfg *cfg)
11673 {
11674         struct hda_input_mux *imux = &spec->private_imux;
11675         int i, err, idx, idx1;
11676
11677         for (i = 0; i < AUTO_PIN_LAST; i++) {
11678                 switch (cfg->input_pins[i]) {
11679                 case 0x0c:
11680                         idx1 = 1;
11681                         idx = 2;        /* Line In */
11682                         break;
11683                 case 0x0f:
11684                         idx1 = 2;
11685                         idx = 2;        /* Line In */
11686                         break;
11687                 case 0x0d:
11688                         idx1 = 0;
11689                         idx = 1;        /* Mic In */
11690                         break;
11691                 case 0x10:
11692                         idx1 = 3;
11693                         idx = 1;        /* Mic In */
11694                         break;
11695                 case 0x11:
11696                         idx1 = 4;
11697                         idx = 0;        /* CD */
11698                         break;
11699                 default:
11700                         continue;
11701                 }
11702
11703                 err = new_analog_input(spec, cfg->input_pins[i],
11704                                        auto_pin_cfg_labels[i], idx, 0x15);
11705                 if (err < 0)
11706                         return err;
11707
11708                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
11709                 imux->items[imux->num_items].index = idx1;
11710                 imux->num_items++;
11711         }
11712         return 0;
11713 }
11714
11715 static struct snd_kcontrol_new alc861_capture_mixer[] = {
11716         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11717         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11718
11719         {
11720                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11721                 /* The multiple "Capture Source" controls confuse alsamixer
11722                  * So call somewhat different..
11723                  */
11724                 /* .name = "Capture Source", */
11725                 .name = "Input Source",
11726                 .count = 1,
11727                 .info = alc_mux_enum_info,
11728                 .get = alc_mux_enum_get,
11729                 .put = alc_mux_enum_put,
11730         },
11731         { } /* end */
11732 };
11733
11734 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
11735                                               hda_nid_t nid,
11736                                               int pin_type, int dac_idx)
11737 {
11738         alc_set_pin_output(codec, nid, pin_type);
11739 }
11740
11741 static void alc861_auto_init_multi_out(struct hda_codec *codec)
11742 {
11743         struct alc_spec *spec = codec->spec;
11744         int i;
11745
11746         alc_subsystem_id(codec, 0x0e, 0x0f, 0x0b);
11747         for (i = 0; i < spec->autocfg.line_outs; i++) {
11748                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
11749                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
11750                 if (nid)
11751                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
11752                                                           spec->multiout.dac_nids[i]);
11753         }
11754 }
11755
11756 static void alc861_auto_init_hp_out(struct hda_codec *codec)
11757 {
11758         struct alc_spec *spec = codec->spec;
11759         hda_nid_t pin;
11760
11761         pin = spec->autocfg.hp_pins[0];
11762         if (pin) /* connect to front */
11763                 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
11764                                                   spec->multiout.dac_nids[0]);
11765         pin = spec->autocfg.speaker_pins[0];
11766         if (pin)
11767                 alc861_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
11768 }
11769
11770 static void alc861_auto_init_analog_input(struct hda_codec *codec)
11771 {
11772         struct alc_spec *spec = codec->spec;
11773         int i;
11774
11775         for (i = 0; i < AUTO_PIN_LAST; i++) {
11776                 hda_nid_t nid = spec->autocfg.input_pins[i];
11777                 if (nid >= 0x0c && nid <= 0x11) {
11778                         snd_hda_codec_write(codec, nid, 0,
11779                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
11780                                             i <= AUTO_PIN_FRONT_MIC ?
11781                                             PIN_VREF80 : PIN_IN);
11782                 }
11783         }
11784 }
11785
11786 /* parse the BIOS configuration and set up the alc_spec */
11787 /* return 1 if successful, 0 if the proper config is not found,
11788  * or a negative error code
11789  */
11790 static int alc861_parse_auto_config(struct hda_codec *codec)
11791 {
11792         struct alc_spec *spec = codec->spec;
11793         int err;
11794         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
11795
11796         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11797                                            alc861_ignore);
11798         if (err < 0)
11799                 return err;
11800         if (!spec->autocfg.line_outs)
11801                 return 0; /* can't find valid BIOS pin config */
11802
11803         err = alc861_auto_fill_dac_nids(spec, &spec->autocfg);
11804         if (err < 0)
11805                 return err;
11806         err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg);
11807         if (err < 0)
11808                 return err;
11809         err = alc861_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
11810         if (err < 0)
11811                 return err;
11812         err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg);
11813         if (err < 0)
11814                 return err;
11815
11816         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
11817
11818         if (spec->autocfg.dig_out_pin)
11819                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
11820
11821         if (spec->kctl_alloc)
11822                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
11823
11824         spec->init_verbs[spec->num_init_verbs++] = alc861_auto_init_verbs;
11825
11826         spec->num_mux_defs = 1;
11827         spec->input_mux = &spec->private_imux;
11828
11829         spec->adc_nids = alc861_adc_nids;
11830         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
11831         spec->mixers[spec->num_mixers] = alc861_capture_mixer;
11832         spec->num_mixers++;
11833
11834         return 1;
11835 }
11836
11837 /* additional initialization for auto-configuration model */
11838 static void alc861_auto_init(struct hda_codec *codec)
11839 {
11840         struct alc_spec *spec = codec->spec;
11841         alc861_auto_init_multi_out(codec);
11842         alc861_auto_init_hp_out(codec);
11843         alc861_auto_init_analog_input(codec);
11844         if (spec->unsol_event)
11845                 alc_sku_automute(codec);
11846 }
11847
11848 #ifdef CONFIG_SND_HDA_POWER_SAVE
11849 static struct hda_amp_list alc861_loopbacks[] = {
11850         { 0x15, HDA_INPUT, 0 },
11851         { 0x15, HDA_INPUT, 1 },
11852         { 0x15, HDA_INPUT, 2 },
11853         { 0x15, HDA_INPUT, 3 },
11854         { } /* end */
11855 };
11856 #endif
11857
11858
11859 /*
11860  * configuration and preset
11861  */
11862 static const char *alc861_models[ALC861_MODEL_LAST] = {
11863         [ALC861_3ST]            = "3stack",
11864         [ALC660_3ST]            = "3stack-660",
11865         [ALC861_3ST_DIG]        = "3stack-dig",
11866         [ALC861_6ST_DIG]        = "6stack-dig",
11867         [ALC861_UNIWILL_M31]    = "uniwill-m31",
11868         [ALC861_TOSHIBA]        = "toshiba",
11869         [ALC861_ASUS]           = "asus",
11870         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
11871         [ALC861_AUTO]           = "auto",
11872 };
11873
11874 static struct snd_pci_quirk alc861_cfg_tbl[] = {
11875         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
11876         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
11877         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
11878         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
11879         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
11880         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
11881         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
11882         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
11883          *        Any other models that need this preset?
11884          */
11885         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
11886         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
11887         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
11888         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
11889         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
11890         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
11891         /* FIXME: the below seems conflict */
11892         /* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
11893         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
11894         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
11895         {}
11896 };
11897
11898 static struct alc_config_preset alc861_presets[] = {
11899         [ALC861_3ST] = {
11900                 .mixers = { alc861_3ST_mixer },
11901                 .init_verbs = { alc861_threestack_init_verbs },
11902                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
11903                 .dac_nids = alc861_dac_nids,
11904                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
11905                 .channel_mode = alc861_threestack_modes,
11906                 .need_dac_fix = 1,
11907                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
11908                 .adc_nids = alc861_adc_nids,
11909                 .input_mux = &alc861_capture_source,
11910         },
11911         [ALC861_3ST_DIG] = {
11912                 .mixers = { alc861_base_mixer },
11913                 .init_verbs = { alc861_threestack_init_verbs },
11914                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
11915                 .dac_nids = alc861_dac_nids,
11916                 .dig_out_nid = ALC861_DIGOUT_NID,
11917                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
11918                 .channel_mode = alc861_threestack_modes,
11919                 .need_dac_fix = 1,
11920                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
11921                 .adc_nids = alc861_adc_nids,
11922                 .input_mux = &alc861_capture_source,
11923         },
11924         [ALC861_6ST_DIG] = {
11925                 .mixers = { alc861_base_mixer },
11926                 .init_verbs = { alc861_base_init_verbs },
11927                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
11928                 .dac_nids = alc861_dac_nids,
11929                 .dig_out_nid = ALC861_DIGOUT_NID,
11930                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
11931                 .channel_mode = alc861_8ch_modes,
11932                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
11933                 .adc_nids = alc861_adc_nids,
11934                 .input_mux = &alc861_capture_source,
11935         },
11936         [ALC660_3ST] = {
11937                 .mixers = { alc861_3ST_mixer },
11938                 .init_verbs = { alc861_threestack_init_verbs },
11939                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
11940                 .dac_nids = alc660_dac_nids,
11941                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
11942                 .channel_mode = alc861_threestack_modes,
11943                 .need_dac_fix = 1,
11944                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
11945                 .adc_nids = alc861_adc_nids,
11946                 .input_mux = &alc861_capture_source,
11947         },
11948         [ALC861_UNIWILL_M31] = {
11949                 .mixers = { alc861_uniwill_m31_mixer },
11950                 .init_verbs = { alc861_uniwill_m31_init_verbs },
11951                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
11952                 .dac_nids = alc861_dac_nids,
11953                 .dig_out_nid = ALC861_DIGOUT_NID,
11954                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
11955                 .channel_mode = alc861_uniwill_m31_modes,
11956                 .need_dac_fix = 1,
11957                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
11958                 .adc_nids = alc861_adc_nids,
11959                 .input_mux = &alc861_capture_source,
11960         },
11961         [ALC861_TOSHIBA] = {
11962                 .mixers = { alc861_toshiba_mixer },
11963                 .init_verbs = { alc861_base_init_verbs,
11964                                 alc861_toshiba_init_verbs },
11965                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
11966                 .dac_nids = alc861_dac_nids,
11967                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
11968                 .channel_mode = alc883_3ST_2ch_modes,
11969                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
11970                 .adc_nids = alc861_adc_nids,
11971                 .input_mux = &alc861_capture_source,
11972                 .unsol_event = alc861_toshiba_unsol_event,
11973                 .init_hook = alc861_toshiba_automute,
11974         },
11975         [ALC861_ASUS] = {
11976                 .mixers = { alc861_asus_mixer },
11977                 .init_verbs = { alc861_asus_init_verbs },
11978                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
11979                 .dac_nids = alc861_dac_nids,
11980                 .dig_out_nid = ALC861_DIGOUT_NID,
11981                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
11982                 .channel_mode = alc861_asus_modes,
11983                 .need_dac_fix = 1,
11984                 .hp_nid = 0x06,
11985                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
11986                 .adc_nids = alc861_adc_nids,
11987                 .input_mux = &alc861_capture_source,
11988         },
11989         [ALC861_ASUS_LAPTOP] = {
11990                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
11991                 .init_verbs = { alc861_asus_init_verbs,
11992                                 alc861_asus_laptop_init_verbs },
11993                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
11994                 .dac_nids = alc861_dac_nids,
11995                 .dig_out_nid = ALC861_DIGOUT_NID,
11996                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
11997                 .channel_mode = alc883_3ST_2ch_modes,
11998                 .need_dac_fix = 1,
11999                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12000                 .adc_nids = alc861_adc_nids,
12001                 .input_mux = &alc861_capture_source,
12002         },
12003 };
12004
12005
12006 static int patch_alc861(struct hda_codec *codec)
12007 {
12008         struct alc_spec *spec;
12009         int board_config;
12010         int err;
12011
12012         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
12013         if (spec == NULL)
12014                 return -ENOMEM;
12015
12016         codec->spec = spec;
12017
12018         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
12019                                                   alc861_models,
12020                                                   alc861_cfg_tbl);
12021
12022         if (board_config < 0) {
12023                 printk(KERN_INFO "hda_codec: Unknown model for ALC861, "
12024                        "trying auto-probe from BIOS...\n");
12025                 board_config = ALC861_AUTO;
12026         }
12027
12028         if (board_config == ALC861_AUTO) {
12029                 /* automatic parse from the BIOS config */
12030                 err = alc861_parse_auto_config(codec);
12031                 if (err < 0) {
12032                         alc_free(codec);
12033                         return err;
12034                 } else if (!err) {
12035                         printk(KERN_INFO
12036                                "hda_codec: Cannot set up configuration "
12037                                "from BIOS.  Using base mode...\n");
12038                    board_config = ALC861_3ST_DIG;
12039                 }
12040         }
12041
12042         if (board_config != ALC861_AUTO)
12043                 setup_preset(spec, &alc861_presets[board_config]);
12044
12045         spec->stream_name_analog = "ALC861 Analog";
12046         spec->stream_analog_playback = &alc861_pcm_analog_playback;
12047         spec->stream_analog_capture = &alc861_pcm_analog_capture;
12048
12049         spec->stream_name_digital = "ALC861 Digital";
12050         spec->stream_digital_playback = &alc861_pcm_digital_playback;
12051         spec->stream_digital_capture = &alc861_pcm_digital_capture;
12052
12053         spec->vmaster_nid = 0x03;
12054
12055         codec->patch_ops = alc_patch_ops;
12056         if (board_config == ALC861_AUTO)
12057                 spec->init_hook = alc861_auto_init;
12058 #ifdef CONFIG_SND_HDA_POWER_SAVE
12059         if (!spec->loopback.amplist)
12060                 spec->loopback.amplist = alc861_loopbacks;
12061 #endif
12062                 
12063         return 0;
12064 }
12065
12066 /*
12067  * ALC861-VD support
12068  *
12069  * Based on ALC882
12070  *
12071  * In addition, an independent DAC
12072  */
12073 #define ALC861VD_DIGOUT_NID     0x06
12074
12075 static hda_nid_t alc861vd_dac_nids[4] = {
12076         /* front, surr, clfe, side surr */
12077         0x02, 0x03, 0x04, 0x05
12078 };
12079
12080 /* dac_nids for ALC660vd are in a different order - according to
12081  * Realtek's driver.
12082  * This should probably tesult in a different mixer for 6stack models
12083  * of ALC660vd codecs, but for now there is only 3stack mixer
12084  * - and it is the same as in 861vd.
12085  * adc_nids in ALC660vd are (is) the same as in 861vd
12086  */
12087 static hda_nid_t alc660vd_dac_nids[3] = {
12088         /* front, rear, clfe, rear_surr */
12089         0x02, 0x04, 0x03
12090 };
12091
12092 static hda_nid_t alc861vd_adc_nids[1] = {
12093         /* ADC0 */
12094         0x09,
12095 };
12096
12097 static hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
12098
12099 /* input MUX */
12100 /* FIXME: should be a matrix-type input source selection */
12101 static struct hda_input_mux alc861vd_capture_source = {
12102         .num_items = 4,
12103         .items = {
12104                 { "Mic", 0x0 },
12105                 { "Front Mic", 0x1 },
12106                 { "Line", 0x2 },
12107                 { "CD", 0x4 },
12108         },
12109 };
12110
12111 static struct hda_input_mux alc861vd_dallas_capture_source = {
12112         .num_items = 2,
12113         .items = {
12114                 { "Ext Mic", 0x0 },
12115                 { "Int Mic", 0x1 },
12116         },
12117 };
12118
12119 static struct hda_input_mux alc861vd_hp_capture_source = {
12120         .num_items = 2,
12121         .items = {
12122                 { "Front Mic", 0x0 },
12123                 { "ATAPI Mic", 0x1 },
12124         },
12125 };
12126
12127 #define alc861vd_mux_enum_info alc_mux_enum_info
12128 #define alc861vd_mux_enum_get alc_mux_enum_get
12129 /* ALC861VD has the ALC882-type input selection (but has only one ADC) */
12130 #define alc861vd_mux_enum_put alc882_mux_enum_put
12131
12132 /*
12133  * 2ch mode
12134  */
12135 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
12136         { 2, NULL }
12137 };
12138
12139 /*
12140  * 6ch mode
12141  */
12142 static struct hda_verb alc861vd_6stack_ch6_init[] = {
12143         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12144         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12145         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12146         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12147         { } /* end */
12148 };
12149
12150 /*
12151  * 8ch mode
12152  */
12153 static struct hda_verb alc861vd_6stack_ch8_init[] = {
12154         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12155         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12156         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12157         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12158         { } /* end */
12159 };
12160
12161 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
12162         { 6, alc861vd_6stack_ch6_init },
12163         { 8, alc861vd_6stack_ch8_init },
12164 };
12165
12166 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
12167         {
12168                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12169                 .name = "Channel Mode",
12170                 .info = alc_ch_mode_info,
12171                 .get = alc_ch_mode_get,
12172                 .put = alc_ch_mode_put,
12173         },
12174         { } /* end */
12175 };
12176
12177 static struct snd_kcontrol_new alc861vd_capture_mixer[] = {
12178         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
12179         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
12180
12181         {
12182                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12183                 /* The multiple "Capture Source" controls confuse alsamixer
12184                  * So call somewhat different..
12185                  */
12186                 /* .name = "Capture Source", */
12187                 .name = "Input Source",
12188                 .count = 1,
12189                 .info = alc861vd_mux_enum_info,
12190                 .get = alc861vd_mux_enum_get,
12191                 .put = alc861vd_mux_enum_put,
12192         },
12193         { } /* end */
12194 };
12195
12196 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
12197  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
12198  */
12199 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
12200         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12201         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
12202
12203         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12204         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
12205
12206         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
12207                                 HDA_OUTPUT),
12208         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
12209                                 HDA_OUTPUT),
12210         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
12211         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
12212
12213         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
12214         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
12215
12216         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12217
12218         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12219         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12220         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12221
12222         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
12223         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12224         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12225
12226         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12227         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12228
12229         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
12230         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
12231
12232         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
12233         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
12234
12235         { } /* end */
12236 };
12237
12238 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
12239         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12240         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
12241
12242         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12243
12244         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12245         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12246         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12247
12248         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
12249         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12250         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12251
12252         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12253         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12254
12255         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
12256         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
12257
12258         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
12259         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
12260
12261         { } /* end */
12262 };
12263
12264 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
12265         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12266         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
12267         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12268
12269         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12270
12271         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12272         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12273         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12274
12275         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
12276         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12277         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12278
12279         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
12280         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
12281
12282         { } /* end */
12283 };
12284
12285 /* Pin assignment: Speaker=0x14, HP = 0x15,
12286  *                 Ext Mic=0x18, Int Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
12287  */
12288 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
12289         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12290         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
12291         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12292         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
12293         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
12294         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12295         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12296         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
12297         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12298         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12299         HDA_CODEC_VOLUME("PC Beep Volume", 0x0b, 0x05, HDA_INPUT),
12300         HDA_CODEC_MUTE("PC Beep Switch", 0x0b, 0x05, HDA_INPUT),
12301         { } /* end */
12302 };
12303
12304 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
12305  *                 Front Mic=0x18, ATAPI Mic = 0x19,
12306  */
12307 static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
12308         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12309         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
12310         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12311         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
12312         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12313         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12314         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12315         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12316         
12317         { } /* end */
12318 };
12319
12320 /*
12321  * generic initialization of ADC, input mixers and output mixers
12322  */
12323 static struct hda_verb alc861vd_volume_init_verbs[] = {
12324         /*
12325          * Unmute ADC0 and set the default input to mic-in
12326          */
12327         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
12328         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12329
12330         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
12331          * the analog-loopback mixer widget
12332          */
12333         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
12334         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12335         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12336         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12337         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12338         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
12339
12340         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
12341         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12342         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12343         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12344         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
12345
12346         /*
12347          * Set up output mixers (0x02 - 0x05)
12348          */
12349         /* set vol=0 to output mixers */
12350         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12351         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12352         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12353         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12354
12355         /* set up input amps for analog loopback */
12356         /* Amp Indices: DAC = 0, mixer = 1 */
12357         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12358         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12359         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12360         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12361         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12362         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12363         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12364         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12365
12366         { }
12367 };
12368
12369 /*
12370  * 3-stack pin configuration:
12371  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
12372  */
12373 static struct hda_verb alc861vd_3stack_init_verbs[] = {
12374         /*
12375          * Set pin mode and muting
12376          */
12377         /* set front pin widgets 0x14 for output */
12378         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12379         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12380         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
12381
12382         /* Mic (rear) pin: input vref at 80% */
12383         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12384         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12385         /* Front Mic pin: input vref at 80% */
12386         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12387         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12388         /* Line In pin: input */
12389         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12390         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12391         /* Line-2 In: Headphone output (output 0 - 0x0c) */
12392         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12393         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12394         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
12395         /* CD pin widget for input */
12396         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12397
12398         { }
12399 };
12400
12401 /*
12402  * 6-stack pin configuration:
12403  */
12404 static struct hda_verb alc861vd_6stack_init_verbs[] = {
12405         /*
12406          * Set pin mode and muting
12407          */
12408         /* set front pin widgets 0x14 for output */
12409         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12410         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12411         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
12412
12413         /* Rear Pin: output 1 (0x0d) */
12414         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12415         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12416         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12417         /* CLFE Pin: output 2 (0x0e) */
12418         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12419         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12420         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
12421         /* Side Pin: output 3 (0x0f) */
12422         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12423         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12424         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
12425
12426         /* Mic (rear) pin: input vref at 80% */
12427         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12428         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12429         /* Front Mic pin: input vref at 80% */
12430         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12431         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12432         /* Line In pin: input */
12433         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12434         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12435         /* Line-2 In: Headphone output (output 0 - 0x0c) */
12436         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12437         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12438         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
12439         /* CD pin widget for input */
12440         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12441
12442         { }
12443 };
12444
12445 static struct hda_verb alc861vd_eapd_verbs[] = {
12446         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
12447         { }
12448 };
12449
12450 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
12451         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12452         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12453         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
12454         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12455         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT}, 
12456         {}
12457 };
12458
12459 /* toggle speaker-output according to the hp-jack state */
12460 static void alc861vd_lenovo_hp_automute(struct hda_codec *codec)
12461 {
12462         unsigned int present;
12463         unsigned char bits;
12464
12465         present = snd_hda_codec_read(codec, 0x1b, 0,
12466                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12467         bits = present ? HDA_AMP_MUTE : 0;
12468         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
12469                                  HDA_AMP_MUTE, bits);
12470 }
12471
12472 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
12473 {
12474         unsigned int present;
12475         unsigned char bits;
12476
12477         present = snd_hda_codec_read(codec, 0x18, 0,
12478                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12479         bits = present ? HDA_AMP_MUTE : 0;
12480         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
12481                                  HDA_AMP_MUTE, bits);
12482 }
12483
12484 static void alc861vd_lenovo_automute(struct hda_codec *codec)
12485 {
12486         alc861vd_lenovo_hp_automute(codec);
12487         alc861vd_lenovo_mic_automute(codec);
12488 }
12489
12490 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
12491                                         unsigned int res)
12492 {
12493         switch (res >> 26) {
12494         case ALC880_HP_EVENT:
12495                 alc861vd_lenovo_hp_automute(codec);
12496                 break;
12497         case ALC880_MIC_EVENT:
12498                 alc861vd_lenovo_mic_automute(codec);
12499                 break;
12500         }
12501 }
12502
12503 static struct hda_verb alc861vd_dallas_verbs[] = {
12504         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12505         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12506         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12507         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12508
12509         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12510         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12511         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12512         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12513         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12514         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12515         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12516         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12517         
12518         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12519         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12520         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12521         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12522         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12523         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12524         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12525         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12526
12527         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
12528         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12529         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
12530         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12531         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12532         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12533         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12534         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12535
12536         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12537         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12538         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12539         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
12540
12541         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12542         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},  
12543         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12544
12545         { } /* end */
12546 };
12547
12548 /* toggle speaker-output according to the hp-jack state */
12549 static void alc861vd_dallas_automute(struct hda_codec *codec)
12550 {
12551         unsigned int present;
12552
12553         present = snd_hda_codec_read(codec, 0x15, 0,
12554                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12555         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
12556                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
12557 }
12558
12559 static void alc861vd_dallas_unsol_event(struct hda_codec *codec, unsigned int res)
12560 {
12561         if ((res >> 26) == ALC880_HP_EVENT)
12562                 alc861vd_dallas_automute(codec);
12563 }
12564
12565 #ifdef CONFIG_SND_HDA_POWER_SAVE
12566 #define alc861vd_loopbacks      alc880_loopbacks
12567 #endif
12568
12569 /* pcm configuration: identiacal with ALC880 */
12570 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
12571 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
12572 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
12573 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
12574
12575 /*
12576  * configuration and preset
12577  */
12578 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
12579         [ALC660VD_3ST]          = "3stack-660",
12580         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
12581         [ALC861VD_3ST]          = "3stack",
12582         [ALC861VD_3ST_DIG]      = "3stack-digout",
12583         [ALC861VD_6ST_DIG]      = "6stack-digout",
12584         [ALC861VD_LENOVO]       = "lenovo",
12585         [ALC861VD_DALLAS]       = "dallas",
12586         [ALC861VD_HP]           = "hp",
12587         [ALC861VD_AUTO]         = "auto",
12588 };
12589
12590 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
12591         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
12592         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
12593         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
12594         SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),
12595         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
12596         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
12597         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
12598         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
12599         SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS),
12600         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
12601         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
12602         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
12603         SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo", ALC861VD_LENOVO),
12604         SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo 3000 C200", ALC861VD_LENOVO),
12605         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
12606         {}
12607 };
12608
12609 static struct alc_config_preset alc861vd_presets[] = {
12610         [ALC660VD_3ST] = {
12611                 .mixers = { alc861vd_3st_mixer },
12612                 .init_verbs = { alc861vd_volume_init_verbs,
12613                                  alc861vd_3stack_init_verbs },
12614                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
12615                 .dac_nids = alc660vd_dac_nids,
12616                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12617                 .channel_mode = alc861vd_3stack_2ch_modes,
12618                 .input_mux = &alc861vd_capture_source,
12619         },
12620         [ALC660VD_3ST_DIG] = {
12621                 .mixers = { alc861vd_3st_mixer },
12622                 .init_verbs = { alc861vd_volume_init_verbs,
12623                                  alc861vd_3stack_init_verbs },
12624                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
12625                 .dac_nids = alc660vd_dac_nids,
12626                 .dig_out_nid = ALC861VD_DIGOUT_NID,
12627                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12628                 .channel_mode = alc861vd_3stack_2ch_modes,
12629                 .input_mux = &alc861vd_capture_source,
12630         },
12631         [ALC861VD_3ST] = {
12632                 .mixers = { alc861vd_3st_mixer },
12633                 .init_verbs = { alc861vd_volume_init_verbs,
12634                                  alc861vd_3stack_init_verbs },
12635                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
12636                 .dac_nids = alc861vd_dac_nids,
12637                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12638                 .channel_mode = alc861vd_3stack_2ch_modes,
12639                 .input_mux = &alc861vd_capture_source,
12640         },
12641         [ALC861VD_3ST_DIG] = {
12642                 .mixers = { alc861vd_3st_mixer },
12643                 .init_verbs = { alc861vd_volume_init_verbs,
12644                                  alc861vd_3stack_init_verbs },
12645                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
12646                 .dac_nids = alc861vd_dac_nids,
12647                 .dig_out_nid = ALC861VD_DIGOUT_NID,
12648                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12649                 .channel_mode = alc861vd_3stack_2ch_modes,
12650                 .input_mux = &alc861vd_capture_source,
12651         },
12652         [ALC861VD_6ST_DIG] = {
12653                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
12654                 .init_verbs = { alc861vd_volume_init_verbs,
12655                                 alc861vd_6stack_init_verbs },
12656                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
12657                 .dac_nids = alc861vd_dac_nids,
12658                 .dig_out_nid = ALC861VD_DIGOUT_NID,
12659                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
12660                 .channel_mode = alc861vd_6stack_modes,
12661                 .input_mux = &alc861vd_capture_source,
12662         },
12663         [ALC861VD_LENOVO] = {
12664                 .mixers = { alc861vd_lenovo_mixer },
12665                 .init_verbs = { alc861vd_volume_init_verbs,
12666                                 alc861vd_3stack_init_verbs,
12667                                 alc861vd_eapd_verbs,
12668                                 alc861vd_lenovo_unsol_verbs },
12669                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
12670                 .dac_nids = alc660vd_dac_nids,
12671                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12672                 .channel_mode = alc861vd_3stack_2ch_modes,
12673                 .input_mux = &alc861vd_capture_source,
12674                 .unsol_event = alc861vd_lenovo_unsol_event,
12675                 .init_hook = alc861vd_lenovo_automute,
12676         },
12677         [ALC861VD_DALLAS] = {
12678                 .mixers = { alc861vd_dallas_mixer },
12679                 .init_verbs = { alc861vd_dallas_verbs },
12680                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
12681                 .dac_nids = alc861vd_dac_nids,
12682                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12683                 .channel_mode = alc861vd_3stack_2ch_modes,
12684                 .input_mux = &alc861vd_dallas_capture_source,
12685                 .unsol_event = alc861vd_dallas_unsol_event,
12686                 .init_hook = alc861vd_dallas_automute,
12687         },
12688         [ALC861VD_HP] = {
12689                 .mixers = { alc861vd_hp_mixer },
12690                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
12691                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
12692                 .dac_nids = alc861vd_dac_nids,
12693                 .dig_out_nid = ALC861VD_DIGOUT_NID,
12694                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12695                 .channel_mode = alc861vd_3stack_2ch_modes,
12696                 .input_mux = &alc861vd_hp_capture_source,
12697                 .unsol_event = alc861vd_dallas_unsol_event,
12698                 .init_hook = alc861vd_dallas_automute,
12699         },              
12700 };
12701
12702 /*
12703  * BIOS auto configuration
12704  */
12705 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
12706                                 hda_nid_t nid, int pin_type, int dac_idx)
12707 {
12708         alc_set_pin_output(codec, nid, pin_type);
12709 }
12710
12711 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
12712 {
12713         struct alc_spec *spec = codec->spec;
12714         int i;
12715
12716         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
12717         for (i = 0; i <= HDA_SIDE; i++) {
12718                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
12719                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
12720                 if (nid)
12721                         alc861vd_auto_set_output_and_unmute(codec, nid,
12722                                                             pin_type, i);
12723         }
12724 }
12725
12726
12727 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
12728 {
12729         struct alc_spec *spec = codec->spec;
12730         hda_nid_t pin;
12731
12732         pin = spec->autocfg.hp_pins[0];
12733         if (pin) /* connect to front and  use dac 0 */
12734                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
12735         pin = spec->autocfg.speaker_pins[0];
12736         if (pin)
12737                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
12738 }
12739
12740 #define alc861vd_is_input_pin(nid)      alc880_is_input_pin(nid)
12741 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
12742
12743 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
12744 {
12745         struct alc_spec *spec = codec->spec;
12746         int i;
12747
12748         for (i = 0; i < AUTO_PIN_LAST; i++) {
12749                 hda_nid_t nid = spec->autocfg.input_pins[i];
12750                 if (alc861vd_is_input_pin(nid)) {
12751                         snd_hda_codec_write(codec, nid, 0,
12752                                         AC_VERB_SET_PIN_WIDGET_CONTROL,
12753                                         i <= AUTO_PIN_FRONT_MIC ?
12754                                                         PIN_VREF80 : PIN_IN);
12755                         if (nid != ALC861VD_PIN_CD_NID)
12756                                 snd_hda_codec_write(codec, nid, 0,
12757                                                 AC_VERB_SET_AMP_GAIN_MUTE,
12758                                                 AMP_OUT_MUTE);
12759                 }
12760         }
12761 }
12762
12763 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
12764 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
12765
12766 /* add playback controls from the parsed DAC table */
12767 /* Based on ALC880 version. But ALC861VD has separate,
12768  * different NIDs for mute/unmute switch and volume control */
12769 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
12770                                              const struct auto_pin_cfg *cfg)
12771 {
12772         char name[32];
12773         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
12774         hda_nid_t nid_v, nid_s;
12775         int i, err;
12776
12777         for (i = 0; i < cfg->line_outs; i++) {
12778                 if (!spec->multiout.dac_nids[i])
12779                         continue;
12780                 nid_v = alc861vd_idx_to_mixer_vol(
12781                                 alc880_dac_to_idx(
12782                                         spec->multiout.dac_nids[i]));
12783                 nid_s = alc861vd_idx_to_mixer_switch(
12784                                 alc880_dac_to_idx(
12785                                         spec->multiout.dac_nids[i]));
12786
12787                 if (i == 2) {
12788                         /* Center/LFE */
12789                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12790                                           "Center Playback Volume",
12791                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
12792                                                               HDA_OUTPUT));
12793                         if (err < 0)
12794                                 return err;
12795                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12796                                           "LFE Playback Volume",
12797                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
12798                                                               HDA_OUTPUT));
12799                         if (err < 0)
12800                                 return err;
12801                         err = add_control(spec, ALC_CTL_BIND_MUTE,
12802                                           "Center Playback Switch",
12803                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
12804                                                               HDA_INPUT));
12805                         if (err < 0)
12806                                 return err;
12807                         err = add_control(spec, ALC_CTL_BIND_MUTE,
12808                                           "LFE Playback Switch",
12809                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
12810                                                               HDA_INPUT));
12811                         if (err < 0)
12812                                 return err;
12813                 } else {
12814                         sprintf(name, "%s Playback Volume", chname[i]);
12815                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
12816                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
12817                                                               HDA_OUTPUT));
12818                         if (err < 0)
12819                                 return err;
12820                         sprintf(name, "%s Playback Switch", chname[i]);
12821                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
12822                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
12823                                                               HDA_INPUT));
12824                         if (err < 0)
12825                                 return err;
12826                 }
12827         }
12828         return 0;
12829 }
12830
12831 /* add playback controls for speaker and HP outputs */
12832 /* Based on ALC880 version. But ALC861VD has separate,
12833  * different NIDs for mute/unmute switch and volume control */
12834 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
12835                                         hda_nid_t pin, const char *pfx)
12836 {
12837         hda_nid_t nid_v, nid_s;
12838         int err;
12839         char name[32];
12840
12841         if (!pin)
12842                 return 0;
12843
12844         if (alc880_is_fixed_pin(pin)) {
12845                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
12846                 /* specify the DAC as the extra output */
12847                 if (!spec->multiout.hp_nid)
12848                         spec->multiout.hp_nid = nid_v;
12849                 else
12850                         spec->multiout.extra_out_nid[0] = nid_v;
12851                 /* control HP volume/switch on the output mixer amp */
12852                 nid_v = alc861vd_idx_to_mixer_vol(
12853                                 alc880_fixed_pin_idx(pin));
12854                 nid_s = alc861vd_idx_to_mixer_switch(
12855                                 alc880_fixed_pin_idx(pin));
12856
12857                 sprintf(name, "%s Playback Volume", pfx);
12858                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
12859                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
12860                 if (err < 0)
12861                         return err;
12862                 sprintf(name, "%s Playback Switch", pfx);
12863                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
12864                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
12865                 if (err < 0)
12866                         return err;
12867         } else if (alc880_is_multi_pin(pin)) {
12868                 /* set manual connection */
12869                 /* we have only a switch on HP-out PIN */
12870                 sprintf(name, "%s Playback Switch", pfx);
12871                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
12872                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
12873                 if (err < 0)
12874                         return err;
12875         }
12876         return 0;
12877 }
12878
12879 /* parse the BIOS configuration and set up the alc_spec
12880  * return 1 if successful, 0 if the proper config is not found,
12881  * or a negative error code
12882  * Based on ALC880 version - had to change it to override
12883  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
12884 static int alc861vd_parse_auto_config(struct hda_codec *codec)
12885 {
12886         struct alc_spec *spec = codec->spec;
12887         int err;
12888         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
12889
12890         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
12891                                            alc861vd_ignore);
12892         if (err < 0)
12893                 return err;
12894         if (!spec->autocfg.line_outs)
12895                 return 0; /* can't find valid BIOS pin config */
12896
12897         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
12898         if (err < 0)
12899                 return err;
12900         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
12901         if (err < 0)
12902                 return err;
12903         err = alc861vd_auto_create_extra_out(spec,
12904                                              spec->autocfg.speaker_pins[0],
12905                                              "Speaker");
12906         if (err < 0)
12907                 return err;
12908         err = alc861vd_auto_create_extra_out(spec,
12909                                              spec->autocfg.hp_pins[0],
12910                                              "Headphone");
12911         if (err < 0)
12912                 return err;
12913         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
12914         if (err < 0)
12915                 return err;
12916
12917         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
12918
12919         if (spec->autocfg.dig_out_pin)
12920                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
12921
12922         if (spec->kctl_alloc)
12923                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
12924
12925         spec->init_verbs[spec->num_init_verbs++]
12926                 = alc861vd_volume_init_verbs;
12927
12928         spec->num_mux_defs = 1;
12929         spec->input_mux = &spec->private_imux;
12930
12931         err = alc_auto_add_mic_boost(codec);
12932         if (err < 0)
12933                 return err;
12934
12935         return 1;
12936 }
12937
12938 /* additional initialization for auto-configuration model */
12939 static void alc861vd_auto_init(struct hda_codec *codec)
12940 {
12941         struct alc_spec *spec = codec->spec;
12942         alc861vd_auto_init_multi_out(codec);
12943         alc861vd_auto_init_hp_out(codec);
12944         alc861vd_auto_init_analog_input(codec);
12945         if (spec->unsol_event)
12946                 alc_sku_automute(codec);
12947 }
12948
12949 static int patch_alc861vd(struct hda_codec *codec)
12950 {
12951         struct alc_spec *spec;
12952         int err, board_config;
12953
12954         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
12955         if (spec == NULL)
12956                 return -ENOMEM;
12957
12958         codec->spec = spec;
12959
12960         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
12961                                                   alc861vd_models,
12962                                                   alc861vd_cfg_tbl);
12963
12964         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
12965                 printk(KERN_INFO "hda_codec: Unknown model for ALC660VD/"
12966                         "ALC861VD, trying auto-probe from BIOS...\n");
12967                 board_config = ALC861VD_AUTO;
12968         }
12969
12970         if (board_config == ALC861VD_AUTO) {
12971                 /* automatic parse from the BIOS config */
12972                 err = alc861vd_parse_auto_config(codec);
12973                 if (err < 0) {
12974                         alc_free(codec);
12975                         return err;
12976                 } else if (!err) {
12977                         printk(KERN_INFO
12978                                "hda_codec: Cannot set up configuration "
12979                                "from BIOS.  Using base mode...\n");
12980                         board_config = ALC861VD_3ST;
12981                 }
12982         }
12983
12984         if (board_config != ALC861VD_AUTO)
12985                 setup_preset(spec, &alc861vd_presets[board_config]);
12986
12987         spec->stream_name_analog = "ALC861VD Analog";
12988         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
12989         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
12990
12991         spec->stream_name_digital = "ALC861VD Digital";
12992         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
12993         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
12994
12995         spec->adc_nids = alc861vd_adc_nids;
12996         spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
12997         spec->capsrc_nids = alc861vd_capsrc_nids;
12998
12999         spec->mixers[spec->num_mixers] = alc861vd_capture_mixer;
13000         spec->num_mixers++;
13001
13002         spec->vmaster_nid = 0x02;
13003
13004         codec->patch_ops = alc_patch_ops;
13005
13006         if (board_config == ALC861VD_AUTO)
13007                 spec->init_hook = alc861vd_auto_init;
13008 #ifdef CONFIG_SND_HDA_POWER_SAVE
13009         if (!spec->loopback.amplist)
13010                 spec->loopback.amplist = alc861vd_loopbacks;
13011 #endif
13012
13013         return 0;
13014 }
13015
13016 /*
13017  * ALC662 support
13018  *
13019  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
13020  * configuration.  Each pin widget can choose any input DACs and a mixer.
13021  * Each ADC is connected from a mixer of all inputs.  This makes possible
13022  * 6-channel independent captures.
13023  *
13024  * In addition, an independent DAC for the multi-playback (not used in this
13025  * driver yet).
13026  */
13027 #define ALC662_DIGOUT_NID       0x06
13028 #define ALC662_DIGIN_NID        0x0a
13029
13030 static hda_nid_t alc662_dac_nids[4] = {
13031         /* front, rear, clfe, rear_surr */
13032         0x02, 0x03, 0x04
13033 };
13034
13035 static hda_nid_t alc662_adc_nids[1] = {
13036         /* ADC1-2 */
13037         0x09,
13038 };
13039
13040 static hda_nid_t alc662_capsrc_nids[1] = { 0x22 };
13041
13042 /* input MUX */
13043 /* FIXME: should be a matrix-type input source selection */
13044 static struct hda_input_mux alc662_capture_source = {
13045         .num_items = 4,
13046         .items = {
13047                 { "Mic", 0x0 },
13048                 { "Front Mic", 0x1 },
13049                 { "Line", 0x2 },
13050                 { "CD", 0x4 },
13051         },
13052 };
13053
13054 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
13055         .num_items = 2,
13056         .items = {
13057                 { "Mic", 0x1 },
13058                 { "Line", 0x2 },
13059         },
13060 };
13061
13062 static struct hda_input_mux alc662_eeepc_capture_source = {
13063         .num_items = 2,
13064         .items = {
13065                 { "i-Mic", 0x1 },
13066                 { "e-Mic", 0x0 },
13067         },
13068 };
13069
13070 #define alc662_mux_enum_info alc_mux_enum_info
13071 #define alc662_mux_enum_get alc_mux_enum_get
13072 #define alc662_mux_enum_put alc882_mux_enum_put
13073
13074 /*
13075  * 2ch mode
13076  */
13077 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
13078         { 2, NULL }
13079 };
13080
13081 /*
13082  * 2ch mode
13083  */
13084 static struct hda_verb alc662_3ST_ch2_init[] = {
13085         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
13086         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
13087         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
13088         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
13089         { } /* end */
13090 };
13091
13092 /*
13093  * 6ch mode
13094  */
13095 static struct hda_verb alc662_3ST_ch6_init[] = {
13096         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13097         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
13098         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
13099         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13100         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
13101         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
13102         { } /* end */
13103 };
13104
13105 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
13106         { 2, alc662_3ST_ch2_init },
13107         { 6, alc662_3ST_ch6_init },
13108 };
13109
13110 /*
13111  * 2ch mode
13112  */
13113 static struct hda_verb alc662_sixstack_ch6_init[] = {
13114         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13115         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13116         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13117         { } /* end */
13118 };
13119
13120 /*
13121  * 6ch mode
13122  */
13123 static struct hda_verb alc662_sixstack_ch8_init[] = {
13124         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13125         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13126         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13127         { } /* end */
13128 };
13129
13130 static struct hda_channel_mode alc662_5stack_modes[2] = {
13131         { 2, alc662_sixstack_ch6_init },
13132         { 6, alc662_sixstack_ch8_init },
13133 };
13134
13135 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
13136  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
13137  */
13138
13139 static struct snd_kcontrol_new alc662_base_mixer[] = {
13140         /* output mixer control */
13141         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
13142         HDA_CODEC_MUTE("Front Playback Switch", 0x02, 0x0, HDA_OUTPUT),
13143         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
13144         HDA_CODEC_MUTE("Surround Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13145         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
13146         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
13147         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
13148         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
13149         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13150
13151         /*Input mixer control */
13152         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
13153         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
13154         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
13155         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
13156         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
13157         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
13158         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
13159         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
13160         { } /* end */
13161 };
13162
13163 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
13164         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13165         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
13166         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13167         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13168         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13169         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13170         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13171         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13172         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13173         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13174         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13175         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
13176         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
13177         { } /* end */
13178 };
13179
13180 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
13181         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13182         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
13183         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13184         HDA_BIND_MUTE("Surround Playback Switch", 0x03, 2, HDA_INPUT),
13185         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
13186         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
13187         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
13188         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
13189         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13190         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13191         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13192         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13193         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13194         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13195         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13196         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13197         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13198         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
13199         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
13200         { } /* end */
13201 };
13202
13203 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
13204         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13205         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
13206         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13207         HDA_BIND_MUTE("Speaker Playback Switch", 0x03, 2, HDA_INPUT),
13208         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13209         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13210         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13211         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13212         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13213         { } /* end */
13214 };
13215
13216 static struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
13217         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13218
13219         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13220         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13221
13222         HDA_CODEC_VOLUME("e-Mic Boost", 0x18, 0, HDA_INPUT),
13223         HDA_CODEC_VOLUME("e-Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13224         HDA_CODEC_MUTE("e-Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13225
13226         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
13227         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13228         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13229         { } /* end */
13230 };
13231
13232 static struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
13233         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13234         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13235         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13236         HDA_BIND_MUTE("Surround Playback Switch", 0x03, 2, HDA_INPUT),
13237         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
13238         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
13239         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
13240         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
13241         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13242         HDA_BIND_MUTE("MuteCtrl Playback Switch", 0x0c, 2, HDA_INPUT),
13243         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13244         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13245         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13246         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13247         { } /* end */
13248 };
13249
13250 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
13251         {
13252                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13253                 .name = "Channel Mode",
13254                 .info = alc_ch_mode_info,
13255                 .get = alc_ch_mode_get,
13256                 .put = alc_ch_mode_put,
13257         },
13258         { } /* end */
13259 };
13260
13261 static struct hda_verb alc662_init_verbs[] = {
13262         /* ADC: mute amp left and right */
13263         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13264         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
13265         /* Front mixer: unmute input/output amp left and right (volume = 0) */
13266
13267         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13268         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13269         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13270         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13271         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
13272
13273         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13274         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13275         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13276         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13277         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13278         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13279
13280         /* Front Pin: output 0 (0x0c) */
13281         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13282         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13283
13284         /* Rear Pin: output 1 (0x0d) */
13285         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13286         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13287
13288         /* CLFE Pin: output 2 (0x0e) */
13289         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13290         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13291
13292         /* Mic (rear) pin: input vref at 80% */
13293         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13294         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13295         /* Front Mic pin: input vref at 80% */
13296         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13297         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13298         /* Line In pin: input */
13299         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13300         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13301         /* Line-2 In: Headphone output (output 0 - 0x0c) */
13302         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13303         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13304         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
13305         /* CD pin widget for input */
13306         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13307
13308         /* FIXME: use matrix-type input source selection */
13309         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
13310         /* Input mixer */
13311         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13312         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13313         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13314         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
13315
13316         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13317         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13318         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13319         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
13320         { }
13321 };
13322
13323 static struct hda_verb alc662_sue_init_verbs[] = {
13324         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
13325         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
13326         {}
13327 };
13328
13329 static struct hda_verb alc662_eeepc_sue_init_verbs[] = {
13330         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
13331         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13332         {}
13333 };
13334
13335 /* Set Unsolicited Event*/
13336 static struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
13337         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13338         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13339         {}
13340 };
13341
13342 /*
13343  * generic initialization of ADC, input mixers and output mixers
13344  */
13345 static struct hda_verb alc662_auto_init_verbs[] = {
13346         /*
13347          * Unmute ADC and set the default input to mic-in
13348          */
13349         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
13350         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13351
13352         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
13353          * mixer widget
13354          * Note: PASD motherboards uses the Line In 2 as the input for front
13355          * panel mic (mic 2)
13356          */
13357         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
13358         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13359         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13360         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13361         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13362         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
13363
13364         /*
13365          * Set up output mixers (0x0c - 0x0f)
13366          */
13367         /* set vol=0 to output mixers */
13368         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13369         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13370         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13371
13372         /* set up input amps for analog loopback */
13373         /* Amp Indices: DAC = 0, mixer = 1 */
13374         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13375         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13376         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13377         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13378         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13379         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13380
13381
13382         /* FIXME: use matrix-type input source selection */
13383         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
13384         /* Input mixer */
13385         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13386         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13387         { }
13388 };
13389
13390 /* capture mixer elements */
13391 static struct snd_kcontrol_new alc662_capture_mixer[] = {
13392         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
13393         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
13394         {
13395                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13396                 /* The multiple "Capture Source" controls confuse alsamixer
13397                  * So call somewhat different..
13398                  */
13399                 /* .name = "Capture Source", */
13400                 .name = "Input Source",
13401                 .count = 1,
13402                 .info = alc662_mux_enum_info,
13403                 .get = alc662_mux_enum_get,
13404                 .put = alc662_mux_enum_put,
13405         },
13406         { } /* end */
13407 };
13408
13409 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
13410 {
13411         unsigned int present;
13412         unsigned char bits;
13413
13414         present = snd_hda_codec_read(codec, 0x14, 0,
13415                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13416         bits = present ? HDA_AMP_MUTE : 0;
13417         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
13418                                  HDA_AMP_MUTE, bits);
13419 }
13420
13421 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
13422 {
13423         unsigned int present;
13424         unsigned char bits;
13425
13426         present = snd_hda_codec_read(codec, 0x1b, 0,
13427                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13428         bits = present ? HDA_AMP_MUTE : 0;
13429         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
13430                                  HDA_AMP_MUTE, bits);
13431         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
13432                                  HDA_AMP_MUTE, bits);
13433 }
13434
13435 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
13436                                            unsigned int res)
13437 {
13438         if ((res >> 26) == ALC880_HP_EVENT)
13439                 alc662_lenovo_101e_all_automute(codec);
13440         if ((res >> 26) == ALC880_FRONT_EVENT)
13441                 alc662_lenovo_101e_ispeaker_automute(codec);
13442 }
13443
13444 static void alc662_eeepc_mic_automute(struct hda_codec *codec)
13445 {
13446         unsigned int present;
13447
13448         present = snd_hda_codec_read(codec, 0x18, 0,
13449                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13450         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13451                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
13452         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13453                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
13454         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13455                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
13456         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13457                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
13458 }
13459
13460 /* unsolicited event for HP jack sensing */
13461 static void alc662_eeepc_unsol_event(struct hda_codec *codec,
13462                                      unsigned int res)
13463 {
13464         if ((res >> 26) == ALC880_HP_EVENT)
13465                 alc262_hippo1_automute( codec );
13466
13467         if ((res >> 26) == ALC880_MIC_EVENT)
13468                 alc662_eeepc_mic_automute(codec);
13469 }
13470
13471 static void alc662_eeepc_inithook(struct hda_codec *codec)
13472 {
13473         alc262_hippo1_automute( codec );
13474         alc662_eeepc_mic_automute(codec);
13475 }
13476
13477 static void alc662_eeepc_ep20_automute(struct hda_codec *codec)
13478 {
13479         unsigned int mute;
13480         unsigned int present;
13481
13482         snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
13483         present = snd_hda_codec_read(codec, 0x14, 0,
13484                                      AC_VERB_GET_PIN_SENSE, 0);
13485         present = (present & 0x80000000) != 0;
13486         if (present) {
13487                 /* mute internal speaker */
13488                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
13489                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
13490         } else {
13491                 /* unmute internal speaker if necessary */
13492                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
13493                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
13494                                          HDA_AMP_MUTE, mute);
13495         }
13496 }
13497
13498 /* unsolicited event for HP jack sensing */
13499 static void alc662_eeepc_ep20_unsol_event(struct hda_codec *codec,
13500                                           unsigned int res)
13501 {
13502         if ((res >> 26) == ALC880_HP_EVENT)
13503                 alc662_eeepc_ep20_automute(codec);
13504 }
13505
13506 static void alc662_eeepc_ep20_inithook(struct hda_codec *codec)
13507 {
13508         alc662_eeepc_ep20_automute(codec);
13509 }
13510
13511 #ifdef CONFIG_SND_HDA_POWER_SAVE
13512 #define alc662_loopbacks        alc880_loopbacks
13513 #endif
13514
13515
13516 /* pcm configuration: identiacal with ALC880 */
13517 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
13518 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
13519 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
13520 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
13521
13522 /*
13523  * configuration and preset
13524  */
13525 static const char *alc662_models[ALC662_MODEL_LAST] = {
13526         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
13527         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
13528         [ALC662_3ST_6ch]        = "3stack-6ch",
13529         [ALC662_5ST_DIG]        = "6stack-dig",
13530         [ALC662_LENOVO_101E]    = "lenovo-101e",
13531         [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
13532         [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
13533         [ALC662_AUTO]           = "auto",
13534 };
13535
13536 static struct snd_pci_quirk alc662_cfg_tbl[] = {
13537         SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
13538         SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
13539         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
13540         {}
13541 };
13542
13543 static struct alc_config_preset alc662_presets[] = {
13544         [ALC662_3ST_2ch_DIG] = {
13545                 .mixers = { alc662_3ST_2ch_mixer, alc662_capture_mixer },
13546                 .init_verbs = { alc662_init_verbs },
13547                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13548                 .dac_nids = alc662_dac_nids,
13549                 .dig_out_nid = ALC662_DIGOUT_NID,
13550                 .dig_in_nid = ALC662_DIGIN_NID,
13551                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
13552                 .channel_mode = alc662_3ST_2ch_modes,
13553                 .input_mux = &alc662_capture_source,
13554         },
13555         [ALC662_3ST_6ch_DIG] = {
13556                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer,
13557                             alc662_capture_mixer },
13558                 .init_verbs = { alc662_init_verbs },
13559                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13560                 .dac_nids = alc662_dac_nids,
13561                 .dig_out_nid = ALC662_DIGOUT_NID,
13562                 .dig_in_nid = ALC662_DIGIN_NID,
13563                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
13564                 .channel_mode = alc662_3ST_6ch_modes,
13565                 .need_dac_fix = 1,
13566                 .input_mux = &alc662_capture_source,
13567         },
13568         [ALC662_3ST_6ch] = {
13569                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer,
13570                             alc662_capture_mixer },
13571                 .init_verbs = { alc662_init_verbs },
13572                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13573                 .dac_nids = alc662_dac_nids,
13574                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
13575                 .channel_mode = alc662_3ST_6ch_modes,
13576                 .need_dac_fix = 1,
13577                 .input_mux = &alc662_capture_source,
13578         },
13579         [ALC662_5ST_DIG] = {
13580                 .mixers = { alc662_base_mixer, alc662_chmode_mixer,
13581                             alc662_capture_mixer },
13582                 .init_verbs = { alc662_init_verbs },
13583                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13584                 .dac_nids = alc662_dac_nids,
13585                 .dig_out_nid = ALC662_DIGOUT_NID,
13586                 .dig_in_nid = ALC662_DIGIN_NID,
13587                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
13588                 .channel_mode = alc662_5stack_modes,
13589                 .input_mux = &alc662_capture_source,
13590         },
13591         [ALC662_LENOVO_101E] = {
13592                 .mixers = { alc662_lenovo_101e_mixer, alc662_capture_mixer },
13593                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
13594                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13595                 .dac_nids = alc662_dac_nids,
13596                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
13597                 .channel_mode = alc662_3ST_2ch_modes,
13598                 .input_mux = &alc662_lenovo_101e_capture_source,
13599                 .unsol_event = alc662_lenovo_101e_unsol_event,
13600                 .init_hook = alc662_lenovo_101e_all_automute,
13601         },
13602         [ALC662_ASUS_EEEPC_P701] = {
13603                 .mixers = { alc662_eeepc_p701_mixer, alc662_capture_mixer },
13604                 .init_verbs = { alc662_init_verbs,
13605                                 alc662_eeepc_sue_init_verbs },
13606                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13607                 .dac_nids = alc662_dac_nids,
13608                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
13609                 .channel_mode = alc662_3ST_2ch_modes,
13610                 .input_mux = &alc662_eeepc_capture_source,
13611                 .unsol_event = alc662_eeepc_unsol_event,
13612                 .init_hook = alc662_eeepc_inithook,
13613         },
13614         [ALC662_ASUS_EEEPC_EP20] = {
13615                 .mixers = { alc662_eeepc_ep20_mixer, alc662_capture_mixer,
13616                             alc662_chmode_mixer },
13617                 .init_verbs = { alc662_init_verbs,
13618                                 alc662_eeepc_ep20_sue_init_verbs },
13619                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13620                 .dac_nids = alc662_dac_nids,
13621                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
13622                 .channel_mode = alc662_3ST_6ch_modes,
13623                 .input_mux = &alc662_lenovo_101e_capture_source,
13624                 .unsol_event = alc662_eeepc_ep20_unsol_event,
13625                 .init_hook = alc662_eeepc_ep20_inithook,
13626         },
13627
13628 };
13629
13630
13631 /*
13632  * BIOS auto configuration
13633  */
13634
13635 /* add playback controls from the parsed DAC table */
13636 static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec,
13637                                              const struct auto_pin_cfg *cfg)
13638 {
13639         char name[32];
13640         static const char *chname[4] = {
13641                 "Front", "Surround", NULL /*CLFE*/, "Side"
13642         };
13643         hda_nid_t nid;
13644         int i, err;
13645
13646         for (i = 0; i < cfg->line_outs; i++) {
13647                 if (!spec->multiout.dac_nids[i])
13648                         continue;
13649                 nid = alc880_idx_to_dac(i);
13650                 if (i == 2) {
13651                         /* Center/LFE */
13652                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
13653                                           "Center Playback Volume",
13654                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
13655                                                               HDA_OUTPUT));
13656                         if (err < 0)
13657                                 return err;
13658                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
13659                                           "LFE Playback Volume",
13660                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
13661                                                               HDA_OUTPUT));
13662                         if (err < 0)
13663                                 return err;
13664                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13665                                           "Center Playback Switch",
13666                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
13667                                                               HDA_INPUT));
13668                         if (err < 0)
13669                                 return err;
13670                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13671                                           "LFE Playback Switch",
13672                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
13673                                                               HDA_INPUT));
13674                         if (err < 0)
13675                                 return err;
13676                 } else {
13677                         sprintf(name, "%s Playback Volume", chname[i]);
13678                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
13679                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
13680                                                               HDA_OUTPUT));
13681                         if (err < 0)
13682                                 return err;
13683                         sprintf(name, "%s Playback Switch", chname[i]);
13684                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
13685                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
13686                                                               HDA_INPUT));
13687                         if (err < 0)
13688                                 return err;
13689                 }
13690         }
13691         return 0;
13692 }
13693
13694 /* add playback controls for speaker and HP outputs */
13695 static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
13696                                         const char *pfx)
13697 {
13698         hda_nid_t nid;
13699         int err;
13700         char name[32];
13701
13702         if (!pin)
13703                 return 0;
13704
13705         if (alc880_is_fixed_pin(pin)) {
13706                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
13707                 /* printk("DAC nid=%x\n",nid); */
13708                 /* specify the DAC as the extra output */
13709                 if (!spec->multiout.hp_nid)
13710                         spec->multiout.hp_nid = nid;
13711                 else
13712                         spec->multiout.extra_out_nid[0] = nid;
13713                 /* control HP volume/switch on the output mixer amp */
13714                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
13715                 sprintf(name, "%s Playback Volume", pfx);
13716                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
13717                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
13718                 if (err < 0)
13719                         return err;
13720                 sprintf(name, "%s Playback Switch", pfx);
13721                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
13722                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
13723                 if (err < 0)
13724                         return err;
13725         } else if (alc880_is_multi_pin(pin)) {
13726                 /* set manual connection */
13727                 /* we have only a switch on HP-out PIN */
13728                 sprintf(name, "%s Playback Switch", pfx);
13729                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
13730                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
13731                 if (err < 0)
13732                         return err;
13733         }
13734         return 0;
13735 }
13736
13737 /* create playback/capture controls for input pins */
13738 static int alc662_auto_create_analog_input_ctls(struct alc_spec *spec,
13739                                                 const struct auto_pin_cfg *cfg)
13740 {
13741         struct hda_input_mux *imux = &spec->private_imux;
13742         int i, err, idx;
13743
13744         for (i = 0; i < AUTO_PIN_LAST; i++) {
13745                 if (alc880_is_input_pin(cfg->input_pins[i])) {
13746                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
13747                         err = new_analog_input(spec, cfg->input_pins[i],
13748                                                auto_pin_cfg_labels[i],
13749                                                idx, 0x0b);
13750                         if (err < 0)
13751                                 return err;
13752                         imux->items[imux->num_items].label =
13753                                 auto_pin_cfg_labels[i];
13754                         imux->items[imux->num_items].index =
13755                                 alc880_input_pin_idx(cfg->input_pins[i]);
13756                         imux->num_items++;
13757                 }
13758         }
13759         return 0;
13760 }
13761
13762 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
13763                                               hda_nid_t nid, int pin_type,
13764                                               int dac_idx)
13765 {
13766         alc_set_pin_output(codec, nid, pin_type);
13767         /* need the manual connection? */
13768         if (alc880_is_multi_pin(nid)) {
13769                 struct alc_spec *spec = codec->spec;
13770                 int idx = alc880_multi_pin_idx(nid);
13771                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
13772                                     AC_VERB_SET_CONNECT_SEL,
13773                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
13774         }
13775 }
13776
13777 static void alc662_auto_init_multi_out(struct hda_codec *codec)
13778 {
13779         struct alc_spec *spec = codec->spec;
13780         int i;
13781
13782         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
13783         for (i = 0; i <= HDA_SIDE; i++) {
13784                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
13785                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
13786                 if (nid)
13787                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
13788                                                           i);
13789         }
13790 }
13791
13792 static void alc662_auto_init_hp_out(struct hda_codec *codec)
13793 {
13794         struct alc_spec *spec = codec->spec;
13795         hda_nid_t pin;
13796
13797         pin = spec->autocfg.hp_pins[0];
13798         if (pin) /* connect to front */
13799                 /* use dac 0 */
13800                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
13801         pin = spec->autocfg.speaker_pins[0];
13802         if (pin)
13803                 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
13804 }
13805
13806 #define alc662_is_input_pin(nid)        alc880_is_input_pin(nid)
13807 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
13808
13809 static void alc662_auto_init_analog_input(struct hda_codec *codec)
13810 {
13811         struct alc_spec *spec = codec->spec;
13812         int i;
13813
13814         for (i = 0; i < AUTO_PIN_LAST; i++) {
13815                 hda_nid_t nid = spec->autocfg.input_pins[i];
13816                 if (alc662_is_input_pin(nid)) {
13817                         snd_hda_codec_write(codec, nid, 0,
13818                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
13819                                             (i <= AUTO_PIN_FRONT_MIC ?
13820                                              PIN_VREF80 : PIN_IN));
13821                         if (nid != ALC662_PIN_CD_NID)
13822                                 snd_hda_codec_write(codec, nid, 0,
13823                                                     AC_VERB_SET_AMP_GAIN_MUTE,
13824                                                     AMP_OUT_MUTE);
13825                 }
13826         }
13827 }
13828
13829 static int alc662_parse_auto_config(struct hda_codec *codec)
13830 {
13831         struct alc_spec *spec = codec->spec;
13832         int err;
13833         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
13834
13835         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
13836                                            alc662_ignore);
13837         if (err < 0)
13838                 return err;
13839         if (!spec->autocfg.line_outs)
13840                 return 0; /* can't find valid BIOS pin config */
13841
13842         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
13843         if (err < 0)
13844                 return err;
13845         err = alc662_auto_create_multi_out_ctls(spec, &spec->autocfg);
13846         if (err < 0)
13847                 return err;
13848         err = alc662_auto_create_extra_out(spec,
13849                                            spec->autocfg.speaker_pins[0],
13850                                            "Speaker");
13851         if (err < 0)
13852                 return err;
13853         err = alc662_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
13854                                            "Headphone");
13855         if (err < 0)
13856                 return err;
13857         err = alc662_auto_create_analog_input_ctls(spec, &spec->autocfg);
13858         if (err < 0)
13859                 return err;
13860
13861         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
13862
13863         if (spec->autocfg.dig_out_pin)
13864                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
13865
13866         if (spec->kctl_alloc)
13867                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
13868
13869         spec->num_mux_defs = 1;
13870         spec->input_mux = &spec->private_imux;
13871         
13872         spec->init_verbs[spec->num_init_verbs++] = alc662_auto_init_verbs;
13873         spec->mixers[spec->num_mixers] = alc662_capture_mixer;
13874         spec->num_mixers++;
13875         return 1;
13876 }
13877
13878 /* additional initialization for auto-configuration model */
13879 static void alc662_auto_init(struct hda_codec *codec)
13880 {
13881         struct alc_spec *spec = codec->spec;
13882         alc662_auto_init_multi_out(codec);
13883         alc662_auto_init_hp_out(codec);
13884         alc662_auto_init_analog_input(codec);
13885         if (spec->unsol_event)
13886                 alc_sku_automute(codec);
13887 }
13888
13889 static int patch_alc662(struct hda_codec *codec)
13890 {
13891         struct alc_spec *spec;
13892         int err, board_config;
13893
13894         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13895         if (!spec)
13896                 return -ENOMEM;
13897
13898         codec->spec = spec;
13899
13900         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
13901                                                   alc662_models,
13902                                                   alc662_cfg_tbl);
13903         if (board_config < 0) {
13904                 printk(KERN_INFO "hda_codec: Unknown model for ALC662, "
13905                        "trying auto-probe from BIOS...\n");
13906                 board_config = ALC662_AUTO;
13907         }
13908
13909         if (board_config == ALC662_AUTO) {
13910                 /* automatic parse from the BIOS config */
13911                 err = alc662_parse_auto_config(codec);
13912                 if (err < 0) {
13913                         alc_free(codec);
13914                         return err;
13915                 } else if (!err) {
13916                         printk(KERN_INFO
13917                                "hda_codec: Cannot set up configuration "
13918                                "from BIOS.  Using base mode...\n");
13919                         board_config = ALC662_3ST_2ch_DIG;
13920                 }
13921         }
13922
13923         if (board_config != ALC662_AUTO)
13924                 setup_preset(spec, &alc662_presets[board_config]);
13925
13926         spec->stream_name_analog = "ALC662 Analog";
13927         spec->stream_analog_playback = &alc662_pcm_analog_playback;
13928         spec->stream_analog_capture = &alc662_pcm_analog_capture;
13929
13930         spec->stream_name_digital = "ALC662 Digital";
13931         spec->stream_digital_playback = &alc662_pcm_digital_playback;
13932         spec->stream_digital_capture = &alc662_pcm_digital_capture;
13933
13934         spec->adc_nids = alc662_adc_nids;
13935         spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
13936         spec->capsrc_nids = alc662_capsrc_nids;
13937
13938         spec->vmaster_nid = 0x02;
13939
13940         codec->patch_ops = alc_patch_ops;
13941         if (board_config == ALC662_AUTO)
13942                 spec->init_hook = alc662_auto_init;
13943 #ifdef CONFIG_SND_HDA_POWER_SAVE
13944         if (!spec->loopback.amplist)
13945                 spec->loopback.amplist = alc662_loopbacks;
13946 #endif
13947
13948         return 0;
13949 }
13950
13951 /*
13952  * patch entries
13953  */
13954 struct hda_codec_preset snd_hda_preset_realtek[] = {
13955         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
13956         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
13957         { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
13958         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
13959         { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
13960         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
13961           .patch = patch_alc861 },
13962         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
13963         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
13964         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
13965         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
13966           .patch = patch_alc883 },
13967         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
13968           .patch = patch_alc662 },
13969         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
13970         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
13971         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
13972         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
13973         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
13974         { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 },
13975         {} /* terminator */
13976 };