]> err.no Git - linux-2.6/blob - sound/pci/hda/patch_realtek.c
[ALSA] hda-codec - Add the support of Dell OEM laptops with ALC268
[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
34 #define ALC880_FRONT_EVENT              0x01
35 #define ALC880_DCVOL_EVENT              0x02
36 #define ALC880_HP_EVENT                 0x04
37 #define ALC880_MIC_EVENT                0x08
38
39 /* ALC880 board config type */
40 enum {
41         ALC880_3ST,
42         ALC880_3ST_DIG,
43         ALC880_5ST,
44         ALC880_5ST_DIG,
45         ALC880_W810,
46         ALC880_Z71V,
47         ALC880_6ST,
48         ALC880_6ST_DIG,
49         ALC880_F1734,
50         ALC880_ASUS,
51         ALC880_ASUS_DIG,
52         ALC880_ASUS_W1V,
53         ALC880_ASUS_DIG2,
54         ALC880_FUJITSU,
55         ALC880_UNIWILL_DIG,
56         ALC880_UNIWILL,
57         ALC880_UNIWILL_P53,
58         ALC880_CLEVO,
59         ALC880_TCL_S700,
60         ALC880_LG,
61         ALC880_LG_LW,
62 #ifdef CONFIG_SND_DEBUG
63         ALC880_TEST,
64 #endif
65         ALC880_AUTO,
66         ALC880_MODEL_LAST /* last tag */
67 };
68
69 /* ALC260 models */
70 enum {
71         ALC260_BASIC,
72         ALC260_HP,
73         ALC260_HP_3013,
74         ALC260_FUJITSU_S702X,
75         ALC260_ACER,
76         ALC260_WILL,
77         ALC260_REPLACER_672V,
78 #ifdef CONFIG_SND_DEBUG
79         ALC260_TEST,
80 #endif
81         ALC260_AUTO,
82         ALC260_MODEL_LAST /* last tag */
83 };
84
85 /* ALC262 models */
86 enum {
87         ALC262_BASIC,
88         ALC262_HIPPO,
89         ALC262_HIPPO_1,
90         ALC262_FUJITSU,
91         ALC262_HP_BPC,
92         ALC262_HP_BPC_D7000_WL,
93         ALC262_HP_BPC_D7000_WF,
94         ALC262_HP_TC_T5735,
95         ALC262_HP_RP5700,
96         ALC262_BENQ_ED8,
97         ALC262_SONY_ASSAMD,
98         ALC262_BENQ_T31,
99         ALC262_ULTRA,
100         ALC262_AUTO,
101         ALC262_MODEL_LAST /* last tag */
102 };
103
104 /* ALC268 models */
105 enum {
106         ALC268_3ST,
107         ALC268_TOSHIBA,
108         ALC268_ACER,
109         ALC268_DELL,
110 #ifdef CONFIG_SND_DEBUG
111         ALC268_TEST,
112 #endif
113         ALC268_AUTO,
114         ALC268_MODEL_LAST /* last tag */
115 };
116
117 /* ALC269 models */
118 enum {
119         ALC269_BASIC,
120         ALC269_AUTO,
121         ALC269_MODEL_LAST /* last tag */
122 };
123
124 /* ALC861 models */
125 enum {
126         ALC861_3ST,
127         ALC660_3ST,
128         ALC861_3ST_DIG,
129         ALC861_6ST_DIG,
130         ALC861_UNIWILL_M31,
131         ALC861_TOSHIBA,
132         ALC861_ASUS,
133         ALC861_ASUS_LAPTOP,
134         ALC861_AUTO,
135         ALC861_MODEL_LAST,
136 };
137
138 /* ALC861-VD models */
139 enum {
140         ALC660VD_3ST,
141         ALC660VD_3ST_DIG,
142         ALC861VD_3ST,
143         ALC861VD_3ST_DIG,
144         ALC861VD_6ST_DIG,
145         ALC861VD_LENOVO,
146         ALC861VD_DALLAS,
147         ALC861VD_HP,
148         ALC861VD_AUTO,
149         ALC861VD_MODEL_LAST,
150 };
151
152 /* ALC662 models */
153 enum {
154         ALC662_3ST_2ch_DIG,
155         ALC662_3ST_6ch_DIG,
156         ALC662_3ST_6ch,
157         ALC662_5ST_DIG,
158         ALC662_LENOVO_101E,
159         ALC662_ASUS_EEEPC_P701,
160         ALC662_ASUS_EEEPC_EP20,
161         ALC662_AUTO,
162         ALC662_MODEL_LAST,
163 };
164
165 /* ALC882 models */
166 enum {
167         ALC882_3ST_DIG,
168         ALC882_6ST_DIG,
169         ALC882_ARIMA,
170         ALC882_W2JC,
171         ALC882_TARGA,
172         ALC882_ASUS_A7J,
173         ALC882_ASUS_A7M,
174         ALC885_MACPRO,
175         ALC885_MBP3,
176         ALC885_IMAC24,
177         ALC882_AUTO,
178         ALC882_MODEL_LAST,
179 };
180
181 /* ALC883 models */
182 enum {
183         ALC883_3ST_2ch_DIG,
184         ALC883_3ST_6ch_DIG,
185         ALC883_3ST_6ch,
186         ALC883_6ST_DIG,
187         ALC883_TARGA_DIG,
188         ALC883_TARGA_2ch_DIG,
189         ALC883_ACER,
190         ALC883_ACER_ASPIRE,
191         ALC883_MEDION,
192         ALC883_MEDION_MD2,      
193         ALC883_LAPTOP_EAPD,
194         ALC883_LENOVO_101E_2ch,
195         ALC883_LENOVO_NB0763,
196         ALC888_LENOVO_MS7195_DIG,
197         ALC883_HAIER_W66,               
198         ALC888_6ST_HP,
199         ALC888_3ST_HP,
200         ALC888_6ST_DELL,
201         ALC883_MITAC,
202         ALC883_AUTO,
203         ALC883_MODEL_LAST,
204 };
205
206 /* for GPIO Poll */
207 #define GPIO_MASK       0x03
208
209 struct alc_spec {
210         /* codec parameterization */
211         struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
212         unsigned int num_mixers;
213
214         const struct hda_verb *init_verbs[5];   /* initialization verbs
215                                                  * don't forget NULL
216                                                  * termination!
217                                                  */
218         unsigned int num_init_verbs;
219
220         char *stream_name_analog;       /* analog PCM stream */
221         struct hda_pcm_stream *stream_analog_playback;
222         struct hda_pcm_stream *stream_analog_capture;
223
224         char *stream_name_digital;      /* digital PCM stream */
225         struct hda_pcm_stream *stream_digital_playback;
226         struct hda_pcm_stream *stream_digital_capture;
227
228         /* playback */
229         struct hda_multi_out multiout;  /* playback set-up
230                                          * max_channels, dacs must be set
231                                          * dig_out_nid and hp_nid are optional
232                                          */
233
234         /* capture */
235         unsigned int num_adc_nids;
236         hda_nid_t *adc_nids;
237         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
238
239         /* capture source */
240         unsigned int num_mux_defs;
241         const struct hda_input_mux *input_mux;
242         unsigned int cur_mux[3];
243
244         /* channel model */
245         const struct hda_channel_mode *channel_mode;
246         int num_channel_mode;
247         int need_dac_fix;
248
249         /* PCM information */
250         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
251
252         /* dynamic controls, init_verbs and input_mux */
253         struct auto_pin_cfg autocfg;
254         unsigned int num_kctl_alloc, num_kctl_used;
255         struct snd_kcontrol_new *kctl_alloc;
256         struct hda_input_mux private_imux;
257         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
258
259         /* hooks */
260         void (*init_hook)(struct hda_codec *codec);
261         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
262
263         /* for pin sensing */
264         unsigned int sense_updated: 1;
265         unsigned int jack_present: 1;
266
267         /* for virtual master */
268         hda_nid_t vmaster_nid;
269         u32 vmaster_tlv[4];
270 #ifdef CONFIG_SND_HDA_POWER_SAVE
271         struct hda_loopback_check loopback;
272 #endif
273 };
274
275 /*
276  * configuration template - to be copied to the spec instance
277  */
278 struct alc_config_preset {
279         struct snd_kcontrol_new *mixers[5]; /* should be identical size
280                                              * with spec
281                                              */
282         const struct hda_verb *init_verbs[5];
283         unsigned int num_dacs;
284         hda_nid_t *dac_nids;
285         hda_nid_t dig_out_nid;          /* optional */
286         hda_nid_t hp_nid;               /* optional */
287         unsigned int num_adc_nids;
288         hda_nid_t *adc_nids;
289         hda_nid_t dig_in_nid;
290         unsigned int num_channel_mode;
291         const struct hda_channel_mode *channel_mode;
292         int need_dac_fix;
293         unsigned int num_mux_defs;
294         const struct hda_input_mux *input_mux;
295         void (*unsol_event)(struct hda_codec *, unsigned int);
296         void (*init_hook)(struct hda_codec *);
297 #ifdef CONFIG_SND_HDA_POWER_SAVE
298         struct hda_amp_list *loopbacks;
299 #endif
300 };
301
302
303 /*
304  * input MUX handling
305  */
306 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
307                              struct snd_ctl_elem_info *uinfo)
308 {
309         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
310         struct alc_spec *spec = codec->spec;
311         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
312         if (mux_idx >= spec->num_mux_defs)
313                 mux_idx = 0;
314         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
315 }
316
317 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
318                             struct snd_ctl_elem_value *ucontrol)
319 {
320         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
321         struct alc_spec *spec = codec->spec;
322         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
323
324         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
325         return 0;
326 }
327
328 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
329                             struct snd_ctl_elem_value *ucontrol)
330 {
331         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
332         struct alc_spec *spec = codec->spec;
333         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
334         unsigned int mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
335         return snd_hda_input_mux_put(codec, &spec->input_mux[mux_idx], ucontrol,
336                                      spec->adc_nids[adc_idx],
337                                      &spec->cur_mux[adc_idx]);
338 }
339
340
341 /*
342  * channel mode setting
343  */
344 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
345                             struct snd_ctl_elem_info *uinfo)
346 {
347         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
348         struct alc_spec *spec = codec->spec;
349         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
350                                     spec->num_channel_mode);
351 }
352
353 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
354                            struct snd_ctl_elem_value *ucontrol)
355 {
356         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
357         struct alc_spec *spec = codec->spec;
358         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
359                                    spec->num_channel_mode,
360                                    spec->multiout.max_channels);
361 }
362
363 static int alc_ch_mode_put(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         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
369                                       spec->num_channel_mode,
370                                       &spec->multiout.max_channels);
371         if (err >= 0 && spec->need_dac_fix)
372                 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
373         return err;
374 }
375
376 /*
377  * Control the mode of pin widget settings via the mixer.  "pc" is used
378  * instead of "%" to avoid consequences of accidently treating the % as 
379  * being part of a format specifier.  Maximum allowed length of a value is
380  * 63 characters plus NULL terminator.
381  *
382  * Note: some retasking pin complexes seem to ignore requests for input
383  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
384  * are requested.  Therefore order this list so that this behaviour will not
385  * cause problems when mixer clients move through the enum sequentially.
386  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
387  * March 2006.
388  */
389 static char *alc_pin_mode_names[] = {
390         "Mic 50pc bias", "Mic 80pc bias",
391         "Line in", "Line out", "Headphone out",
392 };
393 static unsigned char alc_pin_mode_values[] = {
394         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
395 };
396 /* The control can present all 5 options, or it can limit the options based
397  * in the pin being assumed to be exclusively an input or an output pin.  In
398  * addition, "input" pins may or may not process the mic bias option
399  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
400  * accept requests for bias as of chip versions up to March 2006) and/or
401  * wiring in the computer.
402  */
403 #define ALC_PIN_DIR_IN              0x00
404 #define ALC_PIN_DIR_OUT             0x01
405 #define ALC_PIN_DIR_INOUT           0x02
406 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
407 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
408
409 /* Info about the pin modes supported by the different pin direction modes. 
410  * For each direction the minimum and maximum values are given.
411  */
412 static signed char alc_pin_mode_dir_info[5][2] = {
413         { 0, 2 },    /* ALC_PIN_DIR_IN */
414         { 3, 4 },    /* ALC_PIN_DIR_OUT */
415         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
416         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
417         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
418 };
419 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
420 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
421 #define alc_pin_mode_n_items(_dir) \
422         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
423
424 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
425                              struct snd_ctl_elem_info *uinfo)
426 {
427         unsigned int item_num = uinfo->value.enumerated.item;
428         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
429
430         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
431         uinfo->count = 1;
432         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
433
434         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
435                 item_num = alc_pin_mode_min(dir);
436         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
437         return 0;
438 }
439
440 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
441                             struct snd_ctl_elem_value *ucontrol)
442 {
443         unsigned int i;
444         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
445         hda_nid_t nid = kcontrol->private_value & 0xffff;
446         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
447         long *valp = ucontrol->value.integer.value;
448         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
449                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
450                                                  0x00);
451
452         /* Find enumerated value for current pinctl setting */
453         i = alc_pin_mode_min(dir);
454         while (alc_pin_mode_values[i] != pinctl && i <= alc_pin_mode_max(dir))
455                 i++;
456         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
457         return 0;
458 }
459
460 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
461                             struct snd_ctl_elem_value *ucontrol)
462 {
463         signed int change;
464         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
465         hda_nid_t nid = kcontrol->private_value & 0xffff;
466         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
467         long val = *ucontrol->value.integer.value;
468         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
469                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
470                                                  0x00);
471
472         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
473                 val = alc_pin_mode_min(dir);
474
475         change = pinctl != alc_pin_mode_values[val];
476         if (change) {
477                 /* Set pin mode to that requested */
478                 snd_hda_codec_write_cache(codec, nid, 0,
479                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
480                                           alc_pin_mode_values[val]);
481
482                 /* Also enable the retasking pin's input/output as required 
483                  * for the requested pin mode.  Enum values of 2 or less are
484                  * input modes.
485                  *
486                  * Dynamically switching the input/output buffers probably
487                  * reduces noise slightly (particularly on input) so we'll
488                  * do it.  However, having both input and output buffers
489                  * enabled simultaneously doesn't seem to be problematic if
490                  * this turns out to be necessary in the future.
491                  */
492                 if (val <= 2) {
493                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
494                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
495                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
496                                                  HDA_AMP_MUTE, 0);
497                 } else {
498                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
499                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
500                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
501                                                  HDA_AMP_MUTE, 0);
502                 }
503         }
504         return change;
505 }
506
507 #define ALC_PIN_MODE(xname, nid, dir) \
508         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
509           .info = alc_pin_mode_info, \
510           .get = alc_pin_mode_get, \
511           .put = alc_pin_mode_put, \
512           .private_value = nid | (dir<<16) }
513
514 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
515  * together using a mask with more than one bit set.  This control is
516  * currently used only by the ALC260 test model.  At this stage they are not
517  * needed for any "production" models.
518  */
519 #ifdef CONFIG_SND_DEBUG
520 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
521
522 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
523                              struct snd_ctl_elem_value *ucontrol)
524 {
525         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
526         hda_nid_t nid = kcontrol->private_value & 0xffff;
527         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
528         long *valp = ucontrol->value.integer.value;
529         unsigned int val = snd_hda_codec_read(codec, nid, 0,
530                                               AC_VERB_GET_GPIO_DATA, 0x00);
531
532         *valp = (val & mask) != 0;
533         return 0;
534 }
535 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
536                              struct snd_ctl_elem_value *ucontrol)
537 {
538         signed int change;
539         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
540         hda_nid_t nid = kcontrol->private_value & 0xffff;
541         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
542         long val = *ucontrol->value.integer.value;
543         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
544                                                     AC_VERB_GET_GPIO_DATA,
545                                                     0x00);
546
547         /* Set/unset the masked GPIO bit(s) as needed */
548         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
549         if (val == 0)
550                 gpio_data &= ~mask;
551         else
552                 gpio_data |= mask;
553         snd_hda_codec_write_cache(codec, nid, 0,
554                                   AC_VERB_SET_GPIO_DATA, gpio_data);
555
556         return change;
557 }
558 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
559         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
560           .info = alc_gpio_data_info, \
561           .get = alc_gpio_data_get, \
562           .put = alc_gpio_data_put, \
563           .private_value = nid | (mask<<16) }
564 #endif   /* CONFIG_SND_DEBUG */
565
566 /* A switch control to allow the enabling of the digital IO pins on the
567  * ALC260.  This is incredibly simplistic; the intention of this control is
568  * to provide something in the test model allowing digital outputs to be
569  * identified if present.  If models are found which can utilise these
570  * outputs a more complete mixer control can be devised for those models if
571  * necessary.
572  */
573 #ifdef CONFIG_SND_DEBUG
574 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
575
576 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
577                               struct snd_ctl_elem_value *ucontrol)
578 {
579         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
580         hda_nid_t nid = kcontrol->private_value & 0xffff;
581         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
582         long *valp = ucontrol->value.integer.value;
583         unsigned int val = snd_hda_codec_read(codec, nid, 0,
584                                               AC_VERB_GET_DIGI_CONVERT_1, 0x00);
585
586         *valp = (val & mask) != 0;
587         return 0;
588 }
589 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
590                               struct snd_ctl_elem_value *ucontrol)
591 {
592         signed int change;
593         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
594         hda_nid_t nid = kcontrol->private_value & 0xffff;
595         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
596         long val = *ucontrol->value.integer.value;
597         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
598                                                     AC_VERB_GET_DIGI_CONVERT_1,
599                                                     0x00);
600
601         /* Set/unset the masked control bit(s) as needed */
602         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
603         if (val==0)
604                 ctrl_data &= ~mask;
605         else
606                 ctrl_data |= mask;
607         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
608                                   ctrl_data);
609
610         return change;
611 }
612 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
613         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
614           .info = alc_spdif_ctrl_info, \
615           .get = alc_spdif_ctrl_get, \
616           .put = alc_spdif_ctrl_put, \
617           .private_value = nid | (mask<<16) }
618 #endif   /* CONFIG_SND_DEBUG */
619
620 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
621  * Again, this is only used in the ALC26x test models to help identify when
622  * the EAPD line must be asserted for features to work.
623  */
624 #ifdef CONFIG_SND_DEBUG
625 #define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
626
627 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
628                               struct snd_ctl_elem_value *ucontrol)
629 {
630         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
631         hda_nid_t nid = kcontrol->private_value & 0xffff;
632         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
633         long *valp = ucontrol->value.integer.value;
634         unsigned int val = snd_hda_codec_read(codec, nid, 0,
635                                               AC_VERB_GET_EAPD_BTLENABLE, 0x00);
636
637         *valp = (val & mask) != 0;
638         return 0;
639 }
640
641 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
642                               struct snd_ctl_elem_value *ucontrol)
643 {
644         int change;
645         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
646         hda_nid_t nid = kcontrol->private_value & 0xffff;
647         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
648         long val = *ucontrol->value.integer.value;
649         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
650                                                     AC_VERB_GET_EAPD_BTLENABLE,
651                                                     0x00);
652
653         /* Set/unset the masked control bit(s) as needed */
654         change = (!val ? 0 : mask) != (ctrl_data & mask);
655         if (!val)
656                 ctrl_data &= ~mask;
657         else
658                 ctrl_data |= mask;
659         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
660                                   ctrl_data);
661
662         return change;
663 }
664
665 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
666         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
667           .info = alc_eapd_ctrl_info, \
668           .get = alc_eapd_ctrl_get, \
669           .put = alc_eapd_ctrl_put, \
670           .private_value = nid | (mask<<16) }
671 #endif   /* CONFIG_SND_DEBUG */
672
673 /*
674  * set up from the preset table
675  */
676 static void setup_preset(struct alc_spec *spec,
677                          const struct alc_config_preset *preset)
678 {
679         int i;
680
681         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
682                 spec->mixers[spec->num_mixers++] = preset->mixers[i];
683         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
684              i++)
685                 spec->init_verbs[spec->num_init_verbs++] =
686                         preset->init_verbs[i];
687         
688         spec->channel_mode = preset->channel_mode;
689         spec->num_channel_mode = preset->num_channel_mode;
690         spec->need_dac_fix = preset->need_dac_fix;
691
692         spec->multiout.max_channels = spec->channel_mode[0].channels;
693
694         spec->multiout.num_dacs = preset->num_dacs;
695         spec->multiout.dac_nids = preset->dac_nids;
696         spec->multiout.dig_out_nid = preset->dig_out_nid;
697         spec->multiout.hp_nid = preset->hp_nid;
698         
699         spec->num_mux_defs = preset->num_mux_defs;
700         if (!spec->num_mux_defs)
701                 spec->num_mux_defs = 1;
702         spec->input_mux = preset->input_mux;
703
704         spec->num_adc_nids = preset->num_adc_nids;
705         spec->adc_nids = preset->adc_nids;
706         spec->dig_in_nid = preset->dig_in_nid;
707
708         spec->unsol_event = preset->unsol_event;
709         spec->init_hook = preset->init_hook;
710 #ifdef CONFIG_SND_HDA_POWER_SAVE
711         spec->loopback.amplist = preset->loopbacks;
712 #endif
713 }
714
715 /* Enable GPIO mask and set output */
716 static struct hda_verb alc_gpio1_init_verbs[] = {
717         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
718         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
719         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
720         { }
721 };
722
723 static struct hda_verb alc_gpio2_init_verbs[] = {
724         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
725         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
726         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
727         { }
728 };
729
730 static struct hda_verb alc_gpio3_init_verbs[] = {
731         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
732         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
733         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
734         { }
735 };
736
737 static void alc_sku_automute(struct hda_codec *codec)
738 {
739         struct alc_spec *spec = codec->spec;
740         unsigned int mute;
741         unsigned int present;
742         unsigned int hp_nid = spec->autocfg.hp_pins[0];
743         unsigned int sp_nid = spec->autocfg.speaker_pins[0];
744
745         /* need to execute and sync at first */
746         snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
747         present = snd_hda_codec_read(codec, hp_nid, 0,
748                                      AC_VERB_GET_PIN_SENSE, 0);
749         spec->jack_present = (present & 0x80000000) != 0;
750         if (spec->jack_present) {
751                 /* mute internal speaker */
752                 snd_hda_codec_amp_stereo(codec, sp_nid, HDA_OUTPUT, 0,
753                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
754         } else {
755                 /* unmute internal speaker if necessary */
756                 mute = snd_hda_codec_amp_read(codec, hp_nid, 0, HDA_OUTPUT, 0);
757                 snd_hda_codec_amp_stereo(codec, sp_nid, HDA_OUTPUT, 0,
758                                          HDA_AMP_MUTE, mute);
759         }
760 }
761
762 /* unsolicited event for HP jack sensing */
763 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
764 {
765         if (codec->vendor_id == 0x10ec0880)
766                 res >>= 28;
767         else
768                 res >>= 26;
769         if (res != ALC880_HP_EVENT)
770                 return;
771
772         alc_sku_automute(codec);
773 }
774
775 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
776  *      31 ~ 16 :       Manufacture ID
777  *      15 ~ 8  :       SKU ID
778  *      7  ~ 0  :       Assembly ID
779  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
780  */
781 static void alc_subsystem_id(struct hda_codec *codec,
782                              unsigned int porta, unsigned int porte,
783                              unsigned int portd)
784 {
785         unsigned int ass, tmp, i;
786         unsigned nid;
787         struct alc_spec *spec = codec->spec;
788
789         ass = codec->subsystem_id & 0xffff;
790         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
791                 goto do_sku;
792
793         /*      
794          * 31~30        : port conetcivity
795          * 29~21        : reserve
796          * 20           : PCBEEP input
797          * 19~16        : Check sum (15:1)
798          * 15~1         : Custom
799          * 0            : override
800         */
801         nid = 0x1d;
802         if (codec->vendor_id == 0x10ec0260)
803                 nid = 0x17;
804         ass = snd_hda_codec_read(codec, nid, 0,
805                                  AC_VERB_GET_CONFIG_DEFAULT, 0);
806         if (!(ass & 1) && !(ass & 0x100000))
807                 return;
808         if ((ass >> 30) != 1)   /* no physical connection */
809                 return;
810
811         /* check sum */
812         tmp = 0;
813         for (i = 1; i < 16; i++) {
814                 if ((ass >> i) & 1)
815                         tmp++;
816         }
817         if (((ass >> 16) & 0xf) != tmp)
818                 return;
819 do_sku:
820         /*
821          * 0 : override
822          * 1 :  Swap Jack
823          * 2 : 0 --> Desktop, 1 --> Laptop
824          * 3~5 : External Amplifier control
825          * 7~6 : Reserved
826         */
827         tmp = (ass & 0x38) >> 3;        /* external Amp control */
828         switch (tmp) {
829         case 1:
830                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
831                 break;
832         case 3:
833                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
834                 break;
835         case 7:
836                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
837                 break;
838         case 5: /* set EAPD output high */
839                 switch (codec->vendor_id) {
840                 case 0x10ec0260:
841                         snd_hda_codec_write(codec, 0x0f, 0,
842                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
843                         snd_hda_codec_write(codec, 0x10, 0,
844                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
845                         break;
846                 case 0x10ec0262:
847                 case 0x10ec0267:
848                 case 0x10ec0268:
849                 case 0x10ec0269:
850                 case 0x10ec0862:
851                 case 0x10ec0662:        
852                         snd_hda_codec_write(codec, 0x14, 0,
853                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
854                         snd_hda_codec_write(codec, 0x15, 0,
855                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
856                         break;
857                 }
858                 switch (codec->vendor_id) {
859                 case 0x10ec0260:
860                         snd_hda_codec_write(codec, 0x1a, 0,
861                                             AC_VERB_SET_COEF_INDEX, 7);
862                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
863                                                  AC_VERB_GET_PROC_COEF, 0);
864                         snd_hda_codec_write(codec, 0x1a, 0,
865                                             AC_VERB_SET_COEF_INDEX, 7);
866                         snd_hda_codec_write(codec, 0x1a, 0,
867                                             AC_VERB_SET_PROC_COEF,
868                                             tmp | 0x2010);
869                         break;
870                 case 0x10ec0262:
871                 case 0x10ec0880:
872                 case 0x10ec0882:
873                 case 0x10ec0883:
874                 case 0x10ec0885:
875                 case 0x10ec0888:
876                         snd_hda_codec_write(codec, 0x20, 0,
877                                             AC_VERB_SET_COEF_INDEX, 7);
878                         tmp = snd_hda_codec_read(codec, 0x20, 0,
879                                                  AC_VERB_GET_PROC_COEF, 0);
880                         snd_hda_codec_write(codec, 0x20, 0,
881                                             AC_VERB_SET_COEF_INDEX, 7); 
882                         snd_hda_codec_write(codec, 0x20, 0,
883                                             AC_VERB_SET_PROC_COEF,
884                                             tmp | 0x2010);
885                         break;
886                 case 0x10ec0267:
887                 case 0x10ec0268:
888                         snd_hda_codec_write(codec, 0x20, 0,
889                                             AC_VERB_SET_COEF_INDEX, 7);
890                         tmp = snd_hda_codec_read(codec, 0x20, 0,
891                                                  AC_VERB_GET_PROC_COEF, 0);
892                         snd_hda_codec_write(codec, 0x20, 0,
893                                             AC_VERB_SET_COEF_INDEX, 7); 
894                         snd_hda_codec_write(codec, 0x20, 0,
895                                             AC_VERB_SET_PROC_COEF,
896                                             tmp | 0x3000);
897                         break;
898                 }
899         default:
900                 break;
901         }
902         
903         /* is laptop or Desktop and enable the function "Mute internal speaker
904          * when the external headphone out jack is plugged"
905          */
906         if (!(ass & 0x8000))
907                 return;
908         /*
909          * 10~8 : Jack location
910          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
911          * 14~13: Resvered
912          * 15   : 1 --> enable the function "Mute internal speaker
913          *              when the external headphone out jack is plugged"
914          */
915         if (!spec->autocfg.speaker_pins[0]) {
916                 if (spec->autocfg.line_out_pins[0])
917                         spec->autocfg.speaker_pins[0] =
918                                 spec->autocfg.line_out_pins[0];
919                 else
920                         return;
921         }
922
923         if (!spec->autocfg.hp_pins[0]) {
924                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
925                 if (tmp == 0)
926                         spec->autocfg.hp_pins[0] = porta;
927                 else if (tmp == 1)
928                         spec->autocfg.hp_pins[0] = porte;
929                 else if (tmp == 2)
930                         spec->autocfg.hp_pins[0] = portd;
931                 else
932                         return;
933         }
934
935         snd_hda_codec_write(codec, spec->autocfg.hp_pins[0], 0,
936                             AC_VERB_SET_UNSOLICITED_ENABLE,
937                             AC_USRSP_EN | ALC880_HP_EVENT);
938         spec->unsol_event = alc_sku_unsol_event;
939         spec->init_hook = alc_sku_automute;     
940 }
941
942 /*
943  * Fix-up pin default configurations
944  */
945
946 struct alc_pincfg {
947         hda_nid_t nid;
948         u32 val;
949 };
950
951 static void alc_fix_pincfg(struct hda_codec *codec,
952                            const struct snd_pci_quirk *quirk,
953                            const struct alc_pincfg **pinfix)
954 {
955         const struct alc_pincfg *cfg;
956
957         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
958         if (!quirk)
959                 return;
960
961         cfg = pinfix[quirk->value];
962         for (; cfg->nid; cfg++) {
963                 int i;
964                 u32 val = cfg->val;
965                 for (i = 0; i < 4; i++) {
966                         snd_hda_codec_write(codec, cfg->nid, 0,
967                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0 + i,
968                                     val & 0xff);
969                         val >>= 8;
970                 }
971         }
972 }
973
974 /*
975  * ALC880 3-stack model
976  *
977  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
978  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
979  *                 F-Mic = 0x1b, HP = 0x19
980  */
981
982 static hda_nid_t alc880_dac_nids[4] = {
983         /* front, rear, clfe, rear_surr */
984         0x02, 0x05, 0x04, 0x03
985 };
986
987 static hda_nid_t alc880_adc_nids[3] = {
988         /* ADC0-2 */
989         0x07, 0x08, 0x09,
990 };
991
992 /* The datasheet says the node 0x07 is connected from inputs,
993  * but it shows zero connection in the real implementation on some devices.
994  * Note: this is a 915GAV bug, fixed on 915GLV
995  */
996 static hda_nid_t alc880_adc_nids_alt[2] = {
997         /* ADC1-2 */
998         0x08, 0x09,
999 };
1000
1001 #define ALC880_DIGOUT_NID       0x06
1002 #define ALC880_DIGIN_NID        0x0a
1003
1004 static struct hda_input_mux alc880_capture_source = {
1005         .num_items = 4,
1006         .items = {
1007                 { "Mic", 0x0 },
1008                 { "Front Mic", 0x3 },
1009                 { "Line", 0x2 },
1010                 { "CD", 0x4 },
1011         },
1012 };
1013
1014 /* channel source setting (2/6 channel selection for 3-stack) */
1015 /* 2ch mode */
1016 static struct hda_verb alc880_threestack_ch2_init[] = {
1017         /* set line-in to input, mute it */
1018         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1019         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1020         /* set mic-in to input vref 80%, mute it */
1021         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1022         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1023         { } /* end */
1024 };
1025
1026 /* 6ch mode */
1027 static struct hda_verb alc880_threestack_ch6_init[] = {
1028         /* set line-in to output, unmute it */
1029         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1030         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1031         /* set mic-in to output, unmute it */
1032         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1033         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1034         { } /* end */
1035 };
1036
1037 static struct hda_channel_mode alc880_threestack_modes[2] = {
1038         { 2, alc880_threestack_ch2_init },
1039         { 6, alc880_threestack_ch6_init },
1040 };
1041
1042 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1043         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1044         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1045         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1046         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1047         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1048         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1049         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1050         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1051         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1052         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1053         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1054         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1055         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1056         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1057         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
1058         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
1059         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1060         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1061         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
1062         {
1063                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1064                 .name = "Channel Mode",
1065                 .info = alc_ch_mode_info,
1066                 .get = alc_ch_mode_get,
1067                 .put = alc_ch_mode_put,
1068         },
1069         { } /* end */
1070 };
1071
1072 /* capture mixer elements */
1073 static struct snd_kcontrol_new alc880_capture_mixer[] = {
1074         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
1075         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
1076         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
1077         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
1078         HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
1079         HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
1080         {
1081                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1082                 /* The multiple "Capture Source" controls confuse alsamixer
1083                  * So call somewhat different..
1084                  */
1085                 /* .name = "Capture Source", */
1086                 .name = "Input Source",
1087                 .count = 3,
1088                 .info = alc_mux_enum_info,
1089                 .get = alc_mux_enum_get,
1090                 .put = alc_mux_enum_put,
1091         },
1092         { } /* end */
1093 };
1094
1095 /* capture mixer elements (in case NID 0x07 not available) */
1096 static struct snd_kcontrol_new alc880_capture_alt_mixer[] = {
1097         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1098         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1099         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
1100         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
1101         {
1102                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1103                 /* The multiple "Capture Source" controls confuse alsamixer
1104                  * So call somewhat different..
1105                  */
1106                 /* .name = "Capture Source", */
1107                 .name = "Input Source",
1108                 .count = 2,
1109                 .info = alc_mux_enum_info,
1110                 .get = alc_mux_enum_get,
1111                 .put = alc_mux_enum_put,
1112         },
1113         { } /* end */
1114 };
1115
1116
1117
1118 /*
1119  * ALC880 5-stack model
1120  *
1121  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
1122  *      Side = 0x02 (0xd)
1123  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
1124  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
1125  */
1126
1127 /* additional mixers to alc880_three_stack_mixer */
1128 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
1129         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1130         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
1131         { } /* end */
1132 };
1133
1134 /* channel source setting (6/8 channel selection for 5-stack) */
1135 /* 6ch mode */
1136 static struct hda_verb alc880_fivestack_ch6_init[] = {
1137         /* set line-in to input, mute it */
1138         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1139         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1140         { } /* end */
1141 };
1142
1143 /* 8ch mode */
1144 static struct hda_verb alc880_fivestack_ch8_init[] = {
1145         /* set line-in to output, unmute it */
1146         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1147         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1148         { } /* end */
1149 };
1150
1151 static struct hda_channel_mode alc880_fivestack_modes[2] = {
1152         { 6, alc880_fivestack_ch6_init },
1153         { 8, alc880_fivestack_ch8_init },
1154 };
1155
1156
1157 /*
1158  * ALC880 6-stack model
1159  *
1160  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
1161  *      Side = 0x05 (0x0f)
1162  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
1163  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
1164  */
1165
1166 static hda_nid_t alc880_6st_dac_nids[4] = {
1167         /* front, rear, clfe, rear_surr */
1168         0x02, 0x03, 0x04, 0x05
1169 };
1170
1171 static struct hda_input_mux alc880_6stack_capture_source = {
1172         .num_items = 4,
1173         .items = {
1174                 { "Mic", 0x0 },
1175                 { "Front Mic", 0x1 },
1176                 { "Line", 0x2 },
1177                 { "CD", 0x4 },
1178         },
1179 };
1180
1181 /* fixed 8-channels */
1182 static struct hda_channel_mode alc880_sixstack_modes[1] = {
1183         { 8, NULL },
1184 };
1185
1186 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
1187         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1188         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1189         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1190         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1191         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1192         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1193         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1194         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1195         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1196         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1197         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1198         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1199         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1200         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1201         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1202         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1203         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1204         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1205         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1206         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1207         {
1208                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1209                 .name = "Channel Mode",
1210                 .info = alc_ch_mode_info,
1211                 .get = alc_ch_mode_get,
1212                 .put = alc_ch_mode_put,
1213         },
1214         { } /* end */
1215 };
1216
1217
1218 /*
1219  * ALC880 W810 model
1220  *
1221  * W810 has rear IO for:
1222  * Front (DAC 02)
1223  * Surround (DAC 03)
1224  * Center/LFE (DAC 04)
1225  * Digital out (06)
1226  *
1227  * The system also has a pair of internal speakers, and a headphone jack.
1228  * These are both connected to Line2 on the codec, hence to DAC 02.
1229  * 
1230  * There is a variable resistor to control the speaker or headphone
1231  * volume. This is a hardware-only device without a software API.
1232  *
1233  * Plugging headphones in will disable the internal speakers. This is
1234  * implemented in hardware, not via the driver using jack sense. In
1235  * a similar fashion, plugging into the rear socket marked "front" will
1236  * disable both the speakers and headphones.
1237  *
1238  * For input, there's a microphone jack, and an "audio in" jack.
1239  * These may not do anything useful with this driver yet, because I
1240  * haven't setup any initialization verbs for these yet...
1241  */
1242
1243 static hda_nid_t alc880_w810_dac_nids[3] = {
1244         /* front, rear/surround, clfe */
1245         0x02, 0x03, 0x04
1246 };
1247
1248 /* fixed 6 channels */
1249 static struct hda_channel_mode alc880_w810_modes[1] = {
1250         { 6, NULL }
1251 };
1252
1253 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
1254 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
1255         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1256         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1257         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1258         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1259         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1260         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1261         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1262         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1263         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1264         { } /* end */
1265 };
1266
1267
1268 /*
1269  * Z710V model
1270  *
1271  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
1272  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
1273  *                 Line = 0x1a
1274  */
1275
1276 static hda_nid_t alc880_z71v_dac_nids[1] = {
1277         0x02
1278 };
1279 #define ALC880_Z71V_HP_DAC      0x03
1280
1281 /* fixed 2 channels */
1282 static struct hda_channel_mode alc880_2_jack_modes[1] = {
1283         { 2, NULL }
1284 };
1285
1286 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
1287         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1288         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1289         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1290         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
1291         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1292         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1293         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1294         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1295         { } /* end */
1296 };
1297
1298
1299 /*
1300  * ALC880 F1734 model
1301  *
1302  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
1303  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
1304  */
1305
1306 static hda_nid_t alc880_f1734_dac_nids[1] = {
1307         0x03
1308 };
1309 #define ALC880_F1734_HP_DAC     0x02
1310
1311 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
1312         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1313         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1314         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1315         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1316         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1317         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1318         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1319         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1320         { } /* end */
1321 };
1322
1323
1324 /*
1325  * ALC880 ASUS model
1326  *
1327  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1328  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1329  *  Mic = 0x18, Line = 0x1a
1330  */
1331
1332 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
1333 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
1334
1335 static struct snd_kcontrol_new alc880_asus_mixer[] = {
1336         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1337         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1338         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1339         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1340         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1341         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1342         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1343         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1344         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1345         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1346         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1347         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1348         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1349         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1350         {
1351                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1352                 .name = "Channel Mode",
1353                 .info = alc_ch_mode_info,
1354                 .get = alc_ch_mode_get,
1355                 .put = alc_ch_mode_put,
1356         },
1357         { } /* end */
1358 };
1359
1360 /*
1361  * ALC880 ASUS W1V model
1362  *
1363  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1364  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1365  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
1366  */
1367
1368 /* additional mixers to alc880_asus_mixer */
1369 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
1370         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
1371         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
1372         { } /* end */
1373 };
1374
1375 /* additional mixers to alc880_asus_mixer */
1376 static struct snd_kcontrol_new alc880_pcbeep_mixer[] = {
1377         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1378         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1379         { } /* end */
1380 };
1381
1382 /* TCL S700 */
1383 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
1384         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1385         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1386         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1387         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
1388         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
1389         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
1390         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
1391         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1392         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1393         {
1394                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1395                 /* The multiple "Capture Source" controls confuse alsamixer
1396                  * So call somewhat different..
1397                  */
1398                 /* .name = "Capture Source", */
1399                 .name = "Input Source",
1400                 .count = 1,
1401                 .info = alc_mux_enum_info,
1402                 .get = alc_mux_enum_get,
1403                 .put = alc_mux_enum_put,
1404         },
1405         { } /* end */
1406 };
1407
1408 /* Uniwill */
1409 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
1410         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1411         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1412         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1413         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1414         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1415         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1416         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1417         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1418         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1419         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1420         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1421         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1422         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1423         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1424         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1425         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1426         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1427         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1428         {
1429                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1430                 .name = "Channel Mode",
1431                 .info = alc_ch_mode_info,
1432                 .get = alc_ch_mode_get,
1433                 .put = alc_ch_mode_put,
1434         },
1435         { } /* end */
1436 };
1437
1438 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
1439         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1440         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1441         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1442         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1443         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1444         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1445         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1446         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1447         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1448         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1449         { } /* end */
1450 };
1451
1452 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
1453         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1454         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1455         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1456         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1457         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1458         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1459         { } /* end */
1460 };
1461
1462 /*
1463  * virtual master controls
1464  */
1465
1466 /*
1467  * slave controls for virtual master
1468  */
1469 static const char *alc_slave_vols[] = {
1470         "Front Playback Volume",
1471         "Surround Playback Volume",
1472         "Center Playback Volume",
1473         "LFE Playback Volume",
1474         "Side Playback Volume",
1475         "Headphone Playback Volume",
1476         "Speaker Playback Volume",
1477         "Mono Playback Volume",
1478         "iSpeaker Playback Volume",
1479         "Line-Out Playback Volume",
1480         NULL,
1481 };
1482
1483 static const char *alc_slave_sws[] = {
1484         "Front Playback Switch",
1485         "Surround Playback Switch",
1486         "Center Playback Switch",
1487         "LFE Playback Switch",
1488         "Side Playback Switch",
1489         "Headphone Playback Switch",
1490         "Speaker Playback Switch",
1491         "Mono Playback Switch",
1492         "iSpeaker Playback Switch",
1493         NULL,
1494 };
1495
1496 /*
1497  * build control elements
1498  */
1499 static int alc_build_controls(struct hda_codec *codec)
1500 {
1501         struct alc_spec *spec = codec->spec;
1502         int err;
1503         int i;
1504
1505         for (i = 0; i < spec->num_mixers; i++) {
1506                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1507                 if (err < 0)
1508                         return err;
1509         }
1510
1511         if (spec->multiout.dig_out_nid) {
1512                 err = snd_hda_create_spdif_out_ctls(codec,
1513                                                     spec->multiout.dig_out_nid);
1514                 if (err < 0)
1515                         return err;
1516         }
1517         if (spec->dig_in_nid) {
1518                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1519                 if (err < 0)
1520                         return err;
1521         }
1522
1523         /* if we have no master control, let's create it */
1524         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1525                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1526                                         HDA_OUTPUT, spec->vmaster_tlv);
1527                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1528                                           spec->vmaster_tlv, alc_slave_vols);
1529                 if (err < 0)
1530                         return err;
1531         }
1532         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1533                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1534                                           NULL, alc_slave_sws);
1535                 if (err < 0)
1536                         return err;
1537         }
1538
1539         return 0;
1540 }
1541
1542
1543 /*
1544  * initialize the codec volumes, etc
1545  */
1546
1547 /*
1548  * generic initialization of ADC, input mixers and output mixers
1549  */
1550 static struct hda_verb alc880_volume_init_verbs[] = {
1551         /*
1552          * Unmute ADC0-2 and set the default input to mic-in
1553          */
1554         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
1555         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1556         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
1557         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1558         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
1559         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1560
1561         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1562          * mixer widget
1563          * Note: PASD motherboards uses the Line In 2 as the input for front
1564          * panel mic (mic 2)
1565          */
1566         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
1567         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1568         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1569         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
1570         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
1571         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
1572         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
1573         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
1574
1575         /*
1576          * Set up output mixers (0x0c - 0x0f)
1577          */
1578         /* set vol=0 to output mixers */
1579         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1580         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1581         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1582         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1583         /* set up input amps for analog loopback */
1584         /* Amp Indices: DAC = 0, mixer = 1 */
1585         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1586         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1587         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1588         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1589         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1590         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1591         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1592         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1593
1594         { }
1595 };
1596
1597 /*
1598  * 3-stack pin configuration:
1599  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
1600  */
1601 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
1602         /*
1603          * preset connection lists of input pins
1604          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1605          */
1606         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
1607         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1608         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
1609
1610         /*
1611          * Set pin mode and muting
1612          */
1613         /* set front pin widgets 0x14 for output */
1614         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1615         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1616         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1617         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1618         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1619         /* Mic2 (as headphone out) for HP output */
1620         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1621         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1622         /* Line In pin widget for input */
1623         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1624         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1625         /* Line2 (as front mic) pin widget for input and vref at 80% */
1626         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1627         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1628         /* CD pin widget for input */
1629         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1630
1631         { }
1632 };
1633
1634 /*
1635  * 5-stack pin configuration:
1636  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
1637  * line-in/side = 0x1a, f-mic = 0x1b
1638  */
1639 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
1640         /*
1641          * preset connection lists of input pins
1642          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1643          */
1644         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1645         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
1646
1647         /*
1648          * Set pin mode and muting
1649          */
1650         /* set pin widgets 0x14-0x17 for output */
1651         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1652         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1653         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1654         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1655         /* unmute pins for output (no gain on this amp) */
1656         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1657         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1658         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1659         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1660
1661         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1662         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1663         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1664         /* Mic2 (as headphone out) for HP output */
1665         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1666         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1667         /* Line In pin widget for input */
1668         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1669         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1670         /* Line2 (as front mic) pin widget for input and vref at 80% */
1671         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1672         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1673         /* CD pin widget for input */
1674         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1675
1676         { }
1677 };
1678
1679 /*
1680  * W810 pin configuration:
1681  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
1682  */
1683 static struct hda_verb alc880_pin_w810_init_verbs[] = {
1684         /* hphone/speaker input selector: front DAC */
1685         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
1686
1687         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1688         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1689         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1690         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1691         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1692         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1693
1694         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1695         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1696
1697         { }
1698 };
1699
1700 /*
1701  * Z71V pin configuration:
1702  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
1703  */
1704 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
1705         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1706         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1707         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1708         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1709
1710         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1711         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1712         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1713         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1714
1715         { }
1716 };
1717
1718 /*
1719  * 6-stack pin configuration:
1720  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
1721  * f-mic = 0x19, line = 0x1a, HP = 0x1b
1722  */
1723 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
1724         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1725
1726         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1727         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1728         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1729         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1730         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1731         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1732         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1733         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1734
1735         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1736         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1737         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1738         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1739         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1740         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1741         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1742         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1743         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1744         
1745         { }
1746 };
1747
1748 /*
1749  * Uniwill pin configuration:
1750  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
1751  * line = 0x1a
1752  */
1753 static struct hda_verb alc880_uniwill_init_verbs[] = {
1754         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1755
1756         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1757         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1758         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1759         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1760         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1761         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1762         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1763         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1764         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1765         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1766         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1767         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1768         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1769         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1770
1771         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1772         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1773         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1774         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1775         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1776         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1777         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
1778         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
1779         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1780
1781         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
1782         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
1783
1784         { }
1785 };
1786
1787 /*
1788 * Uniwill P53
1789 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19, 
1790  */
1791 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
1792         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1793
1794         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1795         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1796         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1797         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1798         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1799         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1800         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1801         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1802         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1803         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1804         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1805         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1806
1807         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1808         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1809         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1810         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1811         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1812         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1813
1814         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
1815         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
1816
1817         { }
1818 };
1819
1820 static struct hda_verb alc880_beep_init_verbs[] = {
1821         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
1822         { }
1823 };
1824
1825 /* toggle speaker-output according to the hp-jack state */
1826 static void alc880_uniwill_hp_automute(struct hda_codec *codec)
1827 {
1828         unsigned int present;
1829         unsigned char bits;
1830
1831         present = snd_hda_codec_read(codec, 0x14, 0,
1832                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1833         bits = present ? HDA_AMP_MUTE : 0;
1834         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
1835                                  HDA_AMP_MUTE, bits);
1836         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
1837                                  HDA_AMP_MUTE, bits);
1838 }
1839
1840 /* auto-toggle front mic */
1841 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
1842 {
1843         unsigned int present;
1844         unsigned char bits;
1845
1846         present = snd_hda_codec_read(codec, 0x18, 0,
1847                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1848         bits = present ? HDA_AMP_MUTE : 0;
1849         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
1850 }
1851
1852 static void alc880_uniwill_automute(struct hda_codec *codec)
1853 {
1854         alc880_uniwill_hp_automute(codec);
1855         alc880_uniwill_mic_automute(codec);
1856 }
1857
1858 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
1859                                        unsigned int res)
1860 {
1861         /* Looks like the unsol event is incompatible with the standard
1862          * definition.  4bit tag is placed at 28 bit!
1863          */
1864         switch (res >> 28) {
1865         case ALC880_HP_EVENT:
1866                 alc880_uniwill_hp_automute(codec);
1867                 break;
1868         case ALC880_MIC_EVENT:
1869                 alc880_uniwill_mic_automute(codec);
1870                 break;
1871         }
1872 }
1873
1874 static void alc880_uniwill_p53_hp_automute(struct hda_codec *codec)
1875 {
1876         unsigned int present;
1877         unsigned char bits;
1878
1879         present = snd_hda_codec_read(codec, 0x14, 0,
1880                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1881         bits = present ? HDA_AMP_MUTE : 0;
1882         snd_hda_codec_amp_stereo(codec, 0x15, HDA_INPUT, 0, HDA_AMP_MUTE, bits);
1883 }
1884
1885 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
1886 {
1887         unsigned int present;
1888         
1889         present = snd_hda_codec_read(codec, 0x21, 0,
1890                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
1891         present &= HDA_AMP_VOLMASK;
1892         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
1893                                  HDA_AMP_VOLMASK, present);
1894         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
1895                                  HDA_AMP_VOLMASK, present);
1896 }
1897
1898 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
1899                                            unsigned int res)
1900 {
1901         /* Looks like the unsol event is incompatible with the standard
1902          * definition.  4bit tag is placed at 28 bit!
1903          */
1904         if ((res >> 28) == ALC880_HP_EVENT)
1905                 alc880_uniwill_p53_hp_automute(codec);
1906         if ((res >> 28) == ALC880_DCVOL_EVENT)
1907                 alc880_uniwill_p53_dcvol_automute(codec);
1908 }
1909
1910 /*
1911  * F1734 pin configuration:
1912  * HP = 0x14, speaker-out = 0x15, mic = 0x18
1913  */
1914 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
1915         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
1916         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
1917         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
1918         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
1919
1920         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1921         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1922         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1923         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1924
1925         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1926         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1927         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1928         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1929         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1930         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1931         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1932         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1933         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1934
1935         { }
1936 };
1937
1938 /*
1939  * ASUS pin configuration:
1940  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
1941  */
1942 static struct hda_verb alc880_pin_asus_init_verbs[] = {
1943         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
1944         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
1945         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
1946         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
1947
1948         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1949         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1950         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1951         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1952         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1953         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1954         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1955         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1956
1957         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1958         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1959         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1960         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1961         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1962         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1963         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1964         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1965         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1966         
1967         { }
1968 };
1969
1970 /* Enable GPIO mask and set output */
1971 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
1972 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
1973
1974 /* Clevo m520g init */
1975 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
1976         /* headphone output */
1977         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
1978         /* line-out */
1979         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1980         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1981         /* Line-in */
1982         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1983         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1984         /* CD */
1985         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1986         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1987         /* Mic1 (rear panel) */
1988         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1989         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1990         /* Mic2 (front panel) */
1991         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1992         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1993         /* headphone */
1994         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1995         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1996         /* change to EAPD mode */
1997         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
1998         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
1999
2000         { }
2001 };
2002
2003 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
2004         /* change to EAPD mode */
2005         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2006         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2007
2008         /* Headphone output */
2009         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2010         /* Front output*/
2011         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2012         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2013
2014         /* Line In pin widget for input */
2015         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2016         /* CD pin widget for input */
2017         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2018         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2019         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2020
2021         /* change to EAPD mode */
2022         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2023         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
2024
2025         { }
2026 };
2027
2028 /*
2029  * LG m1 express dual
2030  *
2031  * Pin assignment:
2032  *   Rear Line-In/Out (blue): 0x14
2033  *   Build-in Mic-In: 0x15
2034  *   Speaker-out: 0x17
2035  *   HP-Out (green): 0x1b
2036  *   Mic-In/Out (red): 0x19
2037  *   SPDIF-Out: 0x1e
2038  */
2039
2040 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
2041 static hda_nid_t alc880_lg_dac_nids[3] = {
2042         0x05, 0x02, 0x03
2043 };
2044
2045 /* seems analog CD is not working */
2046 static struct hda_input_mux alc880_lg_capture_source = {
2047         .num_items = 3,
2048         .items = {
2049                 { "Mic", 0x1 },
2050                 { "Line", 0x5 },
2051                 { "Internal Mic", 0x6 },
2052         },
2053 };
2054
2055 /* 2,4,6 channel modes */
2056 static struct hda_verb alc880_lg_ch2_init[] = {
2057         /* set line-in and mic-in to input */
2058         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2059         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2060         { }
2061 };
2062
2063 static struct hda_verb alc880_lg_ch4_init[] = {
2064         /* set line-in to out and mic-in to input */
2065         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2066         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2067         { }
2068 };
2069
2070 static struct hda_verb alc880_lg_ch6_init[] = {
2071         /* set line-in and mic-in to output */
2072         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2073         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2074         { }
2075 };
2076
2077 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
2078         { 2, alc880_lg_ch2_init },
2079         { 4, alc880_lg_ch4_init },
2080         { 6, alc880_lg_ch6_init },
2081 };
2082
2083 static struct snd_kcontrol_new alc880_lg_mixer[] = {
2084         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2085         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
2086         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2087         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
2088         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
2089         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
2090         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
2091         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
2092         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2093         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2094         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
2095         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
2096         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
2097         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
2098         {
2099                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2100                 .name = "Channel Mode",
2101                 .info = alc_ch_mode_info,
2102                 .get = alc_ch_mode_get,
2103                 .put = alc_ch_mode_put,
2104         },
2105         { } /* end */
2106 };
2107
2108 static struct hda_verb alc880_lg_init_verbs[] = {
2109         /* set capture source to mic-in */
2110         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2111         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2112         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2113         /* mute all amp mixer inputs */
2114         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
2115         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2116         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2117         /* line-in to input */
2118         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2119         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2120         /* built-in mic */
2121         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2122         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2123         /* speaker-out */
2124         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2125         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2126         /* mic-in to input */
2127         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2128         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2129         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2130         /* HP-out */
2131         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
2132         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2133         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2134         /* jack sense */
2135         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2136         { }
2137 };
2138
2139 /* toggle speaker-output according to the hp-jack state */
2140 static void alc880_lg_automute(struct hda_codec *codec)
2141 {
2142         unsigned int present;
2143         unsigned char bits;
2144
2145         present = snd_hda_codec_read(codec, 0x1b, 0,
2146                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2147         bits = present ? HDA_AMP_MUTE : 0;
2148         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
2149                                  HDA_AMP_MUTE, bits);
2150 }
2151
2152 static void alc880_lg_unsol_event(struct hda_codec *codec, unsigned int res)
2153 {
2154         /* Looks like the unsol event is incompatible with the standard
2155          * definition.  4bit tag is placed at 28 bit!
2156          */
2157         if ((res >> 28) == 0x01)
2158                 alc880_lg_automute(codec);
2159 }
2160
2161 /*
2162  * LG LW20
2163  *
2164  * Pin assignment:
2165  *   Speaker-out: 0x14
2166  *   Mic-In: 0x18
2167  *   Built-in Mic-In: 0x19
2168  *   Line-In: 0x1b
2169  *   HP-Out: 0x1a
2170  *   SPDIF-Out: 0x1e
2171  */
2172
2173 static struct hda_input_mux alc880_lg_lw_capture_source = {
2174         .num_items = 3,
2175         .items = {
2176                 { "Mic", 0x0 },
2177                 { "Internal Mic", 0x1 },
2178                 { "Line In", 0x2 },
2179         },
2180 };
2181
2182 #define alc880_lg_lw_modes alc880_threestack_modes
2183
2184 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
2185         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2186         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2187         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2188         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
2189         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2190         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2191         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2192         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2193         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2194         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2195         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2196         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2197         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
2198         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
2199         {
2200                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2201                 .name = "Channel Mode",
2202                 .info = alc_ch_mode_info,
2203                 .get = alc_ch_mode_get,
2204                 .put = alc_ch_mode_put,
2205         },
2206         { } /* end */
2207 };
2208
2209 static struct hda_verb alc880_lg_lw_init_verbs[] = {
2210         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2211         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2212         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2213
2214         /* set capture source to mic-in */
2215         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2216         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2217         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2218         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2219         /* speaker-out */
2220         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2221         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2222         /* HP-out */
2223         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2224         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2225         /* mic-in to input */
2226         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2227         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2228         /* built-in mic */
2229         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2230         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2231         /* jack sense */
2232         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2233         { }
2234 };
2235
2236 /* toggle speaker-output according to the hp-jack state */
2237 static void alc880_lg_lw_automute(struct hda_codec *codec)
2238 {
2239         unsigned int present;
2240         unsigned char bits;
2241
2242         present = snd_hda_codec_read(codec, 0x1b, 0,
2243                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2244         bits = present ? HDA_AMP_MUTE : 0;
2245         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
2246                                  HDA_AMP_MUTE, bits);
2247 }
2248
2249 static void alc880_lg_lw_unsol_event(struct hda_codec *codec, unsigned int res)
2250 {
2251         /* Looks like the unsol event is incompatible with the standard
2252          * definition.  4bit tag is placed at 28 bit!
2253          */
2254         if ((res >> 28) == 0x01)
2255                 alc880_lg_lw_automute(codec);
2256 }
2257
2258 #ifdef CONFIG_SND_HDA_POWER_SAVE
2259 static struct hda_amp_list alc880_loopbacks[] = {
2260         { 0x0b, HDA_INPUT, 0 },
2261         { 0x0b, HDA_INPUT, 1 },
2262         { 0x0b, HDA_INPUT, 2 },
2263         { 0x0b, HDA_INPUT, 3 },
2264         { 0x0b, HDA_INPUT, 4 },
2265         { } /* end */
2266 };
2267
2268 static struct hda_amp_list alc880_lg_loopbacks[] = {
2269         { 0x0b, HDA_INPUT, 1 },
2270         { 0x0b, HDA_INPUT, 6 },
2271         { 0x0b, HDA_INPUT, 7 },
2272         { } /* end */
2273 };
2274 #endif
2275
2276 /*
2277  * Common callbacks
2278  */
2279
2280 static int alc_init(struct hda_codec *codec)
2281 {
2282         struct alc_spec *spec = codec->spec;
2283         unsigned int i;
2284
2285         for (i = 0; i < spec->num_init_verbs; i++)
2286                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2287
2288         if (spec->init_hook)
2289                 spec->init_hook(codec);
2290
2291         return 0;
2292 }
2293
2294 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2295 {
2296         struct alc_spec *spec = codec->spec;
2297
2298         if (spec->unsol_event)
2299                 spec->unsol_event(codec, res);
2300 }
2301
2302 #ifdef CONFIG_SND_HDA_POWER_SAVE
2303 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2304 {
2305         struct alc_spec *spec = codec->spec;
2306         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2307 }
2308 #endif
2309
2310 /*
2311  * Analog playback callbacks
2312  */
2313 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
2314                                     struct hda_codec *codec,
2315                                     struct snd_pcm_substream *substream)
2316 {
2317         struct alc_spec *spec = codec->spec;
2318         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
2319 }
2320
2321 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2322                                        struct hda_codec *codec,
2323                                        unsigned int stream_tag,
2324                                        unsigned int format,
2325                                        struct snd_pcm_substream *substream)
2326 {
2327         struct alc_spec *spec = codec->spec;
2328         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2329                                                 stream_tag, format, substream);
2330 }
2331
2332 static int alc880_playback_pcm_cleanup(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_cleanup(codec, &spec->multiout);
2338 }
2339
2340 /*
2341  * Digital out
2342  */
2343 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2344                                         struct hda_codec *codec,
2345                                         struct snd_pcm_substream *substream)
2346 {
2347         struct alc_spec *spec = codec->spec;
2348         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2349 }
2350
2351 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2352                                            struct hda_codec *codec,
2353                                            unsigned int stream_tag,
2354                                            unsigned int format,
2355                                            struct snd_pcm_substream *substream)
2356 {
2357         struct alc_spec *spec = codec->spec;
2358         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2359                                              stream_tag, format, substream);
2360 }
2361
2362 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2363                                          struct hda_codec *codec,
2364                                          struct snd_pcm_substream *substream)
2365 {
2366         struct alc_spec *spec = codec->spec;
2367         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2368 }
2369
2370 /*
2371  * Analog capture
2372  */
2373 static int alc880_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2374                                       struct hda_codec *codec,
2375                                       unsigned int stream_tag,
2376                                       unsigned int format,
2377                                       struct snd_pcm_substream *substream)
2378 {
2379         struct alc_spec *spec = codec->spec;
2380
2381         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
2382                                    stream_tag, 0, format);
2383         return 0;
2384 }
2385
2386 static int alc880_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2387                                       struct hda_codec *codec,
2388                                       struct snd_pcm_substream *substream)
2389 {
2390         struct alc_spec *spec = codec->spec;
2391
2392         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
2393                                    0, 0, 0);
2394         return 0;
2395 }
2396
2397
2398 /*
2399  */
2400 static struct hda_pcm_stream alc880_pcm_analog_playback = {
2401         .substreams = 1,
2402         .channels_min = 2,
2403         .channels_max = 8,
2404         /* NID is set in alc_build_pcms */
2405         .ops = {
2406                 .open = alc880_playback_pcm_open,
2407                 .prepare = alc880_playback_pcm_prepare,
2408                 .cleanup = alc880_playback_pcm_cleanup
2409         },
2410 };
2411
2412 static struct hda_pcm_stream alc880_pcm_analog_capture = {
2413         .substreams = 2,
2414         .channels_min = 2,
2415         .channels_max = 2,
2416         /* NID is set in alc_build_pcms */
2417         .ops = {
2418                 .prepare = alc880_capture_pcm_prepare,
2419                 .cleanup = alc880_capture_pcm_cleanup
2420         },
2421 };
2422
2423 static struct hda_pcm_stream alc880_pcm_digital_playback = {
2424         .substreams = 1,
2425         .channels_min = 2,
2426         .channels_max = 2,
2427         /* NID is set in alc_build_pcms */
2428         .ops = {
2429                 .open = alc880_dig_playback_pcm_open,
2430                 .close = alc880_dig_playback_pcm_close,
2431                 .prepare = alc880_dig_playback_pcm_prepare
2432         },
2433 };
2434
2435 static struct hda_pcm_stream alc880_pcm_digital_capture = {
2436         .substreams = 1,
2437         .channels_min = 2,
2438         .channels_max = 2,
2439         /* NID is set in alc_build_pcms */
2440 };
2441
2442 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2443 static struct hda_pcm_stream alc_pcm_null_playback = {
2444         .substreams = 0,
2445         .channels_min = 0,
2446         .channels_max = 0,
2447 };
2448
2449 static int alc_build_pcms(struct hda_codec *codec)
2450 {
2451         struct alc_spec *spec = codec->spec;
2452         struct hda_pcm *info = spec->pcm_rec;
2453         int i;
2454
2455         codec->num_pcms = 1;
2456         codec->pcm_info = info;
2457
2458         info->name = spec->stream_name_analog;
2459         if (spec->stream_analog_playback) {
2460                 snd_assert(spec->multiout.dac_nids, return -EINVAL);
2461                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
2462                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2463         }
2464         if (spec->stream_analog_capture) {
2465                 snd_assert(spec->adc_nids, return -EINVAL);
2466                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
2467                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2468         }
2469
2470         if (spec->channel_mode) {
2471                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2472                 for (i = 0; i < spec->num_channel_mode; i++) {
2473                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2474                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2475                         }
2476                 }
2477         }
2478
2479         /* SPDIF for stream index #1 */
2480         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2481                 codec->num_pcms = 2;
2482                 info = spec->pcm_rec + 1;
2483                 info->name = spec->stream_name_digital;
2484                 if (spec->multiout.dig_out_nid &&
2485                     spec->stream_digital_playback) {
2486                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
2487                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2488                 }
2489                 if (spec->dig_in_nid &&
2490                     spec->stream_digital_capture) {
2491                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
2492                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2493                 }
2494         }
2495
2496         /* If the use of more than one ADC is requested for the current
2497          * model, configure a second analog capture-only PCM.
2498          */
2499         /* Additional Analaog capture for index #2 */
2500         if (spec->num_adc_nids > 1 && spec->stream_analog_capture &&
2501             spec->adc_nids) {
2502                 codec->num_pcms = 3;
2503                 info = spec->pcm_rec + 2;
2504                 info->name = spec->stream_name_analog;
2505                 /* No playback stream for second PCM */
2506                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = alc_pcm_null_playback;
2507                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2508                 if (spec->stream_analog_capture) {
2509                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
2510                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[1];
2511                 }
2512         }
2513
2514         return 0;
2515 }
2516
2517 static void alc_free(struct hda_codec *codec)
2518 {
2519         struct alc_spec *spec = codec->spec;
2520         unsigned int i;
2521
2522         if (!spec)
2523                 return;
2524
2525         if (spec->kctl_alloc) {
2526                 for (i = 0; i < spec->num_kctl_used; i++)
2527                         kfree(spec->kctl_alloc[i].name);
2528                 kfree(spec->kctl_alloc);
2529         }
2530         kfree(spec);
2531 }
2532
2533 /*
2534  */
2535 static struct hda_codec_ops alc_patch_ops = {
2536         .build_controls = alc_build_controls,
2537         .build_pcms = alc_build_pcms,
2538         .init = alc_init,
2539         .free = alc_free,
2540         .unsol_event = alc_unsol_event,
2541 #ifdef CONFIG_SND_HDA_POWER_SAVE
2542         .check_power_status = alc_check_power_status,
2543 #endif
2544 };
2545
2546
2547 /*
2548  * Test configuration for debugging
2549  *
2550  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
2551  * enum controls.
2552  */
2553 #ifdef CONFIG_SND_DEBUG
2554 static hda_nid_t alc880_test_dac_nids[4] = {
2555         0x02, 0x03, 0x04, 0x05
2556 };
2557
2558 static struct hda_input_mux alc880_test_capture_source = {
2559         .num_items = 7,
2560         .items = {
2561                 { "In-1", 0x0 },
2562                 { "In-2", 0x1 },
2563                 { "In-3", 0x2 },
2564                 { "In-4", 0x3 },
2565                 { "CD", 0x4 },
2566                 { "Front", 0x5 },
2567                 { "Surround", 0x6 },
2568         },
2569 };
2570
2571 static struct hda_channel_mode alc880_test_modes[4] = {
2572         { 2, NULL },
2573         { 4, NULL },
2574         { 6, NULL },
2575         { 8, NULL },
2576 };
2577
2578 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
2579                                  struct snd_ctl_elem_info *uinfo)
2580 {
2581         static char *texts[] = {
2582                 "N/A", "Line Out", "HP Out",
2583                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
2584         };
2585         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2586         uinfo->count = 1;
2587         uinfo->value.enumerated.items = 8;
2588         if (uinfo->value.enumerated.item >= 8)
2589                 uinfo->value.enumerated.item = 7;
2590         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2591         return 0;
2592 }
2593
2594 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
2595                                 struct snd_ctl_elem_value *ucontrol)
2596 {
2597         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2598         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2599         unsigned int pin_ctl, item = 0;
2600
2601         pin_ctl = snd_hda_codec_read(codec, nid, 0,
2602                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2603         if (pin_ctl & AC_PINCTL_OUT_EN) {
2604                 if (pin_ctl & AC_PINCTL_HP_EN)
2605                         item = 2;
2606                 else
2607                         item = 1;
2608         } else if (pin_ctl & AC_PINCTL_IN_EN) {
2609                 switch (pin_ctl & AC_PINCTL_VREFEN) {
2610                 case AC_PINCTL_VREF_HIZ: item = 3; break;
2611                 case AC_PINCTL_VREF_50:  item = 4; break;
2612                 case AC_PINCTL_VREF_GRD: item = 5; break;
2613                 case AC_PINCTL_VREF_80:  item = 6; break;
2614                 case AC_PINCTL_VREF_100: item = 7; break;
2615                 }
2616         }
2617         ucontrol->value.enumerated.item[0] = item;
2618         return 0;
2619 }
2620
2621 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
2622                                 struct snd_ctl_elem_value *ucontrol)
2623 {
2624         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2625         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2626         static unsigned int ctls[] = {
2627                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
2628                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
2629                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
2630                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
2631                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
2632                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
2633         };
2634         unsigned int old_ctl, new_ctl;
2635
2636         old_ctl = snd_hda_codec_read(codec, nid, 0,
2637                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2638         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
2639         if (old_ctl != new_ctl) {
2640                 int val;
2641                 snd_hda_codec_write_cache(codec, nid, 0,
2642                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
2643                                           new_ctl);
2644                 val = ucontrol->value.enumerated.item[0] >= 3 ?
2645                         HDA_AMP_MUTE : 0;
2646                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
2647                                          HDA_AMP_MUTE, val);
2648                 return 1;
2649         }
2650         return 0;
2651 }
2652
2653 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
2654                                  struct snd_ctl_elem_info *uinfo)
2655 {
2656         static char *texts[] = {
2657                 "Front", "Surround", "CLFE", "Side"
2658         };
2659         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2660         uinfo->count = 1;
2661         uinfo->value.enumerated.items = 4;
2662         if (uinfo->value.enumerated.item >= 4)
2663                 uinfo->value.enumerated.item = 3;
2664         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2665         return 0;
2666 }
2667
2668 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
2669                                 struct snd_ctl_elem_value *ucontrol)
2670 {
2671         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2672         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2673         unsigned int sel;
2674
2675         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
2676         ucontrol->value.enumerated.item[0] = sel & 3;
2677         return 0;
2678 }
2679
2680 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
2681                                 struct snd_ctl_elem_value *ucontrol)
2682 {
2683         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2684         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2685         unsigned int sel;
2686
2687         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
2688         if (ucontrol->value.enumerated.item[0] != sel) {
2689                 sel = ucontrol->value.enumerated.item[0] & 3;
2690                 snd_hda_codec_write_cache(codec, nid, 0,
2691                                           AC_VERB_SET_CONNECT_SEL, sel);
2692                 return 1;
2693         }
2694         return 0;
2695 }
2696
2697 #define PIN_CTL_TEST(xname,nid) {                       \
2698                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
2699                         .name = xname,                 \
2700                         .info = alc_test_pin_ctl_info, \
2701                         .get = alc_test_pin_ctl_get,   \
2702                         .put = alc_test_pin_ctl_put,   \
2703                         .private_value = nid           \
2704                         }
2705
2706 #define PIN_SRC_TEST(xname,nid) {                       \
2707                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
2708                         .name = xname,                 \
2709                         .info = alc_test_pin_src_info, \
2710                         .get = alc_test_pin_src_get,   \
2711                         .put = alc_test_pin_src_put,   \
2712                         .private_value = nid           \
2713                         }
2714
2715 static struct snd_kcontrol_new alc880_test_mixer[] = {
2716         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2717         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2718         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
2719         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2720         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2721         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2722         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
2723         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2724         PIN_CTL_TEST("Front Pin Mode", 0x14),
2725         PIN_CTL_TEST("Surround Pin Mode", 0x15),
2726         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
2727         PIN_CTL_TEST("Side Pin Mode", 0x17),
2728         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
2729         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
2730         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
2731         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
2732         PIN_SRC_TEST("In-1 Pin Source", 0x18),
2733         PIN_SRC_TEST("In-2 Pin Source", 0x19),
2734         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
2735         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
2736         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
2737         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
2738         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
2739         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
2740         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
2741         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
2742         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
2743         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
2744         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
2745         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
2746         {
2747                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2748                 .name = "Channel Mode",
2749                 .info = alc_ch_mode_info,
2750                 .get = alc_ch_mode_get,
2751                 .put = alc_ch_mode_put,
2752         },
2753         { } /* end */
2754 };
2755
2756 static struct hda_verb alc880_test_init_verbs[] = {
2757         /* Unmute inputs of 0x0c - 0x0f */
2758         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2759         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2760         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2761         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2762         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2763         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2764         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2765         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2766         /* Vol output for 0x0c-0x0f */
2767         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2768         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2769         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2770         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2771         /* Set output pins 0x14-0x17 */
2772         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2773         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2774         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2775         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2776         /* Unmute output pins 0x14-0x17 */
2777         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2778         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2779         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2780         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2781         /* Set input pins 0x18-0x1c */
2782         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2783         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2784         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2785         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2786         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2787         /* Mute input pins 0x18-0x1b */
2788         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2789         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2790         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2791         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2792         /* ADC set up */
2793         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2794         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2795         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2796         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2797         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2798         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2799         /* Analog input/passthru */
2800         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2801         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2802         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2803         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2804         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2805         { }
2806 };
2807 #endif
2808
2809 /*
2810  */
2811
2812 static const char *alc880_models[ALC880_MODEL_LAST] = {
2813         [ALC880_3ST]            = "3stack",
2814         [ALC880_TCL_S700]       = "tcl",
2815         [ALC880_3ST_DIG]        = "3stack-digout",
2816         [ALC880_CLEVO]          = "clevo",
2817         [ALC880_5ST]            = "5stack",
2818         [ALC880_5ST_DIG]        = "5stack-digout",
2819         [ALC880_W810]           = "w810",
2820         [ALC880_Z71V]           = "z71v",
2821         [ALC880_6ST]            = "6stack",
2822         [ALC880_6ST_DIG]        = "6stack-digout",
2823         [ALC880_ASUS]           = "asus",
2824         [ALC880_ASUS_W1V]       = "asus-w1v",
2825         [ALC880_ASUS_DIG]       = "asus-dig",
2826         [ALC880_ASUS_DIG2]      = "asus-dig2",
2827         [ALC880_UNIWILL_DIG]    = "uniwill",
2828         [ALC880_UNIWILL_P53]    = "uniwill-p53",
2829         [ALC880_FUJITSU]        = "fujitsu",
2830         [ALC880_F1734]          = "F1734",
2831         [ALC880_LG]             = "lg",
2832         [ALC880_LG_LW]          = "lg-lw",
2833 #ifdef CONFIG_SND_DEBUG
2834         [ALC880_TEST]           = "test",
2835 #endif
2836         [ALC880_AUTO]           = "auto",
2837 };
2838
2839 static struct snd_pci_quirk alc880_cfg_tbl[] = {
2840         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
2841         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
2842         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
2843         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
2844         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
2845         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
2846         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
2847         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
2848         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
2849         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
2850         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
2851         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
2852         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
2853         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
2854         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
2855         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
2856         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
2857         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
2858         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
2859         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
2860         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
2861         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS", ALC880_ASUS),
2862         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
2863         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
2864         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
2865         SND_PCI_QUIRK(0x1043, 0, "ASUS", ALC880_ASUS), /* default ASUS */
2866         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
2867         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
2868         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
2869         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
2870         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
2871         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
2872         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
2873         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
2874         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
2875         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
2876         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
2877         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
2878         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
2879         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
2880         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
2881         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
2882         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
2883         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
2884         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
2885         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
2886         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
2887         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
2888         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
2889         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
2890         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
2891         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
2892         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
2893         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
2894         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
2895         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
2896         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
2897         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
2898         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
2899         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
2900         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
2901         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
2902         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
2903         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
2904         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
2905         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
2906         SND_PCI_QUIRK(0x8086, 0, "Intel mobo", ALC880_3ST), /* default Intel */
2907         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
2908         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
2909         {}
2910 };
2911
2912 /*
2913  * ALC880 codec presets
2914  */
2915 static struct alc_config_preset alc880_presets[] = {
2916         [ALC880_3ST] = {
2917                 .mixers = { alc880_three_stack_mixer },
2918                 .init_verbs = { alc880_volume_init_verbs,
2919                                 alc880_pin_3stack_init_verbs },
2920                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2921                 .dac_nids = alc880_dac_nids,
2922                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
2923                 .channel_mode = alc880_threestack_modes,
2924                 .need_dac_fix = 1,
2925                 .input_mux = &alc880_capture_source,
2926         },
2927         [ALC880_3ST_DIG] = {
2928                 .mixers = { alc880_three_stack_mixer },
2929                 .init_verbs = { alc880_volume_init_verbs,
2930                                 alc880_pin_3stack_init_verbs },
2931                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2932                 .dac_nids = alc880_dac_nids,
2933                 .dig_out_nid = ALC880_DIGOUT_NID,
2934                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
2935                 .channel_mode = alc880_threestack_modes,
2936                 .need_dac_fix = 1,
2937                 .input_mux = &alc880_capture_source,
2938         },
2939         [ALC880_TCL_S700] = {
2940                 .mixers = { alc880_tcl_s700_mixer },
2941                 .init_verbs = { alc880_volume_init_verbs,
2942                                 alc880_pin_tcl_S700_init_verbs,
2943                                 alc880_gpio2_init_verbs },
2944                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2945                 .dac_nids = alc880_dac_nids,
2946                 .hp_nid = 0x03,
2947                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
2948                 .channel_mode = alc880_2_jack_modes,
2949                 .input_mux = &alc880_capture_source,
2950         },
2951         [ALC880_5ST] = {
2952                 .mixers = { alc880_three_stack_mixer,
2953                             alc880_five_stack_mixer},
2954                 .init_verbs = { alc880_volume_init_verbs,
2955                                 alc880_pin_5stack_init_verbs },
2956                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2957                 .dac_nids = alc880_dac_nids,
2958                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
2959                 .channel_mode = alc880_fivestack_modes,
2960                 .input_mux = &alc880_capture_source,
2961         },
2962         [ALC880_5ST_DIG] = {
2963                 .mixers = { alc880_three_stack_mixer,
2964                             alc880_five_stack_mixer },
2965                 .init_verbs = { alc880_volume_init_verbs,
2966                                 alc880_pin_5stack_init_verbs },
2967                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2968                 .dac_nids = alc880_dac_nids,
2969                 .dig_out_nid = ALC880_DIGOUT_NID,
2970                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
2971                 .channel_mode = alc880_fivestack_modes,
2972                 .input_mux = &alc880_capture_source,
2973         },
2974         [ALC880_6ST] = {
2975                 .mixers = { alc880_six_stack_mixer },
2976                 .init_verbs = { alc880_volume_init_verbs,
2977                                 alc880_pin_6stack_init_verbs },
2978                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
2979                 .dac_nids = alc880_6st_dac_nids,
2980                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
2981                 .channel_mode = alc880_sixstack_modes,
2982                 .input_mux = &alc880_6stack_capture_source,
2983         },
2984         [ALC880_6ST_DIG] = {
2985                 .mixers = { alc880_six_stack_mixer },
2986                 .init_verbs = { alc880_volume_init_verbs,
2987                                 alc880_pin_6stack_init_verbs },
2988                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
2989                 .dac_nids = alc880_6st_dac_nids,
2990                 .dig_out_nid = ALC880_DIGOUT_NID,
2991                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
2992                 .channel_mode = alc880_sixstack_modes,
2993                 .input_mux = &alc880_6stack_capture_source,
2994         },
2995         [ALC880_W810] = {
2996                 .mixers = { alc880_w810_base_mixer },
2997                 .init_verbs = { alc880_volume_init_verbs,
2998                                 alc880_pin_w810_init_verbs,
2999                                 alc880_gpio2_init_verbs },
3000                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
3001                 .dac_nids = alc880_w810_dac_nids,
3002                 .dig_out_nid = ALC880_DIGOUT_NID,
3003                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3004                 .channel_mode = alc880_w810_modes,
3005                 .input_mux = &alc880_capture_source,
3006         },
3007         [ALC880_Z71V] = {
3008                 .mixers = { alc880_z71v_mixer },
3009                 .init_verbs = { alc880_volume_init_verbs,
3010                                 alc880_pin_z71v_init_verbs },
3011                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
3012                 .dac_nids = alc880_z71v_dac_nids,
3013                 .dig_out_nid = ALC880_DIGOUT_NID,
3014                 .hp_nid = 0x03,
3015                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3016                 .channel_mode = alc880_2_jack_modes,
3017                 .input_mux = &alc880_capture_source,
3018         },
3019         [ALC880_F1734] = {
3020                 .mixers = { alc880_f1734_mixer },
3021                 .init_verbs = { alc880_volume_init_verbs,
3022                                 alc880_pin_f1734_init_verbs },
3023                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
3024                 .dac_nids = alc880_f1734_dac_nids,
3025                 .hp_nid = 0x02,
3026                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3027                 .channel_mode = alc880_2_jack_modes,
3028                 .input_mux = &alc880_capture_source,
3029         },
3030         [ALC880_ASUS] = {
3031                 .mixers = { alc880_asus_mixer },
3032                 .init_verbs = { alc880_volume_init_verbs,
3033                                 alc880_pin_asus_init_verbs,
3034                                 alc880_gpio1_init_verbs },
3035                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3036                 .dac_nids = alc880_asus_dac_nids,
3037                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3038                 .channel_mode = alc880_asus_modes,
3039                 .need_dac_fix = 1,
3040                 .input_mux = &alc880_capture_source,
3041         },
3042         [ALC880_ASUS_DIG] = {
3043                 .mixers = { alc880_asus_mixer },
3044                 .init_verbs = { alc880_volume_init_verbs,
3045                                 alc880_pin_asus_init_verbs,
3046                                 alc880_gpio1_init_verbs },
3047                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3048                 .dac_nids = alc880_asus_dac_nids,
3049                 .dig_out_nid = ALC880_DIGOUT_NID,
3050                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3051                 .channel_mode = alc880_asus_modes,
3052                 .need_dac_fix = 1,
3053                 .input_mux = &alc880_capture_source,
3054         },
3055         [ALC880_ASUS_DIG2] = {
3056                 .mixers = { alc880_asus_mixer },
3057                 .init_verbs = { alc880_volume_init_verbs,
3058                                 alc880_pin_asus_init_verbs,
3059                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
3060                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3061                 .dac_nids = alc880_asus_dac_nids,
3062                 .dig_out_nid = ALC880_DIGOUT_NID,
3063                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3064                 .channel_mode = alc880_asus_modes,
3065                 .need_dac_fix = 1,
3066                 .input_mux = &alc880_capture_source,
3067         },
3068         [ALC880_ASUS_W1V] = {
3069                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
3070                 .init_verbs = { alc880_volume_init_verbs,
3071                                 alc880_pin_asus_init_verbs,
3072                                 alc880_gpio1_init_verbs },
3073                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3074                 .dac_nids = alc880_asus_dac_nids,
3075                 .dig_out_nid = ALC880_DIGOUT_NID,
3076                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3077                 .channel_mode = alc880_asus_modes,
3078                 .need_dac_fix = 1,
3079                 .input_mux = &alc880_capture_source,
3080         },
3081         [ALC880_UNIWILL_DIG] = {
3082                 .mixers = { alc880_asus_mixer, alc880_pcbeep_mixer },
3083                 .init_verbs = { alc880_volume_init_verbs,
3084                                 alc880_pin_asus_init_verbs },
3085                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3086                 .dac_nids = alc880_asus_dac_nids,
3087                 .dig_out_nid = ALC880_DIGOUT_NID,
3088                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3089                 .channel_mode = alc880_asus_modes,
3090                 .need_dac_fix = 1,
3091                 .input_mux = &alc880_capture_source,
3092         },
3093         [ALC880_UNIWILL] = {
3094                 .mixers = { alc880_uniwill_mixer },
3095                 .init_verbs = { alc880_volume_init_verbs,
3096                                 alc880_uniwill_init_verbs },
3097                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3098                 .dac_nids = alc880_asus_dac_nids,
3099                 .dig_out_nid = ALC880_DIGOUT_NID,
3100                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3101                 .channel_mode = alc880_threestack_modes,
3102                 .need_dac_fix = 1,
3103                 .input_mux = &alc880_capture_source,
3104                 .unsol_event = alc880_uniwill_unsol_event,
3105                 .init_hook = alc880_uniwill_automute,
3106         },
3107         [ALC880_UNIWILL_P53] = {
3108                 .mixers = { alc880_uniwill_p53_mixer },
3109                 .init_verbs = { alc880_volume_init_verbs,
3110                                 alc880_uniwill_p53_init_verbs },
3111                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3112                 .dac_nids = alc880_asus_dac_nids,
3113                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3114                 .channel_mode = alc880_threestack_modes,
3115                 .input_mux = &alc880_capture_source,
3116                 .unsol_event = alc880_uniwill_p53_unsol_event,
3117                 .init_hook = alc880_uniwill_p53_hp_automute,
3118         },
3119         [ALC880_FUJITSU] = {
3120                 .mixers = { alc880_fujitsu_mixer,
3121                             alc880_pcbeep_mixer, },
3122                 .init_verbs = { alc880_volume_init_verbs,
3123                                 alc880_uniwill_p53_init_verbs,
3124                                 alc880_beep_init_verbs },
3125                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3126                 .dac_nids = alc880_dac_nids,
3127                 .dig_out_nid = ALC880_DIGOUT_NID,
3128                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3129                 .channel_mode = alc880_2_jack_modes,
3130                 .input_mux = &alc880_capture_source,
3131                 .unsol_event = alc880_uniwill_p53_unsol_event,
3132                 .init_hook = alc880_uniwill_p53_hp_automute,
3133         },
3134         [ALC880_CLEVO] = {
3135                 .mixers = { alc880_three_stack_mixer },
3136                 .init_verbs = { alc880_volume_init_verbs,
3137                                 alc880_pin_clevo_init_verbs },
3138                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3139                 .dac_nids = alc880_dac_nids,
3140                 .hp_nid = 0x03,
3141                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3142                 .channel_mode = alc880_threestack_modes,
3143                 .need_dac_fix = 1,
3144                 .input_mux = &alc880_capture_source,
3145         },
3146         [ALC880_LG] = {
3147                 .mixers = { alc880_lg_mixer },
3148                 .init_verbs = { alc880_volume_init_verbs,
3149                                 alc880_lg_init_verbs },
3150                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
3151                 .dac_nids = alc880_lg_dac_nids,
3152                 .dig_out_nid = ALC880_DIGOUT_NID,
3153                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
3154                 .channel_mode = alc880_lg_ch_modes,
3155                 .need_dac_fix = 1,
3156                 .input_mux = &alc880_lg_capture_source,
3157                 .unsol_event = alc880_lg_unsol_event,
3158                 .init_hook = alc880_lg_automute,
3159 #ifdef CONFIG_SND_HDA_POWER_SAVE
3160                 .loopbacks = alc880_lg_loopbacks,
3161 #endif
3162         },
3163         [ALC880_LG_LW] = {
3164                 .mixers = { alc880_lg_lw_mixer },
3165                 .init_verbs = { alc880_volume_init_verbs,
3166                                 alc880_lg_lw_init_verbs },
3167                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3168                 .dac_nids = alc880_dac_nids,
3169                 .dig_out_nid = ALC880_DIGOUT_NID,
3170                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
3171                 .channel_mode = alc880_lg_lw_modes,
3172                 .input_mux = &alc880_lg_lw_capture_source,
3173                 .unsol_event = alc880_lg_lw_unsol_event,
3174                 .init_hook = alc880_lg_lw_automute,
3175         },
3176 #ifdef CONFIG_SND_DEBUG
3177         [ALC880_TEST] = {
3178                 .mixers = { alc880_test_mixer },
3179                 .init_verbs = { alc880_test_init_verbs },
3180                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
3181                 .dac_nids = alc880_test_dac_nids,
3182                 .dig_out_nid = ALC880_DIGOUT_NID,
3183                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
3184                 .channel_mode = alc880_test_modes,
3185                 .input_mux = &alc880_test_capture_source,
3186         },
3187 #endif
3188 };
3189
3190 /*
3191  * Automatic parse of I/O pins from the BIOS configuration
3192  */
3193
3194 #define NUM_CONTROL_ALLOC       32
3195 #define NUM_VERB_ALLOC          32
3196
3197 enum {
3198         ALC_CTL_WIDGET_VOL,
3199         ALC_CTL_WIDGET_MUTE,
3200         ALC_CTL_BIND_MUTE,
3201 };
3202 static struct snd_kcontrol_new alc880_control_templates[] = {
3203         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
3204         HDA_CODEC_MUTE(NULL, 0, 0, 0),
3205         HDA_BIND_MUTE(NULL, 0, 0, 0),
3206 };
3207
3208 /* add dynamic controls */
3209 static int add_control(struct alc_spec *spec, int type, const char *name,
3210                        unsigned long val)
3211 {
3212         struct snd_kcontrol_new *knew;
3213
3214         if (spec->num_kctl_used >= spec->num_kctl_alloc) {
3215                 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
3216
3217                 /* array + terminator */
3218                 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL);
3219                 if (!knew)
3220                         return -ENOMEM;
3221                 if (spec->kctl_alloc) {
3222                         memcpy(knew, spec->kctl_alloc,
3223                                sizeof(*knew) * spec->num_kctl_alloc);
3224                         kfree(spec->kctl_alloc);
3225                 }
3226                 spec->kctl_alloc = knew;
3227                 spec->num_kctl_alloc = num;
3228         }
3229
3230         knew = &spec->kctl_alloc[spec->num_kctl_used];
3231         *knew = alc880_control_templates[type];
3232         knew->name = kstrdup(name, GFP_KERNEL);
3233         if (!knew->name)
3234                 return -ENOMEM;
3235         knew->private_value = val;
3236         spec->num_kctl_used++;
3237         return 0;
3238 }
3239
3240 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
3241 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
3242 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
3243 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
3244 #define alc880_is_input_pin(nid)        ((nid) >= 0x18)
3245 #define alc880_input_pin_idx(nid)       ((nid) - 0x18)
3246 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
3247 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
3248 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
3249 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
3250 #define ALC880_PIN_CD_NID               0x1c
3251
3252 /* fill in the dac_nids table from the parsed pin configuration */
3253 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
3254                                      const struct auto_pin_cfg *cfg)
3255 {
3256         hda_nid_t nid;
3257         int assigned[4];
3258         int i, j;
3259
3260         memset(assigned, 0, sizeof(assigned));
3261         spec->multiout.dac_nids = spec->private_dac_nids;
3262
3263         /* check the pins hardwired to audio widget */
3264         for (i = 0; i < cfg->line_outs; i++) {
3265                 nid = cfg->line_out_pins[i];
3266                 if (alc880_is_fixed_pin(nid)) {
3267                         int idx = alc880_fixed_pin_idx(nid);
3268                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
3269                         assigned[idx] = 1;
3270                 }
3271         }
3272         /* left pins can be connect to any audio widget */
3273         for (i = 0; i < cfg->line_outs; i++) {
3274                 nid = cfg->line_out_pins[i];
3275                 if (alc880_is_fixed_pin(nid))
3276                         continue;
3277                 /* search for an empty channel */
3278                 for (j = 0; j < cfg->line_outs; j++) {
3279                         if (!assigned[j]) {
3280                                 spec->multiout.dac_nids[i] =
3281                                         alc880_idx_to_dac(j);
3282                                 assigned[j] = 1;
3283                                 break;
3284                         }
3285                 }
3286         }
3287         spec->multiout.num_dacs = cfg->line_outs;
3288         return 0;
3289 }
3290
3291 /* add playback controls from the parsed DAC table */
3292 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
3293                                              const struct auto_pin_cfg *cfg)
3294 {
3295         char name[32];
3296         static const char *chname[4] = {
3297                 "Front", "Surround", NULL /*CLFE*/, "Side"
3298         };
3299         hda_nid_t nid;
3300         int i, err;
3301
3302         for (i = 0; i < cfg->line_outs; i++) {
3303                 if (!spec->multiout.dac_nids[i])
3304                         continue;
3305                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
3306                 if (i == 2) {
3307                         /* Center/LFE */
3308                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3309                                           "Center Playback Volume",
3310                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
3311                                                               HDA_OUTPUT));
3312                         if (err < 0)
3313                                 return err;
3314                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3315                                           "LFE Playback Volume",
3316                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
3317                                                               HDA_OUTPUT));
3318                         if (err < 0)
3319                                 return err;
3320                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3321                                           "Center Playback Switch",
3322                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
3323                                                               HDA_INPUT));
3324                         if (err < 0)
3325                                 return err;
3326                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3327                                           "LFE Playback Switch",
3328                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
3329                                                               HDA_INPUT));
3330                         if (err < 0)
3331                                 return err;
3332                 } else {
3333                         sprintf(name, "%s Playback Volume", chname[i]);
3334                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3335                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3336                                                               HDA_OUTPUT));
3337                         if (err < 0)
3338                                 return err;
3339                         sprintf(name, "%s Playback Switch", chname[i]);
3340                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3341                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
3342                                                               HDA_INPUT));
3343                         if (err < 0)
3344                                 return err;
3345                 }
3346         }
3347         return 0;
3348 }
3349
3350 /* add playback controls for speaker and HP outputs */
3351 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
3352                                         const char *pfx)
3353 {
3354         hda_nid_t nid;
3355         int err;
3356         char name[32];
3357
3358         if (!pin)
3359                 return 0;
3360
3361         if (alc880_is_fixed_pin(pin)) {
3362                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
3363                 /* specify the DAC as the extra output */
3364                 if (!spec->multiout.hp_nid)
3365                         spec->multiout.hp_nid = nid;
3366                 else
3367                         spec->multiout.extra_out_nid[0] = nid;
3368                 /* control HP volume/switch on the output mixer amp */
3369                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
3370                 sprintf(name, "%s Playback Volume", pfx);
3371                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3372                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3373                 if (err < 0)
3374                         return err;
3375                 sprintf(name, "%s Playback Switch", pfx);
3376                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3377                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
3378                 if (err < 0)
3379                         return err;
3380         } else if (alc880_is_multi_pin(pin)) {
3381                 /* set manual connection */
3382                 /* we have only a switch on HP-out PIN */
3383                 sprintf(name, "%s Playback Switch", pfx);
3384                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3385                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3386                 if (err < 0)
3387                         return err;
3388         }
3389         return 0;
3390 }
3391
3392 /* create input playback/capture controls for the given pin */
3393 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
3394                             const char *ctlname,
3395                             int idx, hda_nid_t mix_nid)
3396 {
3397         char name[32];
3398         int err;
3399
3400         sprintf(name, "%s Playback Volume", ctlname);
3401         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3402                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3403         if (err < 0)
3404                 return err;
3405         sprintf(name, "%s Playback Switch", ctlname);
3406         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3407                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3408         if (err < 0)
3409                 return err;
3410         return 0;
3411 }
3412
3413 /* create playback/capture controls for input pins */
3414 static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
3415                                                 const struct auto_pin_cfg *cfg)
3416 {
3417         struct hda_input_mux *imux = &spec->private_imux;
3418         int i, err, idx;
3419
3420         for (i = 0; i < AUTO_PIN_LAST; i++) {
3421                 if (alc880_is_input_pin(cfg->input_pins[i])) {
3422                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
3423                         err = new_analog_input(spec, cfg->input_pins[i],
3424                                                auto_pin_cfg_labels[i],
3425                                                idx, 0x0b);
3426                         if (err < 0)
3427                                 return err;
3428                         imux->items[imux->num_items].label =
3429                                 auto_pin_cfg_labels[i];
3430                         imux->items[imux->num_items].index =
3431                                 alc880_input_pin_idx(cfg->input_pins[i]);
3432                         imux->num_items++;
3433                 }
3434         }
3435         return 0;
3436 }
3437
3438 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
3439                                               hda_nid_t nid, int pin_type,
3440                                               int dac_idx)
3441 {
3442         /* set as output */
3443         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3444                             pin_type);
3445         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3446                             AMP_OUT_UNMUTE);
3447         /* need the manual connection? */
3448         if (alc880_is_multi_pin(nid)) {
3449                 struct alc_spec *spec = codec->spec;
3450                 int idx = alc880_multi_pin_idx(nid);
3451                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
3452                                     AC_VERB_SET_CONNECT_SEL,
3453                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
3454         }
3455 }
3456
3457 static int get_pin_type(int line_out_type)
3458 {
3459         if (line_out_type == AUTO_PIN_HP_OUT)
3460                 return PIN_HP;
3461         else
3462                 return PIN_OUT;
3463 }
3464
3465 static void alc880_auto_init_multi_out(struct hda_codec *codec)
3466 {
3467         struct alc_spec *spec = codec->spec;
3468         int i;
3469         
3470         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
3471         for (i = 0; i < spec->autocfg.line_outs; i++) {
3472                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3473                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3474                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
3475         }
3476 }
3477
3478 static void alc880_auto_init_extra_out(struct hda_codec *codec)
3479 {
3480         struct alc_spec *spec = codec->spec;
3481         hda_nid_t pin;
3482
3483         pin = spec->autocfg.speaker_pins[0];
3484         if (pin) /* connect to front */
3485                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
3486         pin = spec->autocfg.hp_pins[0];
3487         if (pin) /* connect to front */
3488                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
3489 }
3490
3491 static void alc880_auto_init_analog_input(struct hda_codec *codec)
3492 {
3493         struct alc_spec *spec = codec->spec;
3494         int i;
3495
3496         for (i = 0; i < AUTO_PIN_LAST; i++) {
3497                 hda_nid_t nid = spec->autocfg.input_pins[i];
3498                 if (alc880_is_input_pin(nid)) {
3499                         snd_hda_codec_write(codec, nid, 0,
3500                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
3501                                             i <= AUTO_PIN_FRONT_MIC ?
3502                                             PIN_VREF80 : PIN_IN);
3503                         if (nid != ALC880_PIN_CD_NID)
3504                                 snd_hda_codec_write(codec, nid, 0,
3505                                                     AC_VERB_SET_AMP_GAIN_MUTE,
3506                                                     AMP_OUT_MUTE);
3507                 }
3508         }
3509 }
3510
3511 /* parse the BIOS configuration and set up the alc_spec */
3512 /* return 1 if successful, 0 if the proper config is not found,
3513  * or a negative error code
3514  */
3515 static int alc880_parse_auto_config(struct hda_codec *codec)
3516 {
3517         struct alc_spec *spec = codec->spec;
3518         int err;
3519         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
3520
3521         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
3522                                            alc880_ignore);
3523         if (err < 0)
3524                 return err;
3525         if (!spec->autocfg.line_outs)
3526                 return 0; /* can't find valid BIOS pin config */
3527
3528         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
3529         if (err < 0)
3530                 return err;
3531         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
3532         if (err < 0)
3533                 return err;
3534         err = alc880_auto_create_extra_out(spec,
3535                                            spec->autocfg.speaker_pins[0],
3536                                            "Speaker");
3537         if (err < 0)
3538                 return err;
3539         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
3540                                            "Headphone");
3541         if (err < 0)
3542                 return err;
3543         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
3544         if (err < 0)
3545                 return err;
3546
3547         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3548
3549         if (spec->autocfg.dig_out_pin)
3550                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
3551         if (spec->autocfg.dig_in_pin)
3552                 spec->dig_in_nid = ALC880_DIGIN_NID;
3553
3554         if (spec->kctl_alloc)
3555                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
3556
3557         spec->init_verbs[spec->num_init_verbs++] = alc880_volume_init_verbs;
3558
3559         spec->num_mux_defs = 1;
3560         spec->input_mux = &spec->private_imux;
3561
3562         return 1;
3563 }
3564
3565 /* additional initialization for auto-configuration model */
3566 static void alc880_auto_init(struct hda_codec *codec)
3567 {
3568         alc880_auto_init_multi_out(codec);
3569         alc880_auto_init_extra_out(codec);
3570         alc880_auto_init_analog_input(codec);
3571 }
3572
3573 /*
3574  * OK, here we have finally the patch for ALC880
3575  */
3576
3577 static int patch_alc880(struct hda_codec *codec)
3578 {
3579         struct alc_spec *spec;
3580         int board_config;
3581         int err;
3582
3583         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3584         if (spec == NULL)
3585                 return -ENOMEM;
3586
3587         codec->spec = spec;
3588
3589         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
3590                                                   alc880_models,
3591                                                   alc880_cfg_tbl);
3592         if (board_config < 0) {
3593                 printk(KERN_INFO "hda_codec: Unknown model for ALC880, "
3594                        "trying auto-probe from BIOS...\n");
3595                 board_config = ALC880_AUTO;
3596         }
3597
3598         if (board_config == ALC880_AUTO) {
3599                 /* automatic parse from the BIOS config */
3600                 err = alc880_parse_auto_config(codec);
3601                 if (err < 0) {
3602                         alc_free(codec);
3603                         return err;
3604                 } else if (!err) {
3605                         printk(KERN_INFO
3606                                "hda_codec: Cannot set up configuration "
3607                                "from BIOS.  Using 3-stack mode...\n");
3608                         board_config = ALC880_3ST;
3609                 }
3610         }
3611
3612         if (board_config != ALC880_AUTO)
3613                 setup_preset(spec, &alc880_presets[board_config]);
3614
3615         spec->stream_name_analog = "ALC880 Analog";
3616         spec->stream_analog_playback = &alc880_pcm_analog_playback;
3617         spec->stream_analog_capture = &alc880_pcm_analog_capture;
3618
3619         spec->stream_name_digital = "ALC880 Digital";
3620         spec->stream_digital_playback = &alc880_pcm_digital_playback;
3621         spec->stream_digital_capture = &alc880_pcm_digital_capture;
3622
3623         if (!spec->adc_nids && spec->input_mux) {
3624                 /* check whether NID 0x07 is valid */
3625                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
3626                 /* get type */
3627                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
3628                 if (wcap != AC_WID_AUD_IN) {
3629                         spec->adc_nids = alc880_adc_nids_alt;
3630                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
3631                         spec->mixers[spec->num_mixers] =
3632                                 alc880_capture_alt_mixer;
3633                         spec->num_mixers++;
3634                 } else {
3635                         spec->adc_nids = alc880_adc_nids;
3636                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
3637                         spec->mixers[spec->num_mixers] = alc880_capture_mixer;
3638                         spec->num_mixers++;
3639                 }
3640         }
3641
3642         spec->vmaster_nid = 0x0c;
3643
3644         codec->patch_ops = alc_patch_ops;
3645         if (board_config == ALC880_AUTO)
3646                 spec->init_hook = alc880_auto_init;
3647 #ifdef CONFIG_SND_HDA_POWER_SAVE
3648         if (!spec->loopback.amplist)
3649                 spec->loopback.amplist = alc880_loopbacks;
3650 #endif
3651
3652         return 0;
3653 }
3654
3655
3656 /*
3657  * ALC260 support
3658  */
3659
3660 static hda_nid_t alc260_dac_nids[1] = {
3661         /* front */
3662         0x02,
3663 };
3664
3665 static hda_nid_t alc260_adc_nids[1] = {
3666         /* ADC0 */
3667         0x04,
3668 };
3669
3670 static hda_nid_t alc260_adc_nids_alt[1] = {
3671         /* ADC1 */
3672         0x05,
3673 };
3674
3675 static hda_nid_t alc260_hp_adc_nids[2] = {
3676         /* ADC1, 0 */
3677         0x05, 0x04
3678 };
3679
3680 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
3681  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
3682  */
3683 static hda_nid_t alc260_dual_adc_nids[2] = {
3684         /* ADC0, ADC1 */
3685         0x04, 0x05
3686 };
3687
3688 #define ALC260_DIGOUT_NID       0x03
3689 #define ALC260_DIGIN_NID        0x06
3690
3691 static struct hda_input_mux alc260_capture_source = {
3692         .num_items = 4,
3693         .items = {
3694                 { "Mic", 0x0 },
3695                 { "Front Mic", 0x1 },
3696                 { "Line", 0x2 },
3697                 { "CD", 0x4 },
3698         },
3699 };
3700
3701 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
3702  * headphone jack and the internal CD lines since these are the only pins at
3703  * which audio can appear.  For flexibility, also allow the option of
3704  * recording the mixer output on the second ADC (ADC0 doesn't have a
3705  * connection to the mixer output).
3706  */
3707 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
3708         {
3709                 .num_items = 3,
3710                 .items = {
3711                         { "Mic/Line", 0x0 },
3712                         { "CD", 0x4 },
3713                         { "Headphone", 0x2 },
3714                 },
3715         },
3716         {
3717                 .num_items = 4,
3718                 .items = {
3719                         { "Mic/Line", 0x0 },
3720                         { "CD", 0x4 },
3721                         { "Headphone", 0x2 },
3722                         { "Mixer", 0x5 },
3723                 },
3724         },
3725
3726 };
3727
3728 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
3729  * the Fujitsu S702x, but jacks are marked differently.
3730  */
3731 static struct hda_input_mux alc260_acer_capture_sources[2] = {
3732         {
3733                 .num_items = 4,
3734                 .items = {
3735                         { "Mic", 0x0 },
3736                         { "Line", 0x2 },
3737                         { "CD", 0x4 },
3738                         { "Headphone", 0x5 },
3739                 },
3740         },
3741         {
3742                 .num_items = 5,
3743                 .items = {
3744                         { "Mic", 0x0 },
3745                         { "Line", 0x2 },
3746                         { "CD", 0x4 },
3747                         { "Headphone", 0x6 },
3748                         { "Mixer", 0x5 },
3749                 },
3750         },
3751 };
3752 /*
3753  * This is just place-holder, so there's something for alc_build_pcms to look
3754  * at when it calculates the maximum number of channels. ALC260 has no mixer
3755  * element which allows changing the channel mode, so the verb list is
3756  * never used.
3757  */
3758 static struct hda_channel_mode alc260_modes[1] = {
3759         { 2, NULL },
3760 };
3761
3762
3763 /* Mixer combinations
3764  *
3765  * basic: base_output + input + pc_beep + capture
3766  * HP: base_output + input + capture_alt
3767  * HP_3013: hp_3013 + input + capture
3768  * fujitsu: fujitsu + capture
3769  * acer: acer + capture
3770  */
3771
3772 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
3773         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3774         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
3775         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
3776         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
3777         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
3778         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
3779         { } /* end */
3780 };
3781
3782 static struct snd_kcontrol_new alc260_input_mixer[] = {
3783         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3784         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3785         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
3786         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
3787         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
3788         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
3789         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
3790         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
3791         { } /* end */
3792 };
3793
3794 static struct snd_kcontrol_new alc260_pc_beep_mixer[] = {
3795         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT),
3796         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT),
3797         { } /* end */
3798 };
3799
3800 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
3801         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
3802         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
3803         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
3804         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
3805         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3806         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
3807         HDA_CODEC_VOLUME_MONO("iSpeaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
3808         HDA_CODEC_MUTE_MONO("iSpeaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
3809         { } /* end */
3810 };
3811
3812 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12, 
3813  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
3814  */
3815 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
3816         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3817         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
3818         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
3819         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3820         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3821         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
3822         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
3823         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
3824         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
3825         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
3826         HDA_CODEC_VOLUME("Internal Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
3827         HDA_BIND_MUTE("Internal Speaker Playback Switch", 0x09, 2, HDA_INPUT),
3828         { } /* end */
3829 };
3830
3831 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
3832  * versions of the ALC260 don't act on requests to enable mic bias from NID
3833  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
3834  * datasheet doesn't mention this restriction.  At this stage it's not clear
3835  * whether this behaviour is intentional or is a hardware bug in chip
3836  * revisions available in early 2006.  Therefore for now allow the
3837  * "Headphone Jack Mode" control to span all choices, but if it turns out
3838  * that the lack of mic bias for this NID is intentional we could change the
3839  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
3840  *
3841  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
3842  * don't appear to make the mic bias available from the "line" jack, even
3843  * though the NID used for this jack (0x14) can supply it.  The theory is
3844  * that perhaps Acer have included blocking capacitors between the ALC260
3845  * and the output jack.  If this turns out to be the case for all such
3846  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
3847  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
3848  *
3849  * The C20x Tablet series have a mono internal speaker which is controlled
3850  * via the chip's Mono sum widget and pin complex, so include the necessary
3851  * controls for such models.  On models without a "mono speaker" the control
3852  * won't do anything.
3853  */
3854 static struct snd_kcontrol_new alc260_acer_mixer[] = {
3855         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3856         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
3857         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
3858         HDA_CODEC_VOLUME_MONO("Mono Speaker Playback Volume", 0x0a, 1, 0x0,
3859                               HDA_OUTPUT),
3860         HDA_BIND_MUTE_MONO("Mono Speaker Playback Switch", 0x0a, 1, 2,
3861                            HDA_INPUT),
3862         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3863         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3864         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
3865         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
3866         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
3867         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
3868         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
3869         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
3870         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
3871         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
3872         { } /* end */
3873 };
3874
3875 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
3876  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
3877  */
3878 static struct snd_kcontrol_new alc260_will_mixer[] = {
3879         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3880         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
3881         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
3882         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
3883         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
3884         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
3885         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
3886         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
3887         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3888         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3889         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
3890         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
3891         { } /* end */
3892 };
3893
3894 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
3895  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
3896  */
3897 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
3898         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3899         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
3900         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
3901         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
3902         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
3903         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
3904         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
3905         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
3906         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
3907         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
3908         { } /* end */
3909 };
3910
3911 /* capture mixer elements */
3912 static struct snd_kcontrol_new alc260_capture_mixer[] = {
3913         HDA_CODEC_VOLUME("Capture Volume", 0x04, 0x0, HDA_INPUT),
3914         HDA_CODEC_MUTE("Capture Switch", 0x04, 0x0, HDA_INPUT),
3915         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x05, 0x0, HDA_INPUT),
3916         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x05, 0x0, HDA_INPUT),
3917         {
3918                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3919                 /* The multiple "Capture Source" controls confuse alsamixer
3920                  * So call somewhat different..
3921                  */
3922                 /* .name = "Capture Source", */
3923                 .name = "Input Source",
3924                 .count = 2,
3925                 .info = alc_mux_enum_info,
3926                 .get = alc_mux_enum_get,
3927                 .put = alc_mux_enum_put,
3928         },
3929         { } /* end */
3930 };
3931
3932 static struct snd_kcontrol_new alc260_capture_alt_mixer[] = {
3933         HDA_CODEC_VOLUME("Capture Volume", 0x05, 0x0, HDA_INPUT),
3934         HDA_CODEC_MUTE("Capture Switch", 0x05, 0x0, HDA_INPUT),
3935         {
3936                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3937                 /* The multiple "Capture Source" controls confuse alsamixer
3938                  * So call somewhat different..
3939                  */
3940                 /* .name = "Capture Source", */
3941                 .name = "Input Source",
3942                 .count = 1,
3943                 .info = alc_mux_enum_info,
3944                 .get = alc_mux_enum_get,
3945                 .put = alc_mux_enum_put,
3946         },
3947         { } /* end */
3948 };
3949
3950 /*
3951  * initialization verbs
3952  */
3953 static struct hda_verb alc260_init_verbs[] = {
3954         /* Line In pin widget for input */
3955         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3956         /* CD pin widget for input */
3957         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3958         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3959         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3960         /* Mic2 (front panel) pin widget for input and vref at 80% */
3961         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3962         /* LINE-2 is used for line-out in rear */
3963         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3964         /* select line-out */
3965         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
3966         /* LINE-OUT pin */
3967         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3968         /* enable HP */
3969         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3970         /* enable Mono */
3971         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3972         /* mute capture amp left and right */
3973         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3974         /* set connection select to line in (default select for this ADC) */
3975         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
3976         /* mute capture amp left and right */
3977         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3978         /* set connection select to line in (default select for this ADC) */
3979         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
3980         /* set vol=0 Line-Out mixer amp left and right */
3981         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3982         /* unmute pin widget amp left and right (no gain on this amp) */
3983         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3984         /* set vol=0 HP mixer amp left and right */
3985         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3986         /* unmute pin widget amp left and right (no gain on this amp) */
3987         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3988         /* set vol=0 Mono mixer amp left and right */
3989         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3990         /* unmute pin widget amp left and right (no gain on this amp) */
3991         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3992         /* unmute LINE-2 out pin */
3993         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3994         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
3995          * Line In 2 = 0x03
3996          */
3997         /* mute analog inputs */
3998         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3999         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4000         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4001         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4002         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4003         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4004         /* mute Front out path */
4005         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4006         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4007         /* mute Headphone out path */
4008         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4009         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4010         /* mute Mono out path */
4011         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4012         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4013         { }
4014 };
4015
4016 #if 0 /* should be identical with alc260_init_verbs? */
4017 static struct hda_verb alc260_hp_init_verbs[] = {
4018         /* Headphone and output */
4019         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4020         /* mono output */
4021         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4022         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4023         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4024         /* Mic2 (front panel) pin widget for input and vref at 80% */
4025         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4026         /* Line In pin widget for input */
4027         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4028         /* Line-2 pin widget for output */
4029         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4030         /* CD pin widget for input */
4031         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4032         /* unmute amp left and right */
4033         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4034         /* set connection select to line in (default select for this ADC) */
4035         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4036         /* unmute Line-Out mixer amp left and right (volume = 0) */
4037         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4038         /* mute pin widget amp left and right (no gain on this amp) */
4039         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4040         /* unmute HP mixer amp left and right (volume = 0) */
4041         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4042         /* mute pin widget amp left and right (no gain on this amp) */
4043         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4044         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4045          * Line In 2 = 0x03
4046          */
4047         /* mute analog inputs */
4048         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4049         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4050         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4051         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4052         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4053         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4054         /* Unmute Front out path */
4055         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4056         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4057         /* Unmute Headphone out path */
4058         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4059         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4060         /* Unmute Mono out path */
4061         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4062         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4063         { }
4064 };
4065 #endif
4066
4067 static struct hda_verb alc260_hp_3013_init_verbs[] = {
4068         /* Line out and output */
4069         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4070         /* mono output */
4071         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4072         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4073         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4074         /* Mic2 (front panel) pin widget for input and vref at 80% */
4075         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4076         /* Line In pin widget for input */
4077         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4078         /* Headphone pin widget for output */
4079         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4080         /* CD pin widget for input */
4081         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4082         /* unmute amp left and right */
4083         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4084         /* set connection select to line in (default select for this ADC) */
4085         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4086         /* unmute Line-Out mixer amp left and right (volume = 0) */
4087         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4088         /* mute pin widget amp left and right (no gain on this amp) */
4089         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4090         /* unmute HP mixer amp left and right (volume = 0) */
4091         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4092         /* mute pin widget amp left and right (no gain on this amp) */
4093         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4094         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4095          * Line In 2 = 0x03
4096          */
4097         /* mute analog inputs */
4098         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4099         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4100         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4101         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4102         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4103         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4104         /* Unmute Front out path */
4105         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4106         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4107         /* Unmute Headphone out path */
4108         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4109         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4110         /* Unmute Mono out path */
4111         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4112         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4113         { }
4114 };
4115
4116 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
4117  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
4118  * audio = 0x16, internal speaker = 0x10.
4119  */
4120 static struct hda_verb alc260_fujitsu_init_verbs[] = {
4121         /* Disable all GPIOs */
4122         {0x01, AC_VERB_SET_GPIO_MASK, 0},
4123         /* Internal speaker is connected to headphone pin */
4124         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4125         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
4126         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4127         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
4128         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4129         /* Ensure all other unused pins are disabled and muted. */
4130         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4131         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4132         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4133         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4134         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4135         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4136         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4137         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4138
4139         /* Disable digital (SPDIF) pins */
4140         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4141         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4142
4143         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus 
4144          * when acting as an output.
4145          */
4146         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4147
4148         /* Start with output sum widgets muted and their output gains at min */
4149         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4150         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4151         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4152         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4153         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4154         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4155         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4156         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4157         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4158
4159         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
4160         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4161         /* Unmute Line1 pin widget output buffer since it starts as an output.
4162          * If the pin mode is changed by the user the pin mode control will
4163          * take care of enabling the pin's input/output buffers as needed.
4164          * Therefore there's no need to enable the input buffer at this
4165          * stage.
4166          */
4167         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4168         /* Unmute input buffer of pin widget used for Line-in (no equiv 
4169          * mixer ctrl)
4170          */
4171         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4172
4173         /* Mute capture amp left and right */
4174         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4175         /* Set ADC connection select to match default mixer setting - line 
4176          * in (on mic1 pin)
4177          */
4178         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4179
4180         /* Do the same for the second ADC: mute capture input amp and
4181          * set ADC connection to line in (on mic1 pin)
4182          */
4183         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4184         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4185
4186         /* Mute all inputs to mixer widget (even unconnected ones) */
4187         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4188         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4189         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4190         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4191         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4192         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4193         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4194         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4195
4196         { }
4197 };
4198
4199 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
4200  * similar laptops (adapted from Fujitsu init verbs).
4201  */
4202 static struct hda_verb alc260_acer_init_verbs[] = {
4203         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
4204          * the headphone jack.  Turn this on and rely on the standard mute
4205          * methods whenever the user wants to turn these outputs off.
4206          */
4207         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
4208         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4209         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
4210         /* Internal speaker/Headphone jack is connected to Line-out pin */
4211         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4212         /* Internal microphone/Mic jack is connected to Mic1 pin */
4213         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
4214         /* Line In jack is connected to Line1 pin */
4215         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4216         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
4217         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4218         /* Ensure all other unused pins are disabled and muted. */
4219         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4220         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4221         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4222         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4223         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4224         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4225         /* Disable digital (SPDIF) pins */
4226         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4227         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4228
4229         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum 
4230          * bus when acting as outputs.
4231          */
4232         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
4233         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4234
4235         /* Start with output sum widgets muted and their output gains at min */
4236         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4237         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4238         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4239         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4240         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4241         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4242         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4243         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4244         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4245
4246         /* Unmute Line-out pin widget amp left and right
4247          * (no equiv mixer ctrl)
4248          */
4249         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4250         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
4251         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4252         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
4253          * inputs. If the pin mode is changed by the user the pin mode control
4254          * will take care of enabling the pin's input/output buffers as needed.
4255          * Therefore there's no need to enable the input buffer at this
4256          * stage.
4257          */
4258         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4259         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4260
4261         /* Mute capture amp left and right */
4262         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4263         /* Set ADC connection select to match default mixer setting - mic
4264          * (on mic1 pin)
4265          */
4266         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4267
4268         /* Do similar with the second ADC: mute capture input amp and
4269          * set ADC connection to mic to match ALSA's default state.
4270          */
4271         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4272         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4273
4274         /* Mute all inputs to mixer widget (even unconnected ones) */
4275         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4276         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4277         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4278         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4279         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4280         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4281         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4282         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4283
4284         { }
4285 };
4286
4287 static struct hda_verb alc260_will_verbs[] = {
4288         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4289         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
4290         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
4291         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4292         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
4293         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
4294         {}
4295 };
4296
4297 static struct hda_verb alc260_replacer_672v_verbs[] = {
4298         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4299         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
4300         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
4301
4302         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
4303         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4304         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4305
4306         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4307         {}
4308 };
4309
4310 /* toggle speaker-output according to the hp-jack state */
4311 static void alc260_replacer_672v_automute(struct hda_codec *codec)
4312 {
4313         unsigned int present;
4314
4315         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
4316         present = snd_hda_codec_read(codec, 0x0f, 0,
4317                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
4318         if (present) {
4319                 snd_hda_codec_write_cache(codec, 0x01, 0,
4320                                           AC_VERB_SET_GPIO_DATA, 1);
4321                 snd_hda_codec_write_cache(codec, 0x0f, 0,
4322                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4323                                           PIN_HP);
4324         } else {
4325                 snd_hda_codec_write_cache(codec, 0x01, 0,
4326                                           AC_VERB_SET_GPIO_DATA, 0);
4327                 snd_hda_codec_write_cache(codec, 0x0f, 0,
4328                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4329                                           PIN_OUT);
4330         }
4331 }
4332
4333 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
4334                                        unsigned int res)
4335 {
4336         if ((res >> 26) == ALC880_HP_EVENT)
4337                 alc260_replacer_672v_automute(codec);
4338 }
4339
4340 /* Test configuration for debugging, modelled after the ALC880 test
4341  * configuration.
4342  */
4343 #ifdef CONFIG_SND_DEBUG
4344 static hda_nid_t alc260_test_dac_nids[1] = {
4345         0x02,
4346 };
4347 static hda_nid_t alc260_test_adc_nids[2] = {
4348         0x04, 0x05,
4349 };
4350 /* For testing the ALC260, each input MUX needs its own definition since
4351  * the signal assignments are different.  This assumes that the first ADC 
4352  * is NID 0x04.
4353  */
4354 static struct hda_input_mux alc260_test_capture_sources[2] = {
4355         {
4356                 .num_items = 7,
4357                 .items = {
4358                         { "MIC1 pin", 0x0 },
4359                         { "MIC2 pin", 0x1 },
4360                         { "LINE1 pin", 0x2 },
4361                         { "LINE2 pin", 0x3 },
4362                         { "CD pin", 0x4 },
4363                         { "LINE-OUT pin", 0x5 },
4364                         { "HP-OUT pin", 0x6 },
4365                 },
4366         },
4367         {
4368                 .num_items = 8,
4369                 .items = {
4370                         { "MIC1 pin", 0x0 },
4371                         { "MIC2 pin", 0x1 },
4372                         { "LINE1 pin", 0x2 },
4373                         { "LINE2 pin", 0x3 },
4374                         { "CD pin", 0x4 },
4375                         { "Mixer", 0x5 },
4376                         { "LINE-OUT pin", 0x6 },
4377                         { "HP-OUT pin", 0x7 },
4378                 },
4379         },
4380 };
4381 static struct snd_kcontrol_new alc260_test_mixer[] = {
4382         /* Output driver widgets */
4383         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4384         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4385         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4386         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
4387         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4388         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
4389
4390         /* Modes for retasking pin widgets
4391          * Note: the ALC260 doesn't seem to act on requests to enable mic
4392          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
4393          * mention this restriction.  At this stage it's not clear whether
4394          * this behaviour is intentional or is a hardware bug in chip
4395          * revisions available at least up until early 2006.  Therefore for
4396          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
4397          * choices, but if it turns out that the lack of mic bias for these
4398          * NIDs is intentional we could change their modes from
4399          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4400          */
4401         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
4402         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
4403         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
4404         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
4405         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
4406         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
4407
4408         /* Loopback mixer controls */
4409         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
4410         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
4411         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
4412         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
4413         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
4414         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
4415         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
4416         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
4417         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4418         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4419         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4420         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4421         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
4422         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
4423         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
4424         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
4425
4426         /* Controls for GPIO pins, assuming they are configured as outputs */
4427         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
4428         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
4429         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
4430         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
4431
4432         /* Switches to allow the digital IO pins to be enabled.  The datasheet
4433          * is ambigious as to which NID is which; testing on laptops which
4434          * make this output available should provide clarification. 
4435          */
4436         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
4437         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
4438
4439         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
4440          * this output to turn on an external amplifier.
4441          */
4442         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
4443         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
4444
4445         { } /* end */
4446 };
4447 static struct hda_verb alc260_test_init_verbs[] = {
4448         /* Enable all GPIOs as outputs with an initial value of 0 */
4449         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
4450         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4451         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
4452
4453         /* Enable retasking pins as output, initially without power amp */
4454         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4455         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4456         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4457         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4458         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4459         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4460
4461         /* Disable digital (SPDIF) pins initially, but users can enable
4462          * them via a mixer switch.  In the case of SPDIF-out, this initverb
4463          * payload also sets the generation to 0, output to be in "consumer"
4464          * PCM format, copyright asserted, no pre-emphasis and no validity
4465          * control.
4466          */
4467         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4468         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4469
4470         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the 
4471          * OUT1 sum bus when acting as an output.
4472          */
4473         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
4474         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
4475         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4476         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
4477
4478         /* Start with output sum widgets muted and their output gains at min */
4479         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4480         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4481         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4482         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4483         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4484         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4485         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4486         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4487         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4488
4489         /* Unmute retasking pin widget output buffers since the default
4490          * state appears to be output.  As the pin mode is changed by the
4491          * user the pin mode control will take care of enabling the pin's
4492          * input/output buffers as needed.
4493          */
4494         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4495         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4496         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4497         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4498         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4499         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4500         /* Also unmute the mono-out pin widget */
4501         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4502
4503         /* Mute capture amp left and right */
4504         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4505         /* Set ADC connection select to match default mixer setting (mic1
4506          * pin)
4507          */
4508         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4509
4510         /* Do the same for the second ADC: mute capture input amp and
4511          * set ADC connection to mic1 pin
4512          */
4513         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4514         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4515
4516         /* Mute all inputs to mixer widget (even unconnected ones) */
4517         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4518         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4519         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4520         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4521         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4522         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4523         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4524         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4525
4526         { }
4527 };
4528 #endif
4529
4530 static struct hda_pcm_stream alc260_pcm_analog_playback = {
4531         .substreams = 1,
4532         .channels_min = 2,
4533         .channels_max = 2,
4534 };
4535
4536 static struct hda_pcm_stream alc260_pcm_analog_capture = {
4537         .substreams = 1,
4538         .channels_min = 2,
4539         .channels_max = 2,
4540 };
4541
4542 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
4543 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
4544
4545 /*
4546  * for BIOS auto-configuration
4547  */
4548
4549 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
4550                                         const char *pfx)
4551 {
4552         hda_nid_t nid_vol;
4553         unsigned long vol_val, sw_val;
4554         char name[32];
4555         int err;
4556
4557         if (nid >= 0x0f && nid < 0x11) {
4558                 nid_vol = nid - 0x7;
4559                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
4560                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
4561         } else if (nid == 0x11) {
4562                 nid_vol = nid - 0x7;
4563                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
4564                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
4565         } else if (nid >= 0x12 && nid <= 0x15) {
4566                 nid_vol = 0x08;
4567                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
4568                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
4569         } else
4570                 return 0; /* N/A */
4571         
4572         snprintf(name, sizeof(name), "%s Playback Volume", pfx);
4573         err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val);
4574         if (err < 0)
4575                 return err;
4576         snprintf(name, sizeof(name), "%s Playback Switch", pfx);
4577         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val);
4578         if (err < 0)
4579                 return err;
4580         return 1;
4581 }
4582
4583 /* add playback controls from the parsed DAC table */
4584 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
4585                                              const struct auto_pin_cfg *cfg)
4586 {
4587         hda_nid_t nid;
4588         int err;
4589
4590         spec->multiout.num_dacs = 1;
4591         spec->multiout.dac_nids = spec->private_dac_nids;
4592         spec->multiout.dac_nids[0] = 0x02;
4593
4594         nid = cfg->line_out_pins[0];
4595         if (nid) {
4596                 err = alc260_add_playback_controls(spec, nid, "Front");
4597                 if (err < 0)
4598                         return err;
4599         }
4600
4601         nid = cfg->speaker_pins[0];
4602         if (nid) {
4603                 err = alc260_add_playback_controls(spec, nid, "Speaker");
4604                 if (err < 0)
4605                         return err;
4606         }
4607
4608         nid = cfg->hp_pins[0];
4609         if (nid) {
4610                 err = alc260_add_playback_controls(spec, nid, "Headphone");
4611                 if (err < 0)
4612                         return err;
4613         }
4614         return 0;
4615 }
4616
4617 /* create playback/capture controls for input pins */
4618 static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec,
4619                                                 const struct auto_pin_cfg *cfg)
4620 {
4621         struct hda_input_mux *imux = &spec->private_imux;
4622         int i, err, idx;
4623
4624         for (i = 0; i < AUTO_PIN_LAST; i++) {
4625                 if (cfg->input_pins[i] >= 0x12) {
4626                         idx = cfg->input_pins[i] - 0x12;
4627                         err = new_analog_input(spec, cfg->input_pins[i],
4628                                                auto_pin_cfg_labels[i], idx,
4629                                                0x07);
4630                         if (err < 0)
4631                                 return err;
4632                         imux->items[imux->num_items].label =
4633                                 auto_pin_cfg_labels[i];
4634                         imux->items[imux->num_items].index = idx;
4635                         imux->num_items++;
4636                 }
4637                 if (cfg->input_pins[i] >= 0x0f && cfg->input_pins[i] <= 0x10){
4638                         idx = cfg->input_pins[i] - 0x09;
4639                         err = new_analog_input(spec, cfg->input_pins[i],
4640                                                auto_pin_cfg_labels[i], idx,
4641                                                0x07);
4642                         if (err < 0)
4643                                 return err;
4644                         imux->items[imux->num_items].label =
4645                                 auto_pin_cfg_labels[i];
4646                         imux->items[imux->num_items].index = idx;
4647                         imux->num_items++;
4648                 }
4649         }
4650         return 0;
4651 }
4652
4653 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
4654                                               hda_nid_t nid, int pin_type,
4655                                               int sel_idx)
4656 {
4657         /* set as output */
4658         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4659                             pin_type);
4660         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4661                             AMP_OUT_UNMUTE);
4662         /* need the manual connection? */
4663         if (nid >= 0x12) {
4664                 int idx = nid - 0x12;
4665                 snd_hda_codec_write(codec, idx + 0x0b, 0,
4666                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
4667         }
4668 }
4669
4670 static void alc260_auto_init_multi_out(struct hda_codec *codec)
4671 {
4672         struct alc_spec *spec = codec->spec;
4673         hda_nid_t nid;
4674
4675         alc_subsystem_id(codec, 0x10, 0x15, 0x0f);
4676         nid = spec->autocfg.line_out_pins[0];
4677         if (nid) {
4678                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
4679                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
4680         }
4681         
4682         nid = spec->autocfg.speaker_pins[0];
4683         if (nid)
4684                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
4685
4686         nid = spec->autocfg.hp_pins[0];
4687         if (nid)
4688                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
4689 }
4690
4691 #define ALC260_PIN_CD_NID               0x16
4692 static void alc260_auto_init_analog_input(struct hda_codec *codec)
4693 {
4694         struct alc_spec *spec = codec->spec;
4695         int i;
4696
4697         for (i = 0; i < AUTO_PIN_LAST; i++) {
4698                 hda_nid_t nid = spec->autocfg.input_pins[i];
4699                 if (nid >= 0x12) {
4700                         snd_hda_codec_write(codec, nid, 0,
4701                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
4702                                             i <= AUTO_PIN_FRONT_MIC ?
4703                                             PIN_VREF80 : PIN_IN);
4704                         if (nid != ALC260_PIN_CD_NID)
4705                                 snd_hda_codec_write(codec, nid, 0,
4706                                                     AC_VERB_SET_AMP_GAIN_MUTE,
4707                                                     AMP_OUT_MUTE);
4708                 }
4709         }
4710 }
4711
4712 /*
4713  * generic initialization of ADC, input mixers and output mixers
4714  */
4715 static struct hda_verb alc260_volume_init_verbs[] = {
4716         /*
4717          * Unmute ADC0-1 and set the default input to mic-in
4718          */
4719         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4720         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4721         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4722         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4723         
4724         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4725          * mixer widget
4726          * Note: PASD motherboards uses the Line In 2 as the input for
4727          * front panel mic (mic 2)
4728          */
4729         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
4730         /* mute analog inputs */
4731         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4732         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4733         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4734         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4735         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4736
4737         /*
4738          * Set up output mixers (0x08 - 0x0a)
4739          */
4740         /* set vol=0 to output mixers */
4741         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4742         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4743         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4744         /* set up input amps for analog loopback */
4745         /* Amp Indices: DAC = 0, mixer = 1 */
4746         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4747         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4748         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4749         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4750         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4751         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4752         
4753         { }
4754 };
4755
4756 static int alc260_parse_auto_config(struct hda_codec *codec)
4757 {
4758         struct alc_spec *spec = codec->spec;
4759         unsigned int wcap;
4760         int err;
4761         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
4762
4763         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
4764                                            alc260_ignore);
4765         if (err < 0)
4766                 return err;
4767         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
4768         if (err < 0)
4769                 return err;
4770         if (!spec->kctl_alloc)
4771                 return 0; /* can't find valid BIOS pin config */
4772         err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg);
4773         if (err < 0)
4774                 return err;
4775
4776         spec->multiout.max_channels = 2;
4777
4778         if (spec->autocfg.dig_out_pin)
4779                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
4780         if (spec->kctl_alloc)
4781                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
4782
4783         spec->init_verbs[spec->num_init_verbs++] = alc260_volume_init_verbs;
4784
4785         spec->num_mux_defs = 1;
4786         spec->input_mux = &spec->private_imux;
4787
4788         /* check whether NID 0x04 is valid */
4789         wcap = get_wcaps(codec, 0x04);
4790         wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */
4791         if (wcap != AC_WID_AUD_IN) {
4792                 spec->adc_nids = alc260_adc_nids_alt;
4793                 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
4794                 spec->mixers[spec->num_mixers] = alc260_capture_alt_mixer;
4795         } else {
4796                 spec->adc_nids = alc260_adc_nids;
4797                 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
4798                 spec->mixers[spec->num_mixers] = alc260_capture_mixer;
4799         }
4800         spec->num_mixers++;
4801
4802         return 1;
4803 }
4804
4805 /* additional initialization for auto-configuration model */
4806 static void alc260_auto_init(struct hda_codec *codec)
4807 {
4808         alc260_auto_init_multi_out(codec);
4809         alc260_auto_init_analog_input(codec);
4810 }
4811
4812 #ifdef CONFIG_SND_HDA_POWER_SAVE
4813 static struct hda_amp_list alc260_loopbacks[] = {
4814         { 0x07, HDA_INPUT, 0 },
4815         { 0x07, HDA_INPUT, 1 },
4816         { 0x07, HDA_INPUT, 2 },
4817         { 0x07, HDA_INPUT, 3 },
4818         { 0x07, HDA_INPUT, 4 },
4819         { } /* end */
4820 };
4821 #endif
4822
4823 /*
4824  * ALC260 configurations
4825  */
4826 static const char *alc260_models[ALC260_MODEL_LAST] = {
4827         [ALC260_BASIC]          = "basic",
4828         [ALC260_HP]             = "hp",
4829         [ALC260_HP_3013]        = "hp-3013",
4830         [ALC260_FUJITSU_S702X]  = "fujitsu",
4831         [ALC260_ACER]           = "acer",
4832         [ALC260_WILL]           = "will",
4833         [ALC260_REPLACER_672V]  = "replacer",
4834 #ifdef CONFIG_SND_DEBUG
4835         [ALC260_TEST]           = "test",
4836 #endif
4837         [ALC260_AUTO]           = "auto",
4838 };
4839
4840 static struct snd_pci_quirk alc260_cfg_tbl[] = {
4841         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
4842         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
4843         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
4844         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013),
4845         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
4846         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP),
4847         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_3013),
4848         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
4849         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
4850         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
4851         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
4852         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
4853         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
4854         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
4855         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
4856         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
4857         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
4858         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
4859         {}
4860 };
4861
4862 static struct alc_config_preset alc260_presets[] = {
4863         [ALC260_BASIC] = {
4864                 .mixers = { alc260_base_output_mixer,
4865                             alc260_input_mixer,
4866                             alc260_pc_beep_mixer,
4867                             alc260_capture_mixer },
4868                 .init_verbs = { alc260_init_verbs },
4869                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4870                 .dac_nids = alc260_dac_nids,
4871                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
4872                 .adc_nids = alc260_adc_nids,
4873                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4874                 .channel_mode = alc260_modes,
4875                 .input_mux = &alc260_capture_source,
4876         },
4877         [ALC260_HP] = {
4878                 .mixers = { alc260_base_output_mixer,
4879                             alc260_input_mixer,
4880                             alc260_capture_alt_mixer },
4881                 .init_verbs = { alc260_init_verbs },
4882                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4883                 .dac_nids = alc260_dac_nids,
4884                 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
4885                 .adc_nids = alc260_hp_adc_nids,
4886                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4887                 .channel_mode = alc260_modes,
4888                 .input_mux = &alc260_capture_source,
4889         },
4890         [ALC260_HP_3013] = {
4891                 .mixers = { alc260_hp_3013_mixer,
4892                             alc260_input_mixer,
4893                             alc260_capture_alt_mixer },
4894                 .init_verbs = { alc260_hp_3013_init_verbs },
4895                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4896                 .dac_nids = alc260_dac_nids,
4897                 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
4898                 .adc_nids = alc260_hp_adc_nids,
4899                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4900                 .channel_mode = alc260_modes,
4901                 .input_mux = &alc260_capture_source,
4902         },
4903         [ALC260_FUJITSU_S702X] = {
4904                 .mixers = { alc260_fujitsu_mixer,
4905                             alc260_capture_mixer },
4906                 .init_verbs = { alc260_fujitsu_init_verbs },
4907                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4908                 .dac_nids = alc260_dac_nids,
4909                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
4910                 .adc_nids = alc260_dual_adc_nids,
4911                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4912                 .channel_mode = alc260_modes,
4913                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
4914                 .input_mux = alc260_fujitsu_capture_sources,
4915         },
4916         [ALC260_ACER] = {
4917                 .mixers = { alc260_acer_mixer,
4918                             alc260_capture_mixer },
4919                 .init_verbs = { alc260_acer_init_verbs },
4920                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4921                 .dac_nids = alc260_dac_nids,
4922                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
4923                 .adc_nids = alc260_dual_adc_nids,
4924                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4925                 .channel_mode = alc260_modes,
4926                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
4927                 .input_mux = alc260_acer_capture_sources,
4928         },
4929         [ALC260_WILL] = {
4930                 .mixers = { alc260_will_mixer,
4931                             alc260_capture_mixer },
4932                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
4933                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4934                 .dac_nids = alc260_dac_nids,
4935                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
4936                 .adc_nids = alc260_adc_nids,
4937                 .dig_out_nid = ALC260_DIGOUT_NID,
4938                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4939                 .channel_mode = alc260_modes,
4940                 .input_mux = &alc260_capture_source,
4941         },
4942         [ALC260_REPLACER_672V] = {
4943                 .mixers = { alc260_replacer_672v_mixer,
4944                             alc260_capture_mixer },
4945                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
4946                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4947                 .dac_nids = alc260_dac_nids,
4948                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
4949                 .adc_nids = alc260_adc_nids,
4950                 .dig_out_nid = ALC260_DIGOUT_NID,
4951                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4952                 .channel_mode = alc260_modes,
4953                 .input_mux = &alc260_capture_source,
4954                 .unsol_event = alc260_replacer_672v_unsol_event,
4955                 .init_hook = alc260_replacer_672v_automute,
4956         },
4957 #ifdef CONFIG_SND_DEBUG
4958         [ALC260_TEST] = {
4959                 .mixers = { alc260_test_mixer,
4960                             alc260_capture_mixer },
4961                 .init_verbs = { alc260_test_init_verbs },
4962                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
4963                 .dac_nids = alc260_test_dac_nids,
4964                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
4965                 .adc_nids = alc260_test_adc_nids,
4966                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4967                 .channel_mode = alc260_modes,
4968                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
4969                 .input_mux = alc260_test_capture_sources,
4970         },
4971 #endif
4972 };
4973
4974 static int patch_alc260(struct hda_codec *codec)
4975 {
4976         struct alc_spec *spec;
4977         int err, board_config;
4978
4979         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4980         if (spec == NULL)
4981                 return -ENOMEM;
4982
4983         codec->spec = spec;
4984
4985         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
4986                                                   alc260_models,
4987                                                   alc260_cfg_tbl);
4988         if (board_config < 0) {
4989                 snd_printd(KERN_INFO "hda_codec: Unknown model for ALC260, "
4990                            "trying auto-probe from BIOS...\n");
4991                 board_config = ALC260_AUTO;
4992         }
4993
4994         if (board_config == ALC260_AUTO) {
4995                 /* automatic parse from the BIOS config */
4996                 err = alc260_parse_auto_config(codec);
4997                 if (err < 0) {
4998                         alc_free(codec);
4999                         return err;
5000                 } else if (!err) {
5001                         printk(KERN_INFO
5002                                "hda_codec: Cannot set up configuration "
5003                                "from BIOS.  Using base mode...\n");
5004                         board_config = ALC260_BASIC;
5005                 }
5006         }
5007
5008         if (board_config != ALC260_AUTO)
5009                 setup_preset(spec, &alc260_presets[board_config]);
5010
5011         spec->stream_name_analog = "ALC260 Analog";
5012         spec->stream_analog_playback = &alc260_pcm_analog_playback;
5013         spec->stream_analog_capture = &alc260_pcm_analog_capture;
5014
5015         spec->stream_name_digital = "ALC260 Digital";
5016         spec->stream_digital_playback = &alc260_pcm_digital_playback;
5017         spec->stream_digital_capture = &alc260_pcm_digital_capture;
5018
5019         spec->vmaster_nid = 0x08;
5020
5021         codec->patch_ops = alc_patch_ops;
5022         if (board_config == ALC260_AUTO)
5023                 spec->init_hook = alc260_auto_init;
5024 #ifdef CONFIG_SND_HDA_POWER_SAVE
5025         if (!spec->loopback.amplist)
5026                 spec->loopback.amplist = alc260_loopbacks;
5027 #endif
5028
5029         return 0;
5030 }
5031
5032
5033 /*
5034  * ALC882 support
5035  *
5036  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5037  * configuration.  Each pin widget can choose any input DACs and a mixer.
5038  * Each ADC is connected from a mixer of all inputs.  This makes possible
5039  * 6-channel independent captures.
5040  *
5041  * In addition, an independent DAC for the multi-playback (not used in this
5042  * driver yet).
5043  */
5044 #define ALC882_DIGOUT_NID       0x06
5045 #define ALC882_DIGIN_NID        0x0a
5046
5047 static struct hda_channel_mode alc882_ch_modes[1] = {
5048         { 8, NULL }
5049 };
5050
5051 static hda_nid_t alc882_dac_nids[4] = {
5052         /* front, rear, clfe, rear_surr */
5053         0x02, 0x03, 0x04, 0x05
5054 };
5055
5056 /* identical with ALC880 */
5057 #define alc882_adc_nids         alc880_adc_nids
5058 #define alc882_adc_nids_alt     alc880_adc_nids_alt
5059
5060 /* input MUX */
5061 /* FIXME: should be a matrix-type input source selection */
5062
5063 static struct hda_input_mux alc882_capture_source = {
5064         .num_items = 4,
5065         .items = {
5066                 { "Mic", 0x0 },
5067                 { "Front Mic", 0x1 },
5068                 { "Line", 0x2 },
5069                 { "CD", 0x4 },
5070         },
5071 };
5072 #define alc882_mux_enum_info alc_mux_enum_info
5073 #define alc882_mux_enum_get alc_mux_enum_get
5074
5075 static int alc882_mux_enum_put(struct snd_kcontrol *kcontrol,
5076                                struct snd_ctl_elem_value *ucontrol)
5077 {
5078         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5079         struct alc_spec *spec = codec->spec;
5080         const struct hda_input_mux *imux = spec->input_mux;
5081         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
5082         static hda_nid_t capture_mixers[3] = { 0x24, 0x23, 0x22 };
5083         hda_nid_t nid = capture_mixers[adc_idx];
5084         unsigned int *cur_val = &spec->cur_mux[adc_idx];
5085         unsigned int i, idx;
5086
5087         idx = ucontrol->value.enumerated.item[0];
5088         if (idx >= imux->num_items)
5089                 idx = imux->num_items - 1;
5090         if (*cur_val == idx)
5091                 return 0;
5092         for (i = 0; i < imux->num_items; i++) {
5093                 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
5094                 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
5095                                          imux->items[i].index,
5096                                          HDA_AMP_MUTE, v);
5097         }
5098         *cur_val = idx;
5099         return 1;
5100 }
5101
5102 /*
5103  * 2ch mode
5104  */
5105 static struct hda_verb alc882_3ST_ch2_init[] = {
5106         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
5107         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5108         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5109         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5110         { } /* end */
5111 };
5112
5113 /*
5114  * 6ch mode
5115  */
5116 static struct hda_verb alc882_3ST_ch6_init[] = {
5117         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5118         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5119         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
5120         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5121         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5122         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5123         { } /* end */
5124 };
5125
5126 static struct hda_channel_mode alc882_3ST_6ch_modes[2] = {
5127         { 2, alc882_3ST_ch2_init },
5128         { 6, alc882_3ST_ch6_init },
5129 };
5130
5131 /*
5132  * 6ch mode
5133  */
5134 static struct hda_verb alc882_sixstack_ch6_init[] = {
5135         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
5136         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5137         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5138         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5139         { } /* end */
5140 };
5141
5142 /*
5143  * 8ch mode
5144  */
5145 static struct hda_verb alc882_sixstack_ch8_init[] = {
5146         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5147         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5148         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5149         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5150         { } /* end */
5151 };
5152
5153 static struct hda_channel_mode alc882_sixstack_modes[2] = {
5154         { 6, alc882_sixstack_ch6_init },
5155         { 8, alc882_sixstack_ch8_init },
5156 };
5157
5158 /*
5159  * macbook pro ALC885 can switch LineIn to LineOut without loosing Mic
5160  */
5161
5162 /*
5163  * 2ch mode
5164  */
5165 static struct hda_verb alc885_mbp_ch2_init[] = {
5166         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5167         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5168         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5169         { } /* end */
5170 };
5171
5172 /*
5173  * 6ch mode
5174  */
5175 static struct hda_verb alc885_mbp_ch6_init[] = {
5176         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5177         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5178         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5179         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5180         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5181         { } /* end */
5182 };
5183
5184 static struct hda_channel_mode alc885_mbp_6ch_modes[2] = {
5185         { 2, alc885_mbp_ch2_init },
5186         { 6, alc885_mbp_ch6_init },
5187 };
5188
5189
5190 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
5191  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
5192  */
5193 static struct snd_kcontrol_new alc882_base_mixer[] = {
5194         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5195         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5196         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
5197         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
5198         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
5199         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
5200         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
5201         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
5202         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
5203         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
5204         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5205         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5206         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5207         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5208         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5209         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5210         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5211         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5212         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5213         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5214         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5215         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5216         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5217         { } /* end */
5218 };
5219
5220 static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
5221         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
5222         HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
5223         HDA_CODEC_MUTE  ("Speaker Playback Switch", 0x14, 0x00, HDA_OUTPUT),
5224         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
5225         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5226         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5227         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
5228         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
5229         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
5230         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
5231         { } /* end */
5232 };
5233 static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
5234         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5235         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5236         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5237         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5238         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5239         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5240         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5241         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5242         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5243         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5244         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5245         { } /* end */
5246 };
5247
5248 static struct snd_kcontrol_new alc882_targa_mixer[] = {
5249         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5250         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5251         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5252         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5253         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5254         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5255         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5256         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5257         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5258         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5259         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5260         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5261         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5262         { } /* end */
5263 };
5264
5265 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
5266  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
5267  */
5268 static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
5269         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5270         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
5271         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5272         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
5273         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5274         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5275         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5276         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5277         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
5278         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
5279         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5280         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5281         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5282         { } /* end */
5283 };
5284
5285 static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
5286         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5287         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5288         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5289         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5290         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5291         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5292         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5293         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5294         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5295         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5296         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5297         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5298         { } /* end */
5299 };
5300
5301 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
5302         {
5303                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5304                 .name = "Channel Mode",
5305                 .info = alc_ch_mode_info,
5306                 .get = alc_ch_mode_get,
5307                 .put = alc_ch_mode_put,
5308         },
5309         { } /* end */
5310 };
5311
5312 static struct hda_verb alc882_init_verbs[] = {
5313         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5314         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5315         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5316         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5317         /* Rear mixer */
5318         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5319         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5320         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5321         /* CLFE mixer */
5322         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5323         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5324         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5325         /* Side mixer */
5326         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5327         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5328         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5329
5330         /* Front Pin: output 0 (0x0c) */
5331         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5332         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5333         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5334         /* Rear Pin: output 1 (0x0d) */
5335         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5336         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5337         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5338         /* CLFE Pin: output 2 (0x0e) */
5339         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5340         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5341         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
5342         /* Side Pin: output 3 (0x0f) */
5343         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5344         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5345         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
5346         /* Mic (rear) pin: input vref at 80% */
5347         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5348         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5349         /* Front Mic pin: input vref at 80% */
5350         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5351         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5352         /* Line In pin: input */
5353         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5354         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5355         /* Line-2 In: Headphone output (output 0 - 0x0c) */
5356         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5357         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5358         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
5359         /* CD pin widget for input */
5360         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5361
5362         /* FIXME: use matrix-type input source selection */
5363         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5364         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5365         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5366         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5367         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5368         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5369         /* Input mixer2 */
5370         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5371         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5372         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5373         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5374         /* Input mixer3 */
5375         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5376         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5377         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5378         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5379         /* ADC1: mute amp left and right */
5380         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5381         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5382         /* ADC2: mute amp left and right */
5383         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5384         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5385         /* ADC3: mute amp left and right */
5386         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5387         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5388
5389         { }
5390 };
5391
5392 static struct hda_verb alc882_eapd_verbs[] = {
5393         /* change to EAPD mode */
5394         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
5395         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
5396         { }
5397 };
5398
5399 /* Mac Pro test */
5400 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
5401         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5402         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5403         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
5404         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
5405         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
5406         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT),
5407         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT),
5408         { } /* end */
5409 };
5410
5411 static struct hda_verb alc882_macpro_init_verbs[] = {
5412         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5413         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5414         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5415         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5416         /* Front Pin: output 0 (0x0c) */
5417         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5418         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5419         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
5420         /* Front Mic pin: input vref at 80% */
5421         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5422         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5423         /* Speaker:  output */
5424         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5425         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5426         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
5427         /* Headphone output (output 0 - 0x0c) */
5428         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5429         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5430         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
5431
5432         /* FIXME: use matrix-type input source selection */
5433         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5434         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5435         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5436         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5437         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5438         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5439         /* Input mixer2 */
5440         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5441         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5442         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5443         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5444         /* Input mixer3 */
5445         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5446         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5447         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5448         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5449         /* ADC1: mute amp left and right */
5450         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5451         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5452         /* ADC2: mute amp left and right */
5453         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5454         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5455         /* ADC3: mute amp left and right */
5456         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5457         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5458
5459         { }
5460 };
5461
5462 /* Macbook Pro rev3 */
5463 static struct hda_verb alc885_mbp3_init_verbs[] = {
5464         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5465         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5466         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5467         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5468         /* Rear mixer */
5469         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5470         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5471         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5472         /* Front Pin: output 0 (0x0c) */
5473         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5474         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5475         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5476         /* HP Pin: output 0 (0x0d) */
5477         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
5478         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5479         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
5480         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5481         /* Mic (rear) pin: input vref at 80% */
5482         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5483         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5484         /* Front Mic pin: input vref at 80% */
5485         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5486         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5487         /* Line In pin: use output 1 when in LineOut mode */
5488         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5489         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5490         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
5491
5492         /* FIXME: use matrix-type input source selection */
5493         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5494         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5495         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5496         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5497         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5498         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5499         /* Input mixer2 */
5500         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5501         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5502         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5503         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5504         /* Input mixer3 */
5505         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5506         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5507         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5508         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5509         /* ADC1: mute amp left and right */
5510         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5511         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5512         /* ADC2: mute amp left and right */
5513         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5514         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5515         /* ADC3: mute amp left and right */
5516         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5517         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5518
5519         { }
5520 };
5521
5522 /* iMac 24 mixer. */
5523 static struct snd_kcontrol_new alc885_imac24_mixer[] = {
5524         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
5525         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
5526         { } /* end */
5527 };
5528
5529 /* iMac 24 init verbs. */
5530 static struct hda_verb alc885_imac24_init_verbs[] = {
5531         /* Internal speakers: output 0 (0x0c) */
5532         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5533         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5534         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
5535         /* Internal speakers: output 0 (0x0c) */
5536         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5537         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5538         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
5539         /* Headphone: output 0 (0x0c) */
5540         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5541         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5542         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5543         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5544         /* Front Mic: input vref at 80% */
5545         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5546         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5547         { }
5548 };
5549
5550 /* Toggle speaker-output according to the hp-jack state */
5551 static void alc885_imac24_automute(struct hda_codec *codec)
5552 {
5553         unsigned int present;
5554
5555         present = snd_hda_codec_read(codec, 0x14, 0,
5556                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5557         snd_hda_codec_amp_stereo(codec, 0x18, HDA_OUTPUT, 0,
5558                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5559         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
5560                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5561 }
5562
5563 /* Processes unsolicited events. */
5564 static void alc885_imac24_unsol_event(struct hda_codec *codec,
5565                                       unsigned int res)
5566 {
5567         /* Headphone insertion or removal. */
5568         if ((res >> 26) == ALC880_HP_EVENT)
5569                 alc885_imac24_automute(codec);
5570 }
5571
5572 static void alc885_mbp3_automute(struct hda_codec *codec)
5573 {
5574         unsigned int present;
5575
5576         present = snd_hda_codec_read(codec, 0x15, 0,
5577                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5578         snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
5579                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5580         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
5581                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
5582
5583 }
5584 static void alc885_mbp3_unsol_event(struct hda_codec *codec,
5585                                     unsigned int res)
5586 {
5587         /* Headphone insertion or removal. */
5588         if ((res >> 26) == ALC880_HP_EVENT)
5589                 alc885_mbp3_automute(codec);
5590 }
5591
5592
5593 static struct hda_verb alc882_targa_verbs[] = {
5594         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5595         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5596
5597         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5598         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5599         
5600         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
5601         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
5602         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5603
5604         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5605         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5606         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
5607         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
5608         { } /* end */
5609 };
5610
5611 /* toggle speaker-output according to the hp-jack state */
5612 static void alc882_targa_automute(struct hda_codec *codec)
5613 {
5614         unsigned int present;
5615  
5616         present = snd_hda_codec_read(codec, 0x14, 0,
5617                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5618         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
5619                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5620         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
5621                                   present ? 1 : 3);
5622 }
5623
5624 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
5625 {
5626         /* Looks like the unsol event is incompatible with the standard
5627          * definition.  4bit tag is placed at 26 bit!
5628          */
5629         if (((res >> 26) == ALC880_HP_EVENT)) {
5630                 alc882_targa_automute(codec);
5631         }
5632 }
5633
5634 static struct hda_verb alc882_asus_a7j_verbs[] = {
5635         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5636         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5637
5638         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5639         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5640         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5641         
5642         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5643         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5644         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5645
5646         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
5647         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
5648         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5649         { } /* end */
5650 };
5651
5652 static struct hda_verb alc882_asus_a7m_verbs[] = {
5653         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5654         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5655
5656         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5657         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5658         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5659         
5660         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5661         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5662         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5663
5664         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
5665         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
5666         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5667         { } /* end */
5668 };
5669
5670 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5671 {
5672         unsigned int gpiostate, gpiomask, gpiodir;
5673
5674         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5675                                        AC_VERB_GET_GPIO_DATA, 0);
5676
5677         if (!muted)
5678                 gpiostate |= (1 << pin);
5679         else
5680                 gpiostate &= ~(1 << pin);
5681
5682         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5683                                       AC_VERB_GET_GPIO_MASK, 0);
5684         gpiomask |= (1 << pin);
5685
5686         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5687                                      AC_VERB_GET_GPIO_DIRECTION, 0);
5688         gpiodir |= (1 << pin);
5689
5690
5691         snd_hda_codec_write(codec, codec->afg, 0,
5692                             AC_VERB_SET_GPIO_MASK, gpiomask);
5693         snd_hda_codec_write(codec, codec->afg, 0,
5694                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5695
5696         msleep(1);
5697
5698         snd_hda_codec_write(codec, codec->afg, 0,
5699                             AC_VERB_SET_GPIO_DATA, gpiostate);
5700 }
5701
5702 /* set up GPIO at initialization */
5703 static void alc885_macpro_init_hook(struct hda_codec *codec)
5704 {
5705         alc882_gpio_mute(codec, 0, 0);
5706         alc882_gpio_mute(codec, 1, 0);
5707 }
5708
5709 /* set up GPIO and update auto-muting at initialization */
5710 static void alc885_imac24_init_hook(struct hda_codec *codec)
5711 {
5712         alc885_macpro_init_hook(codec);
5713         alc885_imac24_automute(codec);
5714 }
5715
5716 /*
5717  * generic initialization of ADC, input mixers and output mixers
5718  */
5719 static struct hda_verb alc882_auto_init_verbs[] = {
5720         /*
5721          * Unmute ADC0-2 and set the default input to mic-in
5722          */
5723         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5724         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5725         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5726         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5727         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5728         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5729
5730         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5731          * mixer widget
5732          * Note: PASD motherboards uses the Line In 2 as the input for
5733          * front panel mic (mic 2)
5734          */
5735         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
5736         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5737         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5738         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5739         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5740         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5741
5742         /*
5743          * Set up output mixers (0x0c - 0x0f)
5744          */
5745         /* set vol=0 to output mixers */
5746         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5747         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5748         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5749         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5750         /* set up input amps for analog loopback */
5751         /* Amp Indices: DAC = 0, mixer = 1 */
5752         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5753         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5754         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5755         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5756         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5757         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5758         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5759         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5760         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5761         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5762
5763         /* FIXME: use matrix-type input source selection */
5764         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5765         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5766         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5767         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
5768         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
5769         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
5770         /* Input mixer2 */
5771         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5772         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
5773         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
5774         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
5775         /* Input mixer3 */
5776         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5777         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
5778         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
5779         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
5780
5781         { }
5782 };
5783
5784 /* capture mixer elements */
5785 static struct snd_kcontrol_new alc882_capture_alt_mixer[] = {
5786         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
5787         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
5788         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
5789         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
5790         {
5791                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5792                 /* The multiple "Capture Source" controls confuse alsamixer
5793                  * So call somewhat different..
5794                  */
5795                 /* .name = "Capture Source", */
5796                 .name = "Input Source",
5797                 .count = 2,
5798                 .info = alc882_mux_enum_info,
5799                 .get = alc882_mux_enum_get,
5800                 .put = alc882_mux_enum_put,
5801         },
5802         { } /* end */
5803 };
5804
5805 static struct snd_kcontrol_new alc882_capture_mixer[] = {
5806         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
5807         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
5808         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
5809         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
5810         HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
5811         HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
5812         {
5813                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5814                 /* The multiple "Capture Source" controls confuse alsamixer
5815                  * So call somewhat different..
5816                  */
5817                 /* .name = "Capture Source", */
5818                 .name = "Input Source",
5819                 .count = 3,
5820                 .info = alc882_mux_enum_info,
5821                 .get = alc882_mux_enum_get,
5822                 .put = alc882_mux_enum_put,
5823         },
5824         { } /* end */
5825 };
5826
5827 #ifdef CONFIG_SND_HDA_POWER_SAVE
5828 #define alc882_loopbacks        alc880_loopbacks
5829 #endif
5830
5831 /* pcm configuration: identiacal with ALC880 */
5832 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
5833 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
5834 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
5835 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
5836
5837 /*
5838  * configuration and preset
5839  */
5840 static const char *alc882_models[ALC882_MODEL_LAST] = {
5841         [ALC882_3ST_DIG]        = "3stack-dig",
5842         [ALC882_6ST_DIG]        = "6stack-dig",
5843         [ALC882_ARIMA]          = "arima",
5844         [ALC882_W2JC]           = "w2jc",
5845         [ALC882_TARGA]          = "targa",
5846         [ALC882_ASUS_A7J]       = "asus-a7j",
5847         [ALC882_ASUS_A7M]       = "asus-a7m",
5848         [ALC885_MACPRO]         = "macpro",
5849         [ALC885_MBP3]           = "mbp3",
5850         [ALC885_IMAC24]         = "imac24",
5851         [ALC882_AUTO]           = "auto",
5852 };
5853
5854 static struct snd_pci_quirk alc882_cfg_tbl[] = {
5855         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
5856         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
5857         SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
5858         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
5859         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
5860         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
5861         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
5862         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
5863         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
5864         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
5865         SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA),
5866         {}
5867 };
5868
5869 static struct alc_config_preset alc882_presets[] = {
5870         [ALC882_3ST_DIG] = {
5871                 .mixers = { alc882_base_mixer },
5872                 .init_verbs = { alc882_init_verbs },
5873                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5874                 .dac_nids = alc882_dac_nids,
5875                 .dig_out_nid = ALC882_DIGOUT_NID,
5876                 .dig_in_nid = ALC882_DIGIN_NID,
5877                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
5878                 .channel_mode = alc882_ch_modes,
5879                 .need_dac_fix = 1,
5880                 .input_mux = &alc882_capture_source,
5881         },
5882         [ALC882_6ST_DIG] = {
5883                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
5884                 .init_verbs = { alc882_init_verbs },
5885                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5886                 .dac_nids = alc882_dac_nids,
5887                 .dig_out_nid = ALC882_DIGOUT_NID,
5888                 .dig_in_nid = ALC882_DIGIN_NID,
5889                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
5890                 .channel_mode = alc882_sixstack_modes,
5891                 .input_mux = &alc882_capture_source,
5892         },
5893         [ALC882_ARIMA] = {
5894                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
5895                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs },
5896                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5897                 .dac_nids = alc882_dac_nids,
5898                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
5899                 .channel_mode = alc882_sixstack_modes,
5900                 .input_mux = &alc882_capture_source,
5901         },
5902         [ALC882_W2JC] = {
5903                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
5904                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
5905                                 alc880_gpio1_init_verbs },
5906                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5907                 .dac_nids = alc882_dac_nids,
5908                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
5909                 .channel_mode = alc880_threestack_modes,
5910                 .need_dac_fix = 1,
5911                 .input_mux = &alc882_capture_source,
5912                 .dig_out_nid = ALC882_DIGOUT_NID,
5913         },
5914         [ALC885_MBP3] = {
5915                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
5916                 .init_verbs = { alc885_mbp3_init_verbs,
5917                                 alc880_gpio1_init_verbs },
5918                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5919                 .dac_nids = alc882_dac_nids,
5920                 .channel_mode = alc885_mbp_6ch_modes,
5921                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_6ch_modes),
5922                 .input_mux = &alc882_capture_source,
5923                 .dig_out_nid = ALC882_DIGOUT_NID,
5924                 .dig_in_nid = ALC882_DIGIN_NID,
5925                 .unsol_event = alc885_mbp3_unsol_event,
5926                 .init_hook = alc885_mbp3_automute,
5927         },
5928         [ALC885_MACPRO] = {
5929                 .mixers = { alc882_macpro_mixer },
5930                 .init_verbs = { alc882_macpro_init_verbs },
5931                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5932                 .dac_nids = alc882_dac_nids,
5933                 .dig_out_nid = ALC882_DIGOUT_NID,
5934                 .dig_in_nid = ALC882_DIGIN_NID,
5935                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
5936                 .channel_mode = alc882_ch_modes,
5937                 .input_mux = &alc882_capture_source,
5938                 .init_hook = alc885_macpro_init_hook,
5939         },
5940         [ALC885_IMAC24] = {
5941                 .mixers = { alc885_imac24_mixer },
5942                 .init_verbs = { alc885_imac24_init_verbs },
5943                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5944                 .dac_nids = alc882_dac_nids,
5945                 .dig_out_nid = ALC882_DIGOUT_NID,
5946                 .dig_in_nid = ALC882_DIGIN_NID,
5947                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
5948                 .channel_mode = alc882_ch_modes,
5949                 .input_mux = &alc882_capture_source,
5950                 .unsol_event = alc885_imac24_unsol_event,
5951                 .init_hook = alc885_imac24_init_hook,
5952         },
5953         [ALC882_TARGA] = {
5954                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer,
5955                             alc882_capture_mixer },
5956                 .init_verbs = { alc882_init_verbs, alc882_targa_verbs},
5957                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5958                 .dac_nids = alc882_dac_nids,
5959                 .dig_out_nid = ALC882_DIGOUT_NID,
5960                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
5961                 .adc_nids = alc882_adc_nids,
5962                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
5963                 .channel_mode = alc882_3ST_6ch_modes,
5964                 .need_dac_fix = 1,
5965                 .input_mux = &alc882_capture_source,
5966                 .unsol_event = alc882_targa_unsol_event,
5967                 .init_hook = alc882_targa_automute,
5968         },
5969         [ALC882_ASUS_A7J] = {
5970                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer,
5971                             alc882_capture_mixer },
5972                 .init_verbs = { alc882_init_verbs, alc882_asus_a7j_verbs},
5973                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5974                 .dac_nids = alc882_dac_nids,
5975                 .dig_out_nid = ALC882_DIGOUT_NID,
5976                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
5977                 .adc_nids = alc882_adc_nids,
5978                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
5979                 .channel_mode = alc882_3ST_6ch_modes,
5980                 .need_dac_fix = 1,
5981                 .input_mux = &alc882_capture_source,
5982         },      
5983         [ALC882_ASUS_A7M] = {
5984                 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
5985                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
5986                                 alc880_gpio1_init_verbs,
5987                                 alc882_asus_a7m_verbs },
5988                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5989                 .dac_nids = alc882_dac_nids,
5990                 .dig_out_nid = ALC882_DIGOUT_NID,
5991                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
5992                 .channel_mode = alc880_threestack_modes,
5993                 .need_dac_fix = 1,
5994                 .input_mux = &alc882_capture_source,
5995         },      
5996 };
5997
5998
5999 /*
6000  * Pin config fixes
6001  */
6002 enum { 
6003         PINFIX_ABIT_AW9D_MAX
6004 };
6005
6006 static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
6007         { 0x15, 0x01080104 }, /* side */
6008         { 0x16, 0x01011012 }, /* rear */
6009         { 0x17, 0x01016011 }, /* clfe */
6010         { }
6011 };
6012
6013 static const struct alc_pincfg *alc882_pin_fixes[] = {
6014         [PINFIX_ABIT_AW9D_MAX] = alc882_abit_aw9d_pinfix,
6015 };
6016
6017 static struct snd_pci_quirk alc882_pinfix_tbl[] = {
6018         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
6019         {}
6020 };
6021
6022 /*
6023  * BIOS auto configuration
6024  */
6025 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
6026                                               hda_nid_t nid, int pin_type,
6027                                               int dac_idx)
6028 {
6029         /* set as output */
6030         struct alc_spec *spec = codec->spec;
6031         int idx;
6032
6033         if (spec->multiout.dac_nids[dac_idx] == 0x25)
6034                 idx = 4;
6035         else
6036                 idx = spec->multiout.dac_nids[dac_idx] - 2;
6037
6038         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
6039                             pin_type);
6040         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
6041                             AMP_OUT_UNMUTE);
6042         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
6043
6044 }
6045
6046 static void alc882_auto_init_multi_out(struct hda_codec *codec)
6047 {
6048         struct alc_spec *spec = codec->spec;
6049         int i;
6050
6051         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
6052         for (i = 0; i <= HDA_SIDE; i++) {
6053                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
6054                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
6055                 if (nid)
6056                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
6057                                                           i);
6058         }
6059 }
6060
6061 static void alc882_auto_init_hp_out(struct hda_codec *codec)
6062 {
6063         struct alc_spec *spec = codec->spec;
6064         hda_nid_t pin;
6065
6066         pin = spec->autocfg.hp_pins[0];
6067         if (pin) /* connect to front */
6068                 /* use dac 0 */
6069                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
6070 }
6071
6072 #define alc882_is_input_pin(nid)        alc880_is_input_pin(nid)
6073 #define ALC882_PIN_CD_NID               ALC880_PIN_CD_NID
6074
6075 static void alc882_auto_init_analog_input(struct hda_codec *codec)
6076 {
6077         struct alc_spec *spec = codec->spec;
6078         int i;
6079
6080         for (i = 0; i < AUTO_PIN_LAST; i++) {
6081                 hda_nid_t nid = spec->autocfg.input_pins[i];
6082                 if (alc882_is_input_pin(nid)) {
6083                         snd_hda_codec_write(codec, nid, 0,
6084                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
6085                                             i <= AUTO_PIN_FRONT_MIC ?
6086                                             PIN_VREF80 : PIN_IN);
6087                         if (nid != ALC882_PIN_CD_NID)
6088                                 snd_hda_codec_write(codec, nid, 0,
6089                                                     AC_VERB_SET_AMP_GAIN_MUTE,
6090                                                     AMP_OUT_MUTE);
6091                 }
6092         }
6093 }
6094
6095 /* add mic boosts if needed */
6096 static int alc_auto_add_mic_boost(struct hda_codec *codec)
6097 {
6098         struct alc_spec *spec = codec->spec;
6099         int err;
6100         hda_nid_t nid;
6101
6102         nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
6103         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6104                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6105                                   "Mic Boost",
6106                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6107                 if (err < 0)
6108                         return err;
6109         }
6110         nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
6111         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6112                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6113                                   "Front Mic Boost",
6114                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6115                 if (err < 0)
6116                         return err;
6117         }
6118         return 0;
6119 }
6120
6121 /* almost identical with ALC880 parser... */
6122 static int alc882_parse_auto_config(struct hda_codec *codec)
6123 {
6124         struct alc_spec *spec = codec->spec;
6125         int err = alc880_parse_auto_config(codec);
6126
6127         if (err < 0)
6128                 return err;
6129         else if (!err)
6130                 return 0; /* no config found */
6131
6132         err = alc_auto_add_mic_boost(codec);
6133         if (err < 0)
6134                 return err;
6135
6136         /* hack - override the init verbs */
6137         spec->init_verbs[0] = alc882_auto_init_verbs;
6138
6139         return 1; /* config found */
6140 }
6141
6142 /* additional initialization for auto-configuration model */
6143 static void alc882_auto_init(struct hda_codec *codec)
6144 {
6145         alc882_auto_init_multi_out(codec);
6146         alc882_auto_init_hp_out(codec);
6147         alc882_auto_init_analog_input(codec);
6148 }
6149
6150 static int patch_alc882(struct hda_codec *codec)
6151 {
6152         struct alc_spec *spec;
6153         int err, board_config;
6154
6155         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6156         if (spec == NULL)
6157                 return -ENOMEM;
6158
6159         codec->spec = spec;
6160
6161         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
6162                                                   alc882_models,
6163                                                   alc882_cfg_tbl);
6164
6165         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
6166                 /* Pick up systems that don't supply PCI SSID */
6167                 switch (codec->subsystem_id) {
6168                 case 0x106b0c00: /* Mac Pro */
6169                         board_config = ALC885_MACPRO;
6170                         break;
6171                 case 0x106b1000: /* iMac 24 */
6172                         board_config = ALC885_IMAC24;
6173                         break;
6174                 case 0x106b00a1: /* Macbook */
6175                 case 0x106b2c00: /* Macbook Pro rev3 */
6176                         board_config = ALC885_MBP3;
6177                         break;
6178                 default:
6179                         printk(KERN_INFO "hda_codec: Unknown model for ALC882, "
6180                                          "trying auto-probe from BIOS...\n");
6181                         board_config = ALC882_AUTO;
6182                 }
6183         }
6184
6185         alc_fix_pincfg(codec, alc882_pinfix_tbl, alc882_pin_fixes);
6186
6187         if (board_config == ALC882_AUTO) {
6188                 /* automatic parse from the BIOS config */
6189                 err = alc882_parse_auto_config(codec);
6190                 if (err < 0) {
6191                         alc_free(codec);
6192                         return err;
6193                 } else if (!err) {
6194                         printk(KERN_INFO
6195                                "hda_codec: Cannot set up configuration "
6196                                "from BIOS.  Using base mode...\n");
6197                         board_config = ALC882_3ST_DIG;
6198                 }
6199         }
6200
6201         if (board_config != ALC882_AUTO)
6202                 setup_preset(spec, &alc882_presets[board_config]);
6203
6204         spec->stream_name_analog = "ALC882 Analog";
6205         spec->stream_analog_playback = &alc882_pcm_analog_playback;
6206         spec->stream_analog_capture = &alc882_pcm_analog_capture;
6207
6208         spec->stream_name_digital = "ALC882 Digital";
6209         spec->stream_digital_playback = &alc882_pcm_digital_playback;
6210         spec->stream_digital_capture = &alc882_pcm_digital_capture;
6211
6212         if (!spec->adc_nids && spec->input_mux) {
6213                 /* check whether NID 0x07 is valid */
6214                 unsigned int wcap = get_wcaps(codec, 0x07);
6215                 /* get type */
6216                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
6217                 if (wcap != AC_WID_AUD_IN) {
6218                         spec->adc_nids = alc882_adc_nids_alt;
6219                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
6220                         spec->mixers[spec->num_mixers] =
6221                                 alc882_capture_alt_mixer;
6222                         spec->num_mixers++;
6223                 } else {
6224                         spec->adc_nids = alc882_adc_nids;
6225                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
6226                         spec->mixers[spec->num_mixers] = alc882_capture_mixer;
6227                         spec->num_mixers++;
6228                 }
6229         }
6230
6231         spec->vmaster_nid = 0x0c;
6232
6233         codec->patch_ops = alc_patch_ops;
6234         if (board_config == ALC882_AUTO)
6235                 spec->init_hook = alc882_auto_init;
6236 #ifdef CONFIG_SND_HDA_POWER_SAVE
6237         if (!spec->loopback.amplist)
6238                 spec->loopback.amplist = alc882_loopbacks;
6239 #endif
6240
6241         return 0;
6242 }
6243
6244 /*
6245  * ALC883 support
6246  *
6247  * ALC883 is almost identical with ALC880 but has cleaner and more flexible
6248  * configuration.  Each pin widget can choose any input DACs and a mixer.
6249  * Each ADC is connected from a mixer of all inputs.  This makes possible
6250  * 6-channel independent captures.
6251  *
6252  * In addition, an independent DAC for the multi-playback (not used in this
6253  * driver yet).
6254  */
6255 #define ALC883_DIGOUT_NID       0x06
6256 #define ALC883_DIGIN_NID        0x0a
6257
6258 static hda_nid_t alc883_dac_nids[4] = {
6259         /* front, rear, clfe, rear_surr */
6260         0x02, 0x04, 0x03, 0x05
6261 };
6262
6263 static hda_nid_t alc883_adc_nids[2] = {
6264         /* ADC1-2 */
6265         0x08, 0x09,
6266 };
6267
6268 /* input MUX */
6269 /* FIXME: should be a matrix-type input source selection */
6270
6271 static struct hda_input_mux alc883_capture_source = {
6272         .num_items = 4,
6273         .items = {
6274                 { "Mic", 0x0 },
6275                 { "Front Mic", 0x1 },
6276                 { "Line", 0x2 },
6277                 { "CD", 0x4 },
6278         },
6279 };
6280
6281 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
6282         .num_items = 2,
6283         .items = {
6284                 { "Mic", 0x1 },
6285                 { "Line", 0x2 },
6286         },
6287 };
6288
6289 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
6290         .num_items = 4,
6291         .items = {
6292                 { "Mic", 0x0 },
6293                 { "iMic", 0x1 },
6294                 { "Line", 0x2 },
6295                 { "CD", 0x4 },
6296         },
6297 };
6298
6299 #define alc883_mux_enum_info alc_mux_enum_info
6300 #define alc883_mux_enum_get alc_mux_enum_get
6301
6302 static int alc883_mux_enum_put(struct snd_kcontrol *kcontrol,
6303                                struct snd_ctl_elem_value *ucontrol)
6304 {
6305         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6306         struct alc_spec *spec = codec->spec;
6307         const struct hda_input_mux *imux = spec->input_mux;
6308         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
6309         static hda_nid_t capture_mixers[3] = { 0x24, 0x23, 0x22 };
6310         hda_nid_t nid = capture_mixers[adc_idx];
6311         unsigned int *cur_val = &spec->cur_mux[adc_idx];
6312         unsigned int i, idx;
6313
6314         idx = ucontrol->value.enumerated.item[0];
6315         if (idx >= imux->num_items)
6316                 idx = imux->num_items - 1;
6317         if (*cur_val == idx)
6318                 return 0;
6319         for (i = 0; i < imux->num_items; i++) {
6320                 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
6321                 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
6322                                          imux->items[i].index,
6323                                          HDA_AMP_MUTE, v);
6324         }
6325         *cur_val = idx;
6326         return 1;
6327 }
6328
6329 /*
6330  * 2ch mode
6331  */
6332 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
6333         { 2, NULL }
6334 };
6335
6336 /*
6337  * 2ch mode
6338  */
6339 static struct hda_verb alc883_3ST_ch2_init[] = {
6340         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6341         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6342         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6343         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6344         { } /* end */
6345 };
6346
6347 /*
6348  * 4ch mode
6349  */
6350 static struct hda_verb alc883_3ST_ch4_init[] = {
6351         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6352         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6353         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6354         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6355         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6356         { } /* end */
6357 };
6358
6359 /*
6360  * 6ch mode
6361  */
6362 static struct hda_verb alc883_3ST_ch6_init[] = {
6363         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6364         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6365         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6366         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6367         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6368         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6369         { } /* end */
6370 };
6371
6372 static struct hda_channel_mode alc883_3ST_6ch_modes[3] = {
6373         { 2, alc883_3ST_ch2_init },
6374         { 4, alc883_3ST_ch4_init },
6375         { 6, alc883_3ST_ch6_init },
6376 };
6377
6378 /*
6379  * 6ch mode
6380  */
6381 static struct hda_verb alc883_sixstack_ch6_init[] = {
6382         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6383         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6384         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6385         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6386         { } /* end */
6387 };
6388
6389 /*
6390  * 8ch mode
6391  */
6392 static struct hda_verb alc883_sixstack_ch8_init[] = {
6393         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6394         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6395         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6396         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6397         { } /* end */
6398 };
6399
6400 static struct hda_channel_mode alc883_sixstack_modes[2] = {
6401         { 6, alc883_sixstack_ch6_init },
6402         { 8, alc883_sixstack_ch8_init },
6403 };
6404
6405 static struct hda_verb alc883_medion_eapd_verbs[] = {
6406         /* eanable EAPD on medion laptop */
6407         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
6408         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
6409         { }
6410 };
6411
6412 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
6413  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
6414  */
6415
6416 static struct snd_kcontrol_new alc883_base_mixer[] = {
6417         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6418         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6419         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6420         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6421         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6422         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6423         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6424         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6425         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6426         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6427         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6428         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6429         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6430         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6431         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6432         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6433         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6434         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6435         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6436         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6437         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6438         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6439         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6440         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6441         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6442         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6443         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6444         {
6445                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6446                 /* .name = "Capture Source", */
6447                 .name = "Input Source",
6448                 .count = 2,
6449                 .info = alc883_mux_enum_info,
6450                 .get = alc883_mux_enum_get,
6451                 .put = alc883_mux_enum_put,
6452         },
6453         { } /* end */
6454 };
6455
6456 static struct snd_kcontrol_new alc883_mitac_mixer[] = {
6457         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6458         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6459         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6460         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6461         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6462         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6463         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6464         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6465         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6466         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6467         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6468         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6469         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6470         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6471         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6472         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6473         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6474         {
6475                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6476                 /* .name = "Capture Source", */
6477                 .name = "Input Source",
6478                 .count = 2,
6479                 .info = alc883_mux_enum_info,
6480                 .get = alc883_mux_enum_get,
6481                 .put = alc883_mux_enum_put,
6482         },
6483         { } /* end */
6484 };
6485
6486 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
6487         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6488         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6489         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6490         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6491         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6492         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6493         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6494         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6495         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6496         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6497         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6498         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6499         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6500         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6501         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6502         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6503         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6504         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6505         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6506         {
6507                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6508                 /* .name = "Capture Source", */
6509                 .name = "Input Source",
6510                 .count = 2,
6511                 .info = alc883_mux_enum_info,
6512                 .get = alc883_mux_enum_get,
6513                 .put = alc883_mux_enum_put,
6514         },
6515         { } /* end */
6516 };
6517
6518 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
6519         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6520         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6521         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6522         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6523         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6524         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6525         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6526         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6527         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6528         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6529         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6530         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6531         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6532         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6533         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6534         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6535         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6536         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6537         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6538         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6539         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6540         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6541         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6542         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6543         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6544         {
6545                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6546                 /* .name = "Capture Source", */
6547                 .name = "Input Source",
6548                 .count = 2,
6549                 .info = alc883_mux_enum_info,
6550                 .get = alc883_mux_enum_get,
6551                 .put = alc883_mux_enum_put,
6552         },
6553         { } /* end */
6554 };
6555
6556 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
6557         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6558         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6559         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6560         HDA_CODEC_MUTE("Surround Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6561         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6562         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6563         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x16, 1, 0x0, HDA_OUTPUT),
6564         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
6565         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6566         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6567         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6568         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6569         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6570         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6571         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6572         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6573         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6574         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6575         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6576         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6577         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6578         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6579         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6580
6581         {
6582                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6583                 /* .name = "Capture Source", */
6584                 .name = "Input Source",
6585                 .count = 1,
6586                 .info = alc883_mux_enum_info,
6587                 .get = alc883_mux_enum_get,
6588                 .put = alc883_mux_enum_put,
6589         },
6590         { } /* end */
6591 };
6592
6593 static struct snd_kcontrol_new alc883_tagra_mixer[] = {
6594         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6595         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6596         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
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("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6604         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6605         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6606         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6607         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6608         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6609         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6610         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6611         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6612         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6613         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6614         {
6615                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6616                 /* .name = "Capture Source", */
6617                 .name = "Input Source",
6618                 .count = 2,
6619                 .info = alc883_mux_enum_info,
6620                 .get = alc883_mux_enum_get,
6621                 .put = alc883_mux_enum_put,
6622         },
6623         { } /* end */
6624 };
6625
6626 static struct snd_kcontrol_new alc883_tagra_2ch_mixer[] = {
6627         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6628         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6629         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6630         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6631         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6632         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6633         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6634         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6635         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6636         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6637         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6638         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6639         {
6640                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6641                 /* .name = "Capture Source", */
6642                 .name = "Input Source",
6643                 .count = 2,
6644                 .info = alc883_mux_enum_info,
6645                 .get = alc883_mux_enum_get,
6646                 .put = alc883_mux_enum_put,
6647         },
6648         { } /* end */
6649 };
6650
6651 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
6652         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6653         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6654         HDA_CODEC_VOLUME("iSpeaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6655         HDA_BIND_MUTE("iSpeaker Playback Switch", 0x0d, 2, HDA_INPUT),
6656         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6657         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6658         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6659         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6660         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6661         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6662         {
6663                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6664                 /* .name = "Capture Source", */
6665                 .name = "Input Source",
6666                 .count = 1,
6667                 .info = alc883_mux_enum_info,
6668                 .get = alc883_mux_enum_get,
6669                 .put = alc883_mux_enum_put,
6670         },
6671         { } /* end */
6672 };
6673
6674 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
6675         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6676         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
6677         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6678         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6679         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6680         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6681         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6682         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6683         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6684         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6685         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6686         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6687         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6688         {
6689                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6690                 /* .name = "Capture Source", */
6691                 .name = "Input Source",
6692                 .count = 2,
6693                 .info = alc883_mux_enum_info,
6694                 .get = alc883_mux_enum_get,
6695                 .put = alc883_mux_enum_put,
6696         },
6697         { } /* end */
6698 };
6699
6700 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
6701         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6702         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6703         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6704         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6705         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6706         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6707         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6708         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6709         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6710         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6711         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6712         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6713         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6714         {
6715                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6716                 /* .name = "Capture Source", */
6717                 .name = "Input Source",
6718                 .count = 2,
6719                 .info = alc883_mux_enum_info,
6720                 .get = alc883_mux_enum_get,
6721                 .put = alc883_mux_enum_put,
6722         },
6723         { } /* end */
6724 };      
6725
6726 static struct snd_kcontrol_new alc888_6st_hp_mixer[] = {
6727         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6728         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6729         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
6730         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
6731         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
6732         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
6733         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
6734         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
6735         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6736         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6737         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6738         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6739         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6740         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6741         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6742         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6743         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6744         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6745         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6746         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6747         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6748         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6749         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6750         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6751         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6752         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6753         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6754         {
6755                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6756                 /* .name = "Capture Source", */
6757                 .name = "Input Source",
6758                 .count = 2,
6759                 .info = alc883_mux_enum_info,
6760                 .get = alc883_mux_enum_get,
6761                 .put = alc883_mux_enum_put,
6762         },
6763         { } /* end */
6764 };
6765
6766 static struct snd_kcontrol_new alc888_3st_hp_mixer[] = {
6767         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6768         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6769         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
6770         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
6771         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
6772         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
6773         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
6774         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
6775         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6776         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6777         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6778         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6779         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6780         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6781         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6782         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6783         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6784         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6785         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6786         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6787         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6788         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6789         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6790         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6791         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6792         {
6793                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6794                 /* .name = "Capture Source", */
6795                 .name = "Input Source",
6796                 .count = 2,
6797                 .info = alc883_mux_enum_info,
6798                 .get = alc883_mux_enum_get,
6799                 .put = alc883_mux_enum_put,
6800         },
6801         { } /* end */
6802 };
6803
6804 static struct snd_kcontrol_new alc888_6st_dell_mixer[] = {
6805         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6806         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6807         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
6808         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
6809         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
6810         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
6811         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
6812         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
6813         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6814         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6815         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6816         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6817         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6818         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6819         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6820         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6821         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6822         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6823         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6824         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6825         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6826         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6827         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6828         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6829         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6830         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6831         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6832         {
6833                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6834                 /* .name = "Capture Source", */
6835                 .name = "Input Source",
6836                 .count = 2,
6837                 .info = alc883_mux_enum_info,
6838                 .get = alc883_mux_enum_get,
6839                 .put = alc883_mux_enum_put,
6840         },
6841         { } /* end */
6842 };
6843
6844 static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
6845         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6846         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6847         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6848         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6849         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6850         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6851         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6852         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6853         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6854         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6855         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6856         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6857         {
6858                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6859                 /* .name = "Capture Source", */
6860                 .name = "Input Source",
6861                 .count = 2,
6862                 .info = alc883_mux_enum_info,
6863                 .get = alc883_mux_enum_get,
6864                 .put = alc883_mux_enum_put,
6865         },
6866         { } /* end */
6867 };
6868
6869 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
6870         {
6871                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6872                 .name = "Channel Mode",
6873                 .info = alc_ch_mode_info,
6874                 .get = alc_ch_mode_get,
6875                 .put = alc_ch_mode_put,
6876         },
6877         { } /* end */
6878 };
6879
6880 static struct hda_verb alc883_init_verbs[] = {
6881         /* ADC1: mute amp left and right */
6882         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6883         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6884         /* ADC2: mute amp left and right */
6885         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6886         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6887         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6888         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6889         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6890         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6891         /* Rear mixer */
6892         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6893         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6894         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6895         /* CLFE mixer */
6896         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6897         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6898         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6899         /* Side mixer */
6900         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6901         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6902         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6903
6904         /* mute analog input loopbacks */
6905         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6906         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6907         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6908         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6909         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6910
6911         /* Front Pin: output 0 (0x0c) */
6912         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6913         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6914         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6915         /* Rear Pin: output 1 (0x0d) */
6916         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6917         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6918         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
6919         /* CLFE Pin: output 2 (0x0e) */
6920         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6921         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6922         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
6923         /* Side Pin: output 3 (0x0f) */
6924         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6925         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6926         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
6927         /* Mic (rear) pin: input vref at 80% */
6928         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6929         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6930         /* Front Mic pin: input vref at 80% */
6931         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6932         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6933         /* Line In pin: input */
6934         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6935         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6936         /* Line-2 In: Headphone output (output 0 - 0x0c) */
6937         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6938         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6939         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
6940         /* CD pin widget for input */
6941         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6942
6943         /* FIXME: use matrix-type input source selection */
6944         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6945         /* Input mixer2 */
6946         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6947         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6948         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6949         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
6950         /* Input mixer3 */
6951         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6952         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6953         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6954         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
6955         { }
6956 };
6957
6958 /* toggle speaker-output according to the hp-jack state */
6959 static void alc883_mitac_hp_automute(struct hda_codec *codec)
6960 {
6961         unsigned int present;
6962
6963         present = snd_hda_codec_read(codec, 0x15, 0,
6964                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6965         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
6966                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6967         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
6968                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6969 }
6970
6971 /* auto-toggle front mic */
6972 /*
6973 static void alc883_mitac_mic_automute(struct hda_codec *codec)
6974 {
6975         unsigned int present;
6976         unsigned char bits;
6977
6978         present = snd_hda_codec_read(codec, 0x18, 0,
6979                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6980         bits = present ? HDA_AMP_MUTE : 0;
6981         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
6982 }
6983 */
6984
6985 static void alc883_mitac_automute(struct hda_codec *codec)
6986 {
6987         alc883_mitac_hp_automute(codec);
6988         /* alc883_mitac_mic_automute(codec); */
6989 }
6990
6991 static void alc883_mitac_unsol_event(struct hda_codec *codec,
6992                                            unsigned int res)
6993 {
6994         switch (res >> 26) {
6995         case ALC880_HP_EVENT:
6996                 alc883_mitac_hp_automute(codec);
6997                 break;
6998         case ALC880_MIC_EVENT:
6999                 /* alc883_mitac_mic_automute(codec); */
7000                 break;
7001         }
7002 }
7003
7004 static struct hda_verb alc883_mitac_verbs[] = {
7005         /* HP */
7006         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7007         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7008         /* Subwoofer */
7009         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
7010         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7011
7012         /* enable unsolicited event */
7013         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7014         /* {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN}, */
7015
7016         { } /* end */
7017 };
7018
7019 static struct hda_verb alc883_tagra_verbs[] = {
7020         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7021         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7022
7023         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7024         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7025         
7026         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7027         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7028         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7029
7030         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7031         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
7032         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
7033         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
7034
7035         { } /* end */
7036 };
7037
7038 static struct hda_verb alc883_lenovo_101e_verbs[] = {
7039         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7040         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
7041         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
7042         { } /* end */
7043 };
7044
7045 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
7046         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7047         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7048         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7049         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7050         { } /* end */
7051 };
7052
7053 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
7054         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7055         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7056         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7057         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
7058         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
7059         { } /* end */
7060 };
7061
7062 static struct hda_verb alc883_haier_w66_verbs[] = {
7063         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7064         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7065
7066         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7067
7068         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7069         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7070         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7071         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7072         { } /* end */
7073 };
7074
7075 static struct hda_verb alc888_6st_hp_verbs[] = {
7076         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
7077         {0x15, AC_VERB_SET_CONNECT_SEL, 0x02},  /* Rear : output 2 (0x0e) */
7078         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* CLFE : output 1 (0x0d) */
7079         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},  /* Side : output 3 (0x0f) */
7080         { }
7081 };
7082
7083 static struct hda_verb alc888_3st_hp_verbs[] = {
7084         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
7085         {0x18, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
7086         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
7087         { }
7088 };
7089
7090 static struct hda_verb alc888_6st_dell_verbs[] = {
7091         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
7092         {0x15, AC_VERB_SET_CONNECT_SEL, 0x02},  /* Rear : output 1 (0x0e) */
7093         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* CLFE : output 2 (0x0d) */
7094         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},  /* Side : output 3 (0x0f) */
7095         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7096         { }
7097 };
7098
7099 static struct hda_verb alc888_3st_hp_2ch_init[] = {
7100         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7101         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7102         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7103         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7104         { }
7105 };
7106
7107 static struct hda_verb alc888_3st_hp_6ch_init[] = {
7108         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7109         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7110         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7111         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7112         { }
7113 };
7114
7115 static struct hda_channel_mode alc888_3st_hp_modes[2] = {
7116         { 2, alc888_3st_hp_2ch_init },
7117         { 6, alc888_3st_hp_6ch_init },
7118 };
7119
7120 /* toggle front-jack and RCA according to the hp-jack state */
7121 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
7122 {
7123         unsigned int present;
7124  
7125         present = snd_hda_codec_read(codec, 0x1b, 0,
7126                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7127         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7128                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7129         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7130                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7131 }
7132
7133 /* toggle RCA according to the front-jack state */
7134 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
7135 {
7136         unsigned int present;
7137  
7138         present = snd_hda_codec_read(codec, 0x14, 0,
7139                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7140         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7141                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7142 }
7143
7144 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
7145                                              unsigned int res)
7146 {
7147         if ((res >> 26) == ALC880_HP_EVENT)
7148                 alc888_lenovo_ms7195_front_automute(codec);
7149         if ((res >> 26) == ALC880_FRONT_EVENT)
7150                 alc888_lenovo_ms7195_rca_automute(codec);
7151 }
7152
7153 static struct hda_verb alc883_medion_md2_verbs[] = {
7154         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7155         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7156
7157         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7158
7159         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7160         { } /* end */
7161 };
7162
7163 /* toggle speaker-output according to the hp-jack state */
7164 static void alc883_medion_md2_automute(struct hda_codec *codec)
7165 {
7166         unsigned int present;
7167  
7168         present = snd_hda_codec_read(codec, 0x14, 0,
7169                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7170         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7171                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7172 }
7173
7174 static void alc883_medion_md2_unsol_event(struct hda_codec *codec,
7175                                           unsigned int res)
7176 {
7177         if ((res >> 26) == ALC880_HP_EVENT)
7178                 alc883_medion_md2_automute(codec);
7179 }
7180
7181 /* toggle speaker-output according to the hp-jack state */
7182 static void alc883_tagra_automute(struct hda_codec *codec)
7183 {
7184         unsigned int present;
7185         unsigned char bits;
7186
7187         present = snd_hda_codec_read(codec, 0x14, 0,
7188                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7189         bits = present ? HDA_AMP_MUTE : 0;
7190         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
7191                                  HDA_AMP_MUTE, bits);
7192         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
7193                                   present ? 1 : 3);
7194 }
7195
7196 static void alc883_tagra_unsol_event(struct hda_codec *codec, unsigned int res)
7197 {
7198         if ((res >> 26) == ALC880_HP_EVENT)
7199                 alc883_tagra_automute(codec);
7200 }
7201
7202 static void alc883_haier_w66_automute(struct hda_codec *codec)
7203 {
7204         unsigned int present;
7205         unsigned char bits;
7206
7207         present = snd_hda_codec_read(codec, 0x1b, 0,
7208                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7209         bits = present ? 0x80 : 0;
7210         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7211                                  0x80, bits);
7212 }
7213
7214 static void alc883_haier_w66_unsol_event(struct hda_codec *codec,
7215                                          unsigned int res)
7216 {
7217         if ((res >> 26) == ALC880_HP_EVENT)
7218                 alc883_haier_w66_automute(codec);
7219 }
7220
7221 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
7222 {
7223         unsigned int present;
7224         unsigned char bits;
7225
7226         present = snd_hda_codec_read(codec, 0x14, 0,
7227                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7228         bits = present ? HDA_AMP_MUTE : 0;
7229         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7230                                  HDA_AMP_MUTE, bits);
7231 }
7232
7233 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
7234 {
7235         unsigned int present;
7236         unsigned char bits;
7237
7238         present = snd_hda_codec_read(codec, 0x1b, 0,
7239                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7240         bits = present ? HDA_AMP_MUTE : 0;
7241         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7242                                  HDA_AMP_MUTE, bits);
7243         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7244                                  HDA_AMP_MUTE, bits);
7245 }
7246
7247 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
7248                                            unsigned int res)
7249 {
7250         if ((res >> 26) == ALC880_HP_EVENT)
7251                 alc883_lenovo_101e_all_automute(codec);
7252         if ((res >> 26) == ALC880_FRONT_EVENT)
7253                 alc883_lenovo_101e_ispeaker_automute(codec);
7254 }
7255
7256 /* toggle speaker-output according to the hp-jack state */
7257 static void alc883_acer_aspire_automute(struct hda_codec *codec)
7258 {
7259         unsigned int present;
7260  
7261         present = snd_hda_codec_read(codec, 0x14, 0,
7262                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7263         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7264                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7265         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
7266                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7267 }
7268
7269 static void alc883_acer_aspire_unsol_event(struct hda_codec *codec,
7270                                            unsigned int res)
7271 {
7272         if ((res >> 26) == ALC880_HP_EVENT)
7273                 alc883_acer_aspire_automute(codec);
7274 }
7275
7276 static struct hda_verb alc883_acer_eapd_verbs[] = {
7277         /* HP Pin: output 0 (0x0c) */
7278         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7279         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7280         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7281         /* Front Pin: output 0 (0x0c) */
7282         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7283         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7284         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7285         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
7286         /* eanable EAPD on medion laptop */
7287         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7288         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
7289         /* enable unsolicited event */
7290         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7291         { }
7292 };
7293
7294 static void alc888_6st_dell_front_automute(struct hda_codec *codec)
7295 {
7296         unsigned int present;
7297  
7298         present = snd_hda_codec_read(codec, 0x1b, 0,
7299                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7300         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7301                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7302         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7303                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7304         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
7305                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7306         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
7307                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7308 }
7309
7310 static void alc888_6st_dell_unsol_event(struct hda_codec *codec,
7311                                              unsigned int res)
7312 {
7313         switch (res >> 26) {
7314         case ALC880_HP_EVENT:
7315                 printk("hp_event\n");
7316                 alc888_6st_dell_front_automute(codec);
7317                 break;
7318         }
7319 }
7320
7321 /*
7322  * generic initialization of ADC, input mixers and output mixers
7323  */
7324 static struct hda_verb alc883_auto_init_verbs[] = {
7325         /*
7326          * Unmute ADC0-2 and set the default input to mic-in
7327          */
7328         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7329         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7330         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7331         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7332
7333         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
7334          * mixer widget
7335          * Note: PASD motherboards uses the Line In 2 as the input for
7336          * front panel mic (mic 2)
7337          */
7338         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
7339         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7340         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7341         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7342         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7343         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7344
7345         /*
7346          * Set up output mixers (0x0c - 0x0f)
7347          */
7348         /* set vol=0 to output mixers */
7349         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7350         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7351         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7352         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7353         /* set up input amps for analog loopback */
7354         /* Amp Indices: DAC = 0, mixer = 1 */
7355         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7356         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7357         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7358         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7359         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7360         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7361         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7362         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7363         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7364         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7365
7366         /* FIXME: use matrix-type input source selection */
7367         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7368         /* Input mixer1 */
7369         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7370         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7371         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7372         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
7373         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7374         /* Input mixer2 */
7375         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7376         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7377         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7378         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
7379         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7380
7381         { }
7382 };
7383
7384 /* capture mixer elements */
7385 static struct snd_kcontrol_new alc883_capture_mixer[] = {
7386         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7387         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7388         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7389         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7390         {
7391                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7392                 /* The multiple "Capture Source" controls confuse alsamixer
7393                  * So call somewhat different..
7394                  */
7395                 /* .name = "Capture Source", */
7396                 .name = "Input Source",
7397                 .count = 2,
7398                 .info = alc882_mux_enum_info,
7399                 .get = alc882_mux_enum_get,
7400                 .put = alc882_mux_enum_put,
7401         },
7402         { } /* end */
7403 };
7404
7405 #ifdef CONFIG_SND_HDA_POWER_SAVE
7406 #define alc883_loopbacks        alc880_loopbacks
7407 #endif
7408
7409 /* pcm configuration: identiacal with ALC880 */
7410 #define alc883_pcm_analog_playback      alc880_pcm_analog_playback
7411 #define alc883_pcm_analog_capture       alc880_pcm_analog_capture
7412 #define alc883_pcm_digital_playback     alc880_pcm_digital_playback
7413 #define alc883_pcm_digital_capture      alc880_pcm_digital_capture
7414
7415 /*
7416  * configuration and preset
7417  */
7418 static const char *alc883_models[ALC883_MODEL_LAST] = {
7419         [ALC883_3ST_2ch_DIG]    = "3stack-dig",
7420         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
7421         [ALC883_3ST_6ch]        = "3stack-6ch",
7422         [ALC883_6ST_DIG]        = "6stack-dig",
7423         [ALC883_TARGA_DIG]      = "targa-dig",
7424         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
7425         [ALC883_ACER]           = "acer",
7426         [ALC883_ACER_ASPIRE]    = "acer-aspire",
7427         [ALC883_MEDION]         = "medion",
7428         [ALC883_MEDION_MD2]     = "medion-md2",
7429         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
7430         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
7431         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
7432         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
7433         [ALC883_HAIER_W66]      = "haier-w66",
7434         [ALC888_6ST_HP]         = "6stack-hp",
7435         [ALC888_3ST_HP]         = "3stack-hp",
7436         [ALC888_6ST_DELL]       = "6stack-dell",
7437         [ALC883_MITAC]          = "mitac",
7438         [ALC883_AUTO]           = "auto",
7439 };
7440
7441 static struct snd_pci_quirk alc883_cfg_tbl[] = {
7442         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG),
7443         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
7444         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
7445         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
7446         SND_PCI_QUIRK(0x1025, 0, "Acer laptop", ALC883_ACER), /* default Acer */
7447         SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
7448         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
7449         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
7450         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
7451         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC888_6ST_HP),
7452         SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
7453         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
7454         SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
7455         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
7456         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
7457         SND_PCI_QUIRK(0x1458, 0xa002, "MSI", ALC883_6ST_DIG),
7458         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
7459         SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
7460         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
7461         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
7462         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
7463         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
7464         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
7465         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
7466         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
7467         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
7468         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
7469         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
7470         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
7471         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
7472         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
7473         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
7474         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
7475         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
7476         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
7477         SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
7478         SND_PCI_QUIRK(0x1558, 0, "Clevo laptop", ALC883_LAPTOP_EAPD),
7479         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
7480         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
7481         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
7482         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
7483         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
7484         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
7485         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
7486         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
7487         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
7488         {}
7489 };
7490
7491 static struct alc_config_preset alc883_presets[] = {
7492         [ALC883_3ST_2ch_DIG] = {
7493                 .mixers = { alc883_3ST_2ch_mixer },
7494                 .init_verbs = { alc883_init_verbs },
7495                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7496                 .dac_nids = alc883_dac_nids,
7497                 .dig_out_nid = ALC883_DIGOUT_NID,
7498                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7499                 .adc_nids = alc883_adc_nids,
7500                 .dig_in_nid = ALC883_DIGIN_NID,
7501                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7502                 .channel_mode = alc883_3ST_2ch_modes,
7503                 .input_mux = &alc883_capture_source,
7504         },
7505         [ALC883_3ST_6ch_DIG] = {
7506                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
7507                 .init_verbs = { alc883_init_verbs },
7508                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7509                 .dac_nids = alc883_dac_nids,
7510                 .dig_out_nid = ALC883_DIGOUT_NID,
7511                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7512                 .adc_nids = alc883_adc_nids,
7513                 .dig_in_nid = ALC883_DIGIN_NID,
7514                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7515                 .channel_mode = alc883_3ST_6ch_modes,
7516                 .need_dac_fix = 1,
7517                 .input_mux = &alc883_capture_source,
7518         },
7519         [ALC883_3ST_6ch] = {
7520                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
7521                 .init_verbs = { alc883_init_verbs },
7522                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7523                 .dac_nids = alc883_dac_nids,
7524                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7525                 .adc_nids = alc883_adc_nids,
7526                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7527                 .channel_mode = alc883_3ST_6ch_modes,
7528                 .need_dac_fix = 1,
7529                 .input_mux = &alc883_capture_source,
7530         },
7531         [ALC883_6ST_DIG] = {
7532                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
7533                 .init_verbs = { alc883_init_verbs },
7534                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7535                 .dac_nids = alc883_dac_nids,
7536                 .dig_out_nid = ALC883_DIGOUT_NID,
7537                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7538                 .adc_nids = alc883_adc_nids,
7539                 .dig_in_nid = ALC883_DIGIN_NID,
7540                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7541                 .channel_mode = alc883_sixstack_modes,
7542                 .input_mux = &alc883_capture_source,
7543         },
7544         [ALC883_TARGA_DIG] = {
7545                 .mixers = { alc883_tagra_mixer, alc883_chmode_mixer },
7546                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
7547                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7548                 .dac_nids = alc883_dac_nids,
7549                 .dig_out_nid = ALC883_DIGOUT_NID,
7550                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7551                 .adc_nids = alc883_adc_nids,
7552                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7553                 .channel_mode = alc883_3ST_6ch_modes,
7554                 .need_dac_fix = 1,
7555                 .input_mux = &alc883_capture_source,
7556                 .unsol_event = alc883_tagra_unsol_event,
7557                 .init_hook = alc883_tagra_automute,
7558         },
7559         [ALC883_TARGA_2ch_DIG] = {
7560                 .mixers = { alc883_tagra_2ch_mixer},
7561                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
7562                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7563                 .dac_nids = alc883_dac_nids,
7564                 .dig_out_nid = ALC883_DIGOUT_NID,
7565                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7566                 .adc_nids = alc883_adc_nids,
7567                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7568                 .channel_mode = alc883_3ST_2ch_modes,
7569                 .input_mux = &alc883_capture_source,
7570                 .unsol_event = alc883_tagra_unsol_event,
7571                 .init_hook = alc883_tagra_automute,
7572         },
7573         [ALC883_ACER] = {
7574                 .mixers = { alc883_base_mixer },
7575                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
7576                  * and the headphone jack.  Turn this on and rely on the
7577                  * standard mute methods whenever the user wants to turn
7578                  * these outputs off.
7579                  */
7580                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
7581                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7582                 .dac_nids = alc883_dac_nids,
7583                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7584                 .adc_nids = alc883_adc_nids,
7585                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7586                 .channel_mode = alc883_3ST_2ch_modes,
7587                 .input_mux = &alc883_capture_source,
7588         },
7589         [ALC883_ACER_ASPIRE] = {
7590                 .mixers = { alc883_acer_aspire_mixer },
7591                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
7592                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7593                 .dac_nids = alc883_dac_nids,
7594                 .dig_out_nid = ALC883_DIGOUT_NID,
7595                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7596                 .adc_nids = alc883_adc_nids,
7597                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7598                 .channel_mode = alc883_3ST_2ch_modes,
7599                 .input_mux = &alc883_capture_source,
7600                 .unsol_event = alc883_acer_aspire_unsol_event,
7601                 .init_hook = alc883_acer_aspire_automute,
7602         },
7603         [ALC883_MEDION] = {
7604                 .mixers = { alc883_fivestack_mixer,
7605                             alc883_chmode_mixer },
7606                 .init_verbs = { alc883_init_verbs,
7607                                 alc883_medion_eapd_verbs },
7608                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7609                 .dac_nids = alc883_dac_nids,
7610                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7611                 .adc_nids = alc883_adc_nids,
7612                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7613                 .channel_mode = alc883_sixstack_modes,
7614                 .input_mux = &alc883_capture_source,
7615         },
7616         [ALC883_MEDION_MD2] = {
7617                 .mixers = { alc883_medion_md2_mixer},
7618                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
7619                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7620                 .dac_nids = alc883_dac_nids,
7621                 .dig_out_nid = ALC883_DIGOUT_NID,
7622                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7623                 .adc_nids = alc883_adc_nids,
7624                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7625                 .channel_mode = alc883_3ST_2ch_modes,
7626                 .input_mux = &alc883_capture_source,
7627                 .unsol_event = alc883_medion_md2_unsol_event,
7628                 .init_hook = alc883_medion_md2_automute,
7629         },      
7630         [ALC883_LAPTOP_EAPD] = {
7631                 .mixers = { alc883_base_mixer },
7632                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
7633                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7634                 .dac_nids = alc883_dac_nids,
7635                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7636                 .adc_nids = alc883_adc_nids,
7637                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7638                 .channel_mode = alc883_3ST_2ch_modes,
7639                 .input_mux = &alc883_capture_source,
7640         },
7641         [ALC883_LENOVO_101E_2ch] = {
7642                 .mixers = { alc883_lenovo_101e_2ch_mixer},
7643                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
7644                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7645                 .dac_nids = alc883_dac_nids,
7646                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7647                 .adc_nids = alc883_adc_nids,
7648                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7649                 .channel_mode = alc883_3ST_2ch_modes,
7650                 .input_mux = &alc883_lenovo_101e_capture_source,
7651                 .unsol_event = alc883_lenovo_101e_unsol_event,
7652                 .init_hook = alc883_lenovo_101e_all_automute,
7653         },
7654         [ALC883_LENOVO_NB0763] = {
7655                 .mixers = { alc883_lenovo_nb0763_mixer },
7656                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
7657                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7658                 .dac_nids = alc883_dac_nids,
7659                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7660                 .adc_nids = alc883_adc_nids,
7661                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7662                 .channel_mode = alc883_3ST_2ch_modes,
7663                 .need_dac_fix = 1,
7664                 .input_mux = &alc883_lenovo_nb0763_capture_source,
7665                 .unsol_event = alc883_medion_md2_unsol_event,
7666                 .init_hook = alc883_medion_md2_automute,
7667         },
7668         [ALC888_LENOVO_MS7195_DIG] = {
7669                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
7670                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
7671                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7672                 .dac_nids = alc883_dac_nids,
7673                 .dig_out_nid = ALC883_DIGOUT_NID,
7674                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7675                 .adc_nids = alc883_adc_nids,
7676                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7677                 .channel_mode = alc883_3ST_6ch_modes,
7678                 .need_dac_fix = 1,
7679                 .input_mux = &alc883_capture_source,
7680                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
7681                 .init_hook = alc888_lenovo_ms7195_front_automute,
7682         },
7683         [ALC883_HAIER_W66] = {
7684                 .mixers = { alc883_tagra_2ch_mixer},
7685                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
7686                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7687                 .dac_nids = alc883_dac_nids,
7688                 .dig_out_nid = ALC883_DIGOUT_NID,
7689                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7690                 .adc_nids = alc883_adc_nids,
7691                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7692                 .channel_mode = alc883_3ST_2ch_modes,
7693                 .input_mux = &alc883_capture_source,
7694                 .unsol_event = alc883_haier_w66_unsol_event,
7695                 .init_hook = alc883_haier_w66_automute,
7696         },      
7697         [ALC888_6ST_HP] = {
7698                 .mixers = { alc888_6st_hp_mixer, alc883_chmode_mixer },
7699                 .init_verbs = { alc883_init_verbs, alc888_6st_hp_verbs },
7700                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7701                 .dac_nids = alc883_dac_nids,
7702                 .dig_out_nid = ALC883_DIGOUT_NID,
7703                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7704                 .adc_nids = alc883_adc_nids,
7705                 .dig_in_nid = ALC883_DIGIN_NID,
7706                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7707                 .channel_mode = alc883_sixstack_modes,
7708                 .input_mux = &alc883_capture_source,
7709         },
7710         [ALC888_3ST_HP] = {
7711                 .mixers = { alc888_3st_hp_mixer, alc883_chmode_mixer },
7712                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
7713                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7714                 .dac_nids = alc883_dac_nids,
7715                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7716                 .adc_nids = alc883_adc_nids,
7717                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
7718                 .channel_mode = alc888_3st_hp_modes,
7719                 .need_dac_fix = 1,
7720                 .input_mux = &alc883_capture_source,
7721         },
7722         [ALC888_6ST_DELL] = {
7723                 .mixers = { alc888_6st_dell_mixer, alc883_chmode_mixer },
7724                 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
7725                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7726                 .dac_nids = alc883_dac_nids,
7727                 .dig_out_nid = ALC883_DIGOUT_NID,
7728                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7729                 .adc_nids = alc883_adc_nids,
7730                 .dig_in_nid = ALC883_DIGIN_NID,
7731                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7732                 .channel_mode = alc883_sixstack_modes,
7733                 .input_mux = &alc883_capture_source,
7734                 .unsol_event = alc888_6st_dell_unsol_event,
7735                 .init_hook = alc888_6st_dell_front_automute,
7736         },
7737         [ALC883_MITAC] = {
7738                 .mixers = { alc883_mitac_mixer },
7739                 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
7740                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7741                 .dac_nids = alc883_dac_nids,
7742                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7743                 .adc_nids = alc883_adc_nids,
7744                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7745                 .channel_mode = alc883_3ST_2ch_modes,
7746                 .input_mux = &alc883_capture_source,
7747                 .unsol_event = alc883_mitac_unsol_event,
7748                 .init_hook = alc883_mitac_automute,
7749         },
7750 };
7751
7752
7753 /*
7754  * BIOS auto configuration
7755  */
7756 static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
7757                                               hda_nid_t nid, int pin_type,
7758                                               int dac_idx)
7759 {
7760         /* set as output */
7761         struct alc_spec *spec = codec->spec;
7762         int idx;
7763
7764         if (spec->multiout.dac_nids[dac_idx] == 0x25)
7765                 idx = 4;
7766         else
7767                 idx = spec->multiout.dac_nids[dac_idx] - 2;
7768
7769         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
7770                             pin_type);
7771         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
7772                             AMP_OUT_UNMUTE);
7773         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
7774
7775 }
7776
7777 static void alc883_auto_init_multi_out(struct hda_codec *codec)
7778 {
7779         struct alc_spec *spec = codec->spec;
7780         int i;
7781
7782         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
7783         for (i = 0; i <= HDA_SIDE; i++) {
7784                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
7785                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
7786                 if (nid)
7787                         alc883_auto_set_output_and_unmute(codec, nid, pin_type,
7788                                                           i);
7789         }
7790 }
7791
7792 static void alc883_auto_init_hp_out(struct hda_codec *codec)
7793 {
7794         struct alc_spec *spec = codec->spec;
7795         hda_nid_t pin;
7796
7797         pin = spec->autocfg.hp_pins[0];
7798         if (pin) /* connect to front */
7799                 /* use dac 0 */
7800                 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
7801 }
7802
7803 #define alc883_is_input_pin(nid)        alc880_is_input_pin(nid)
7804 #define ALC883_PIN_CD_NID               ALC880_PIN_CD_NID
7805
7806 static void alc883_auto_init_analog_input(struct hda_codec *codec)
7807 {
7808         struct alc_spec *spec = codec->spec;
7809         int i;
7810
7811         for (i = 0; i < AUTO_PIN_LAST; i++) {
7812                 hda_nid_t nid = spec->autocfg.input_pins[i];
7813                 if (alc883_is_input_pin(nid)) {
7814                         snd_hda_codec_write(codec, nid, 0,
7815                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
7816                                             (i <= AUTO_PIN_FRONT_MIC ?
7817                                              PIN_VREF80 : PIN_IN));
7818                         if (nid != ALC883_PIN_CD_NID)
7819                                 snd_hda_codec_write(codec, nid, 0,
7820                                                     AC_VERB_SET_AMP_GAIN_MUTE,
7821                                                     AMP_OUT_MUTE);
7822                 }
7823         }
7824 }
7825
7826 /* almost identical with ALC880 parser... */
7827 static int alc883_parse_auto_config(struct hda_codec *codec)
7828 {
7829         struct alc_spec *spec = codec->spec;
7830         int err = alc880_parse_auto_config(codec);
7831
7832         if (err < 0)
7833                 return err;
7834         else if (!err)
7835                 return 0; /* no config found */
7836
7837         err = alc_auto_add_mic_boost(codec);
7838         if (err < 0)
7839                 return err;
7840
7841         /* hack - override the init verbs */
7842         spec->init_verbs[0] = alc883_auto_init_verbs;
7843         spec->mixers[spec->num_mixers] = alc883_capture_mixer;
7844         spec->num_mixers++;
7845
7846         return 1; /* config found */
7847 }
7848
7849 /* additional initialization for auto-configuration model */
7850 static void alc883_auto_init(struct hda_codec *codec)
7851 {
7852         alc883_auto_init_multi_out(codec);
7853         alc883_auto_init_hp_out(codec);
7854         alc883_auto_init_analog_input(codec);
7855 }
7856
7857 static int patch_alc883(struct hda_codec *codec)
7858 {
7859         struct alc_spec *spec;
7860         int err, board_config;
7861
7862         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
7863         if (spec == NULL)
7864                 return -ENOMEM;
7865
7866         codec->spec = spec;
7867
7868         board_config = snd_hda_check_board_config(codec, ALC883_MODEL_LAST,
7869                                                   alc883_models,
7870                                                   alc883_cfg_tbl);
7871         if (board_config < 0) {
7872                 printk(KERN_INFO "hda_codec: Unknown model for ALC883, "
7873                        "trying auto-probe from BIOS...\n");
7874                 board_config = ALC883_AUTO;
7875         }
7876
7877         if (board_config == ALC883_AUTO) {
7878                 /* automatic parse from the BIOS config */
7879                 err = alc883_parse_auto_config(codec);
7880                 if (err < 0) {
7881                         alc_free(codec);
7882                         return err;
7883                 } else if (!err) {
7884                         printk(KERN_INFO
7885                                "hda_codec: Cannot set up configuration "
7886                                "from BIOS.  Using base mode...\n");
7887                         board_config = ALC883_3ST_2ch_DIG;
7888                 }
7889         }
7890
7891         if (board_config != ALC883_AUTO)
7892                 setup_preset(spec, &alc883_presets[board_config]);
7893
7894         spec->stream_name_analog = "ALC883 Analog";
7895         spec->stream_analog_playback = &alc883_pcm_analog_playback;
7896         spec->stream_analog_capture = &alc883_pcm_analog_capture;
7897
7898         spec->stream_name_digital = "ALC883 Digital";
7899         spec->stream_digital_playback = &alc883_pcm_digital_playback;
7900         spec->stream_digital_capture = &alc883_pcm_digital_capture;
7901
7902         if (!spec->adc_nids && spec->input_mux) {
7903                 spec->adc_nids = alc883_adc_nids;
7904                 spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
7905         }
7906
7907         spec->vmaster_nid = 0x0c;
7908
7909         codec->patch_ops = alc_patch_ops;
7910         if (board_config == ALC883_AUTO)
7911                 spec->init_hook = alc883_auto_init;
7912 #ifdef CONFIG_SND_HDA_POWER_SAVE
7913         if (!spec->loopback.amplist)
7914                 spec->loopback.amplist = alc883_loopbacks;
7915 #endif
7916
7917         return 0;
7918 }
7919
7920 /*
7921  * ALC262 support
7922  */
7923
7924 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
7925 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
7926
7927 #define alc262_dac_nids         alc260_dac_nids
7928 #define alc262_adc_nids         alc882_adc_nids
7929 #define alc262_adc_nids_alt     alc882_adc_nids_alt
7930
7931 #define alc262_modes            alc260_modes
7932 #define alc262_capture_source   alc882_capture_source
7933
7934 static struct snd_kcontrol_new alc262_base_mixer[] = {
7935         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7936         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7937         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7938         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7939         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7940         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7941         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7942         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7943         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7944         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
7945         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
7946         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7947         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
7948            HDA_CODEC_MUTE("PC Beelp Playback Switch", 0x0b, 0x05, HDA_INPUT), */
7949         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
7950         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7951         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7952         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
7953         { } /* end */
7954 };
7955
7956 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
7957         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7958         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7959         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7960         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7961         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7962         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7963         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7964         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7965         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7966         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
7967         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
7968         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7969         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
7970            HDA_CODEC_MUTE("PC Beelp Playback Switch", 0x0b, 0x05, HDA_INPUT), */
7971         /*HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),*/
7972         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7973         { } /* end */
7974 };
7975
7976 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
7977         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7978         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7979         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7980         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7981         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
7982
7983         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7984         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7985         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7986         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
7987         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
7988         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7989         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7990         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7991         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7992         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7993         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
7994         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
7995         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
7996         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
7997         { } /* end */
7998 };
7999
8000 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
8001         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8002         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8003         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8004         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8005         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
8006         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
8007         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
8008         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
8009         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
8010         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
8011         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
8012         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8013         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8014         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8015         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
8016         { } /* end */
8017 };
8018
8019 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
8020         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8021         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8022         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
8023         { } /* end */
8024 };
8025
8026 static struct hda_bind_ctls alc262_hp_t5735_bind_front_vol = {
8027         .ops = &snd_hda_bind_vol,
8028         .values = {
8029                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
8030                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
8031                 0
8032         },
8033 };
8034
8035 static struct hda_bind_ctls alc262_hp_t5735_bind_front_sw = {
8036         .ops = &snd_hda_bind_sw,
8037         .values = {
8038                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
8039                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
8040                 0
8041         },
8042 };
8043
8044 /* mute/unmute internal speaker according to the hp jack and mute state */
8045 static void alc262_hp_t5735_automute(struct hda_codec *codec, int force)
8046 {
8047         struct alc_spec *spec = codec->spec;
8048         unsigned int mute;
8049
8050         if (force || !spec->sense_updated) {
8051                 unsigned int present;
8052                 present = snd_hda_codec_read(codec, 0x15, 0,
8053                                              AC_VERB_GET_PIN_SENSE, 0);
8054                 spec->jack_present = (present & 0x80000000) != 0;
8055                 spec->sense_updated = 1;
8056         }
8057         if (spec->jack_present)
8058                 mute = (0x7080 | ((0)<<8));  /* mute internal speaker */
8059         else    /* unmute internal speaker if necessary */
8060                 mute = (0x7000 | ((0)<<8));
8061         snd_hda_codec_write(codec, 0x0c, 0,
8062                             AC_VERB_SET_AMP_GAIN_MUTE, mute );
8063 }
8064
8065 static void alc262_hp_t5735_unsol_event(struct hda_codec *codec,
8066                                         unsigned int res)
8067 {
8068         if ((res >> 26) != ALC880_HP_EVENT)
8069                 return;
8070         alc262_hp_t5735_automute(codec, 1);
8071 }
8072
8073 static void alc262_hp_t5735_init_hook(struct hda_codec *codec)
8074 {
8075         alc262_hp_t5735_automute(codec, 1);
8076 }
8077
8078 static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
8079         HDA_BIND_VOL("PCM Playback Volume", &alc262_hp_t5735_bind_front_vol),
8080         HDA_BIND_SW("PCM Playback Switch",&alc262_hp_t5735_bind_front_sw),
8081         HDA_CODEC_VOLUME("LineOut Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8082         HDA_CODEC_MUTE("LineOut Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8083         HDA_CODEC_VOLUME("iSpeaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8084         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8085         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8086         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8087         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8088         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8089         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8090         { } /* end */
8091 };
8092
8093 static struct hda_verb alc262_hp_t5735_verbs[] = {
8094         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8095         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8096
8097         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8098         { }
8099 };
8100
8101 static struct hda_bind_ctls alc262_hp_rp5700_bind_front_vol = {
8102         .ops = &snd_hda_bind_vol,
8103         .values = {
8104                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
8105                 HDA_COMPOSE_AMP_VAL(0x0e, 3, 0, HDA_OUTPUT),
8106                 0
8107         },
8108 };
8109
8110 static struct hda_bind_ctls alc262_hp_rp5700_bind_front_sw = {
8111         .ops = &snd_hda_bind_sw,
8112         .values = {
8113                 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
8114                 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT),
8115                 0
8116         },
8117 };
8118
8119 static struct snd_kcontrol_new alc262_hp_rp5700_mixer[] = {
8120         HDA_BIND_VOL("PCM Playback Volume", &alc262_hp_rp5700_bind_front_vol),
8121         HDA_BIND_SW("PCM Playback Switch", &alc262_hp_rp5700_bind_front_sw),
8122         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8123         HDA_CODEC_MUTE("Master Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8124         HDA_CODEC_VOLUME("iSpeaker Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
8125         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x16, 0x0, HDA_OUTPUT),
8126         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
8127         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
8128         { } /* end */
8129 };
8130
8131 static struct hda_verb alc262_hp_rp5700_verbs[] = {
8132         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8133         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8134         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8135         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8136         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8137         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8138         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8139         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8140         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
8141         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
8142         {}
8143 };
8144
8145 static struct hda_input_mux alc262_hp_rp5700_capture_source = {
8146         .num_items = 1,
8147         .items = {
8148                 { "Line", 0x1 },
8149         },
8150 };
8151
8152 /* bind hp and internal speaker mute (with plug check) */
8153 static int alc262_sony_master_sw_put(struct snd_kcontrol *kcontrol,
8154                                      struct snd_ctl_elem_value *ucontrol)
8155 {
8156         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8157         long *valp = ucontrol->value.integer.value;
8158         int change;
8159
8160         /* change hp mute */
8161         change = snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
8162                                           HDA_AMP_MUTE,
8163                                           valp[0] ? 0 : HDA_AMP_MUTE);
8164         change |= snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
8165                                            HDA_AMP_MUTE,
8166                                            valp[1] ? 0 : HDA_AMP_MUTE);
8167         if (change) {
8168                 /* change speaker according to HP jack state */
8169                 struct alc_spec *spec = codec->spec;
8170                 unsigned int mute;
8171                 if (spec->jack_present)
8172                         mute = HDA_AMP_MUTE;
8173                 else
8174                         mute = snd_hda_codec_amp_read(codec, 0x15, 0,
8175                                                       HDA_OUTPUT, 0);
8176                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8177                                          HDA_AMP_MUTE, mute);
8178         }
8179         return change;
8180 }
8181
8182 static struct snd_kcontrol_new alc262_sony_mixer[] = {
8183         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8184         {
8185                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8186                 .name = "Master Playback Switch",
8187                 .info = snd_hda_mixer_amp_switch_info,
8188                 .get = snd_hda_mixer_amp_switch_get,
8189                 .put = alc262_sony_master_sw_put,
8190                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
8191         },
8192         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8193         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8194         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8195         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8196         { } /* end */
8197 };
8198
8199 static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
8200         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8201         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8202         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8203         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8204         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8205         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8206         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8207         { } /* end */
8208 };
8209
8210 #define alc262_capture_mixer            alc882_capture_mixer
8211 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
8212
8213 /*
8214  * generic initialization of ADC, input mixers and output mixers
8215  */
8216 static struct hda_verb alc262_init_verbs[] = {
8217         /*
8218          * Unmute ADC0-2 and set the default input to mic-in
8219          */
8220         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
8221         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8222         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8223         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8224         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8225         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8226
8227         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8228          * mixer widget
8229          * Note: PASD motherboards uses the Line In 2 as the input for
8230          * front panel mic (mic 2)
8231          */
8232         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8233         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8234         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8235         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8236         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8237         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8238
8239         /*
8240          * Set up output mixers (0x0c - 0x0e)
8241          */
8242         /* set vol=0 to output mixers */
8243         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8244         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8245         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8246         /* set up input amps for analog loopback */
8247         /* Amp Indices: DAC = 0, mixer = 1 */
8248         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8249         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8250         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8251         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8252         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8253         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8254
8255         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
8256         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8257         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
8258         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8259         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8260         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8261
8262         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8263         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8264         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8265         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8266         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8267         
8268         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8269         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
8270         
8271         /* FIXME: use matrix-type input source selection */
8272         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8273         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
8274         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8275         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8276         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8277         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8278         /* Input mixer2 */
8279         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8280         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8281         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8282         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8283         /* Input mixer3 */
8284         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8285         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8286         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8287         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8288
8289         { }
8290 };
8291
8292 static struct hda_verb alc262_hippo_unsol_verbs[] = {
8293         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8294         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8295         {}
8296 };
8297
8298 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
8299         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8300         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8301         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8302
8303         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8304         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8305         {}
8306 };
8307
8308 static struct hda_verb alc262_sony_unsol_verbs[] = {
8309         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8310         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8311         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
8312
8313         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8314         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8315 };
8316
8317 /* mute/unmute internal speaker according to the hp jack and mute state */
8318 static void alc262_hippo_automute(struct hda_codec *codec)
8319 {
8320         struct alc_spec *spec = codec->spec;
8321         unsigned int mute;
8322         unsigned int present;
8323
8324         /* need to execute and sync at first */
8325         snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
8326         present = snd_hda_codec_read(codec, 0x15, 0,
8327                                      AC_VERB_GET_PIN_SENSE, 0);
8328         spec->jack_present = (present & 0x80000000) != 0;
8329         if (spec->jack_present) {
8330                 /* mute internal speaker */
8331                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8332                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8333         } else {
8334                 /* unmute internal speaker if necessary */
8335                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
8336                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8337                                          HDA_AMP_MUTE, mute);
8338         }
8339 }
8340
8341 /* unsolicited event for HP jack sensing */
8342 static void alc262_hippo_unsol_event(struct hda_codec *codec,
8343                                        unsigned int res)
8344 {
8345         if ((res >> 26) != ALC880_HP_EVENT)
8346                 return;
8347         alc262_hippo_automute(codec);
8348 }
8349
8350 static void alc262_hippo1_automute(struct hda_codec *codec)
8351 {
8352         unsigned int mute;
8353         unsigned int present;
8354
8355         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
8356         present = snd_hda_codec_read(codec, 0x1b, 0,
8357                                      AC_VERB_GET_PIN_SENSE, 0);
8358         present = (present & 0x80000000) != 0;
8359         if (present) {
8360                 /* mute internal speaker */
8361                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8362                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8363         } else {
8364                 /* unmute internal speaker if necessary */
8365                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
8366                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8367                                          HDA_AMP_MUTE, mute);
8368         }
8369 }
8370
8371 /* unsolicited event for HP jack sensing */
8372 static void alc262_hippo1_unsol_event(struct hda_codec *codec,
8373                                        unsigned int res)
8374 {
8375         if ((res >> 26) != ALC880_HP_EVENT)
8376                 return;
8377         alc262_hippo1_automute(codec);
8378 }
8379
8380 /*
8381  * fujitsu model
8382  *  0x14 = headphone/spdif-out, 0x15 = internal speaker
8383  */
8384
8385 #define ALC_HP_EVENT    0x37
8386
8387 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
8388         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
8389         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8390         {}
8391 };
8392
8393 static struct hda_input_mux alc262_fujitsu_capture_source = {
8394         .num_items = 3,
8395         .items = {
8396                 { "Mic", 0x0 },
8397                 { "Int Mic", 0x1 },
8398                 { "CD", 0x4 },
8399         },
8400 };
8401
8402 static struct hda_input_mux alc262_HP_capture_source = {
8403         .num_items = 5,
8404         .items = {
8405                 { "Mic", 0x0 },
8406                 { "Front Mic", 0x1 },
8407                 { "Line", 0x2 },
8408                 { "CD", 0x4 },
8409                 { "AUX IN", 0x6 },
8410         },
8411 };
8412
8413 static struct hda_input_mux alc262_HP_D7000_capture_source = {
8414         .num_items = 4,
8415         .items = {
8416                 { "Mic", 0x0 },
8417                 { "Front Mic", 0x2 },
8418                 { "Line", 0x1 },
8419                 { "CD", 0x4 },
8420         },
8421 };
8422
8423 /* mute/unmute internal speaker according to the hp jack and mute state */
8424 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
8425 {
8426         struct alc_spec *spec = codec->spec;
8427         unsigned int mute;
8428
8429         if (force || !spec->sense_updated) {
8430                 unsigned int present;
8431                 /* need to execute and sync at first */
8432                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
8433                 present = snd_hda_codec_read(codec, 0x14, 0,
8434                                          AC_VERB_GET_PIN_SENSE, 0);
8435                 spec->jack_present = (present & 0x80000000) != 0;
8436                 spec->sense_updated = 1;
8437         }
8438         if (spec->jack_present) {
8439                 /* mute internal speaker */
8440                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8441                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8442         } else {
8443                 /* unmute internal speaker if necessary */
8444                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
8445                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8446                                          HDA_AMP_MUTE, mute);
8447         }
8448 }
8449
8450 /* unsolicited event for HP jack sensing */
8451 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
8452                                        unsigned int res)
8453 {
8454         if ((res >> 26) != ALC_HP_EVENT)
8455                 return;
8456         alc262_fujitsu_automute(codec, 1);
8457 }
8458
8459 /* bind volumes of both NID 0x0c and 0x0d */
8460 static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
8461         .ops = &snd_hda_bind_vol,
8462         .values = {
8463                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
8464                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
8465                 0
8466         },
8467 };
8468
8469 /* bind hp and internal speaker mute (with plug check) */
8470 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
8471                                          struct snd_ctl_elem_value *ucontrol)
8472 {
8473         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8474         long *valp = ucontrol->value.integer.value;
8475         int change;
8476
8477         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
8478                                           HDA_AMP_MUTE,
8479                                           valp[0] ? 0 : HDA_AMP_MUTE);
8480         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
8481                                            HDA_AMP_MUTE,
8482                                            valp[1] ? 0 : HDA_AMP_MUTE);
8483         if (change)
8484                 alc262_fujitsu_automute(codec, 0);
8485         return change;
8486 }
8487
8488 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
8489         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
8490         {
8491                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8492                 .name = "Master Playback Switch",
8493                 .info = snd_hda_mixer_amp_switch_info,
8494                 .get = snd_hda_mixer_amp_switch_get,
8495                 .put = alc262_fujitsu_master_sw_put,
8496                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
8497         },
8498         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8499         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8500         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8501         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8502         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8503         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
8504         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8505         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8506         { } /* end */
8507 };
8508
8509 /* additional init verbs for Benq laptops */
8510 static struct hda_verb alc262_EAPD_verbs[] = {
8511         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
8512         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
8513         {}
8514 };
8515
8516 static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
8517         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8518         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8519
8520         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
8521         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
8522         {}
8523 };
8524
8525 /* Samsung Q1 Ultra Vista model setup */
8526 static struct snd_kcontrol_new alc262_ultra_mixer[] = {
8527         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8528         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8529         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8530         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8531         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8532         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
8533         { } /* end */
8534 };
8535
8536 static struct hda_verb alc262_ultra_verbs[] = {
8537         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8538         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8539         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
8540         /* Mic is on Node 0x19 */
8541         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8542         {0x22, AC_VERB_SET_CONNECT_SEL, 0x01},
8543         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8544         {0x23, AC_VERB_SET_CONNECT_SEL, 0x01},
8545         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8546         {0x24, AC_VERB_SET_CONNECT_SEL, 0x01},
8547         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8548         {}
8549 };
8550
8551 static struct hda_input_mux alc262_ultra_capture_source = {
8552         .num_items = 1,
8553         .items = {
8554                 { "Mic", 0x1 },
8555         },
8556 };
8557
8558 /* mute/unmute internal speaker according to the hp jack and mute state */
8559 static void alc262_ultra_automute(struct hda_codec *codec)
8560 {
8561         struct alc_spec *spec = codec->spec;
8562         unsigned int mute;
8563         unsigned int present;
8564
8565         /* need to execute and sync at first */
8566         snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
8567         present = snd_hda_codec_read(codec, 0x15, 0,
8568                                      AC_VERB_GET_PIN_SENSE, 0);
8569         spec->jack_present = (present & 0x80000000) != 0;
8570         if (spec->jack_present) {
8571                 /* mute internal speaker */
8572                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8573                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8574         } else {
8575                 /* unmute internal speaker if necessary */
8576                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
8577                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8578                                          HDA_AMP_MUTE, mute);
8579         }
8580 }
8581
8582 /* unsolicited event for HP jack sensing */
8583 static void alc262_ultra_unsol_event(struct hda_codec *codec,
8584                                        unsigned int res)
8585 {
8586         if ((res >> 26) != ALC880_HP_EVENT)
8587                 return;
8588         alc262_ultra_automute(codec);
8589 }
8590
8591 /* add playback controls from the parsed DAC table */
8592 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
8593                                              const struct auto_pin_cfg *cfg)
8594 {
8595         hda_nid_t nid;
8596         int err;
8597
8598         spec->multiout.num_dacs = 1;    /* only use one dac */
8599         spec->multiout.dac_nids = spec->private_dac_nids;
8600         spec->multiout.dac_nids[0] = 2;
8601
8602         nid = cfg->line_out_pins[0];
8603         if (nid) {
8604                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
8605                                   "Front Playback Volume",
8606                                   HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT));
8607                 if (err < 0)
8608                         return err;
8609                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
8610                                   "Front Playback Switch",
8611                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
8612                 if (err < 0)
8613                         return err;
8614         }
8615
8616         nid = cfg->speaker_pins[0];
8617         if (nid) {
8618                 if (nid == 0x16) {
8619                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
8620                                           "Speaker Playback Volume",
8621                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
8622                                                               HDA_OUTPUT));
8623                         if (err < 0)
8624                                 return err;
8625                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
8626                                           "Speaker Playback Switch",
8627                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
8628                                                               HDA_OUTPUT));
8629                         if (err < 0)
8630                                 return err;
8631                 } else {
8632                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
8633                                           "Speaker Playback Switch",
8634                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
8635                                                               HDA_OUTPUT));
8636                         if (err < 0)
8637                                 return err;
8638                 }
8639         }
8640         nid = cfg->hp_pins[0];
8641         if (nid) {
8642                 /* spec->multiout.hp_nid = 2; */
8643                 if (nid == 0x16) {
8644                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
8645                                           "Headphone Playback Volume",
8646                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
8647                                                               HDA_OUTPUT));
8648                         if (err < 0)
8649                                 return err;
8650                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
8651                                           "Headphone Playback Switch",
8652                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
8653                                                               HDA_OUTPUT));
8654                         if (err < 0)
8655                                 return err;
8656                 } else {
8657                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
8658                                           "Headphone Playback Switch",
8659                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
8660                                                               HDA_OUTPUT));
8661                         if (err < 0)
8662                                 return err;
8663                 }
8664         }
8665         return 0;
8666 }
8667
8668 /* identical with ALC880 */
8669 #define alc262_auto_create_analog_input_ctls \
8670         alc880_auto_create_analog_input_ctls
8671
8672 /*
8673  * generic initialization of ADC, input mixers and output mixers
8674  */
8675 static struct hda_verb alc262_volume_init_verbs[] = {
8676         /*
8677          * Unmute ADC0-2 and set the default input to mic-in
8678          */
8679         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
8680         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8681         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8682         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8683         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8684         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8685
8686         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8687          * mixer widget
8688          * Note: PASD motherboards uses the Line In 2 as the input for
8689          * front panel mic (mic 2)
8690          */
8691         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8692         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8693         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8694         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8695         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8696         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8697
8698         /*
8699          * Set up output mixers (0x0c - 0x0f)
8700          */
8701         /* set vol=0 to output mixers */
8702         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8703         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8704         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8705         
8706         /* set up input amps for analog loopback */
8707         /* Amp Indices: DAC = 0, mixer = 1 */
8708         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8709         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8710         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8711         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8712         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8713         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8714
8715         /* FIXME: use matrix-type input source selection */
8716         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8717         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
8718         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8719         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8720         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8721         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8722         /* Input mixer2 */
8723         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8724         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8725         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8726         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8727         /* Input mixer3 */
8728         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8729         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8730         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8731         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8732
8733         { }
8734 };
8735
8736 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
8737         /*
8738          * Unmute ADC0-2 and set the default input to mic-in
8739          */
8740         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
8741         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8742         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8743         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8744         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8745         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8746
8747         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8748          * mixer widget
8749          * Note: PASD motherboards uses the Line In 2 as the input for
8750          * front panel mic (mic 2)
8751          */
8752         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8753         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8754         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8755         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8756         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8757         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8758         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
8759         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
8760         
8761         /*
8762          * Set up output mixers (0x0c - 0x0e)
8763          */
8764         /* set vol=0 to output mixers */
8765         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8766         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8767         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8768
8769         /* set up input amps for analog loopback */
8770         /* Amp Indices: DAC = 0, mixer = 1 */
8771         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8772         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8773         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8774         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8775         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8776         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8777
8778         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8779         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8780         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8781
8782         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8783         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8784
8785         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8786         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8787
8788         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8789         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8790         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8791         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8792         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8793
8794         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
8795         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8796         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8797         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
8798         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8799         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8800
8801
8802         /* FIXME: use matrix-type input source selection */
8803         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8804         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
8805         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8806         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
8807         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
8808         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
8809         /* Input mixer2 */
8810         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8811         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
8812         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
8813         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
8814         /* Input mixer3 */
8815         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8816         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
8817         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
8818         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
8819
8820         { }
8821 };
8822
8823 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
8824         /*
8825          * Unmute ADC0-2 and set the default input to mic-in
8826          */
8827         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
8828         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8829         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8830         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8831         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8832         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8833
8834         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8835          * mixer widget
8836          * Note: PASD motherboards uses the Line In 2 as the input for front
8837          * panel mic (mic 2)
8838          */
8839         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8840         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8841         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8842         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8843         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8844         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8845         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
8846         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
8847         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
8848         /*
8849          * Set up output mixers (0x0c - 0x0e)
8850          */
8851         /* set vol=0 to output mixers */
8852         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8853         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8854         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8855
8856         /* set up input amps for analog loopback */
8857         /* Amp Indices: DAC = 0, mixer = 1 */
8858         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8859         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8860         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8861         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8862         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8863         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8864
8865
8866         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
8867         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
8868         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
8869         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
8870         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
8871         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
8872         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
8873
8874         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8875         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8876
8877         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8878         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
8879
8880         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
8881         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8882         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8883         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
8884         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8885         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8886
8887         /* FIXME: use matrix-type input source selection */
8888         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8889         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
8890         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
8891         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
8892         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
8893         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
8894         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
8895         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
8896         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
8897         /* Input mixer2 */
8898         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8899         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8900         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
8901         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
8902         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
8903         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
8904         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
8905         /* Input mixer3 */
8906         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8907         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8908         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
8909         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
8910         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
8911         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
8912         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
8913
8914         { }
8915 };
8916
8917 #ifdef CONFIG_SND_HDA_POWER_SAVE
8918 #define alc262_loopbacks        alc880_loopbacks
8919 #endif
8920
8921 /* pcm configuration: identiacal with ALC880 */
8922 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
8923 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
8924 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
8925 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
8926
8927 /*
8928  * BIOS auto configuration
8929  */
8930 static int alc262_parse_auto_config(struct hda_codec *codec)
8931 {
8932         struct alc_spec *spec = codec->spec;
8933         int err;
8934         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
8935
8936         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
8937                                            alc262_ignore);
8938         if (err < 0)
8939                 return err;
8940         if (!spec->autocfg.line_outs)
8941                 return 0; /* can't find valid BIOS pin config */
8942         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
8943         if (err < 0)
8944                 return err;
8945         err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg);
8946         if (err < 0)
8947                 return err;
8948
8949         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
8950
8951         if (spec->autocfg.dig_out_pin)
8952                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
8953         if (spec->autocfg.dig_in_pin)
8954                 spec->dig_in_nid = ALC262_DIGIN_NID;
8955
8956         if (spec->kctl_alloc)
8957                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
8958
8959         spec->init_verbs[spec->num_init_verbs++] = alc262_volume_init_verbs;
8960         spec->num_mux_defs = 1;
8961         spec->input_mux = &spec->private_imux;
8962
8963         err = alc_auto_add_mic_boost(codec);
8964         if (err < 0)
8965                 return err;
8966
8967         return 1;
8968 }
8969
8970 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
8971 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
8972 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
8973
8974
8975 /* init callback for auto-configuration model -- overriding the default init */
8976 static void alc262_auto_init(struct hda_codec *codec)
8977 {
8978         alc262_auto_init_multi_out(codec);
8979         alc262_auto_init_hp_out(codec);
8980         alc262_auto_init_analog_input(codec);
8981 }
8982
8983 /*
8984  * configuration and preset
8985  */
8986 static const char *alc262_models[ALC262_MODEL_LAST] = {
8987         [ALC262_BASIC]          = "basic",
8988         [ALC262_HIPPO]          = "hippo",
8989         [ALC262_HIPPO_1]        = "hippo_1",
8990         [ALC262_FUJITSU]        = "fujitsu",
8991         [ALC262_HP_BPC]         = "hp-bpc",
8992         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
8993         [ALC262_HP_TC_T5735]    = "hp-tc-t5735",
8994         [ALC262_HP_RP5700]      = "hp-rp5700",
8995         [ALC262_BENQ_ED8]       = "benq",
8996         [ALC262_BENQ_T31]       = "benq-t31",
8997         [ALC262_SONY_ASSAMD]    = "sony-assamd",
8998         [ALC262_ULTRA]          = "ultra",
8999         [ALC262_AUTO]           = "auto",
9000 };
9001
9002 static struct snd_pci_quirk alc262_cfg_tbl[] = {
9003         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
9004         SND_PCI_QUIRK(0x103c, 0x12fe, "HP xw9400", ALC262_HP_BPC),
9005         SND_PCI_QUIRK(0x103c, 0x12ff, "HP xw4550", ALC262_HP_BPC),
9006         SND_PCI_QUIRK(0x103c, 0x1306, "HP xw8600", ALC262_HP_BPC),
9007         SND_PCI_QUIRK(0x103c, 0x1307, "HP xw6600", ALC262_HP_BPC),
9008         SND_PCI_QUIRK(0x103c, 0x1308, "HP xw4600", ALC262_HP_BPC),
9009         SND_PCI_QUIRK(0x103c, 0x1309, "HP xw4*00", ALC262_HP_BPC),
9010         SND_PCI_QUIRK(0x103c, 0x130a, "HP xw6*00", ALC262_HP_BPC),
9011         SND_PCI_QUIRK(0x103c, 0x130b, "HP xw8*00", ALC262_HP_BPC),
9012         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
9013         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
9014         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
9015         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
9016         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
9017         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
9018         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
9019         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
9020         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
9021         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
9022         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
9023         SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
9024                       ALC262_HP_TC_T5735),
9025         SND_PCI_QUIRK(0x103c, 0x2817, "HP RP5700", ALC262_HP_RP5700),
9026         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
9027         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
9028         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
9029         SND_PCI_QUIRK(0x104d, 0x900e, "Sony ASSAMD", ALC262_SONY_ASSAMD),
9030         SND_PCI_QUIRK(0x104d, 0x9015, "Sony 0x9015", ALC262_SONY_ASSAMD),
9031         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
9032         SND_PCI_QUIRK(0x144d, 0xc032, "Samsung Q1 Ultra", ALC262_ULTRA),
9033         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
9034         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
9035         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
9036         {}
9037 };
9038
9039 static struct alc_config_preset alc262_presets[] = {
9040         [ALC262_BASIC] = {
9041                 .mixers = { alc262_base_mixer },
9042                 .init_verbs = { alc262_init_verbs },
9043                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9044                 .dac_nids = alc262_dac_nids,
9045                 .hp_nid = 0x03,
9046                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9047                 .channel_mode = alc262_modes,
9048                 .input_mux = &alc262_capture_source,
9049         },
9050         [ALC262_HIPPO] = {
9051                 .mixers = { alc262_base_mixer },
9052                 .init_verbs = { alc262_init_verbs, alc262_hippo_unsol_verbs},
9053                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9054                 .dac_nids = alc262_dac_nids,
9055                 .hp_nid = 0x03,
9056                 .dig_out_nid = ALC262_DIGOUT_NID,
9057                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9058                 .channel_mode = alc262_modes,
9059                 .input_mux = &alc262_capture_source,
9060                 .unsol_event = alc262_hippo_unsol_event,
9061                 .init_hook = alc262_hippo_automute,
9062         },
9063         [ALC262_HIPPO_1] = {
9064                 .mixers = { alc262_hippo1_mixer },
9065                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
9066                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9067                 .dac_nids = alc262_dac_nids,
9068                 .hp_nid = 0x02,
9069                 .dig_out_nid = ALC262_DIGOUT_NID,
9070                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9071                 .channel_mode = alc262_modes,
9072                 .input_mux = &alc262_capture_source,
9073                 .unsol_event = alc262_hippo1_unsol_event,
9074                 .init_hook = alc262_hippo1_automute,
9075         },
9076         [ALC262_FUJITSU] = {
9077                 .mixers = { alc262_fujitsu_mixer },
9078                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
9079                                 alc262_fujitsu_unsol_verbs },
9080                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9081                 .dac_nids = alc262_dac_nids,
9082                 .hp_nid = 0x03,
9083                 .dig_out_nid = ALC262_DIGOUT_NID,
9084                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9085                 .channel_mode = alc262_modes,
9086                 .input_mux = &alc262_fujitsu_capture_source,
9087                 .unsol_event = alc262_fujitsu_unsol_event,
9088         },
9089         [ALC262_HP_BPC] = {
9090                 .mixers = { alc262_HP_BPC_mixer },
9091                 .init_verbs = { alc262_HP_BPC_init_verbs },
9092                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9093                 .dac_nids = alc262_dac_nids,
9094                 .hp_nid = 0x03,
9095                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9096                 .channel_mode = alc262_modes,
9097                 .input_mux = &alc262_HP_capture_source,
9098         },
9099         [ALC262_HP_BPC_D7000_WF] = {
9100                 .mixers = { alc262_HP_BPC_WildWest_mixer },
9101                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
9102                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9103                 .dac_nids = alc262_dac_nids,
9104                 .hp_nid = 0x03,
9105                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9106                 .channel_mode = alc262_modes,
9107                 .input_mux = &alc262_HP_D7000_capture_source,
9108         },
9109         [ALC262_HP_BPC_D7000_WL] = {
9110                 .mixers = { alc262_HP_BPC_WildWest_mixer,
9111                             alc262_HP_BPC_WildWest_option_mixer },
9112                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
9113                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9114                 .dac_nids = alc262_dac_nids,
9115                 .hp_nid = 0x03,
9116                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9117                 .channel_mode = alc262_modes,
9118                 .input_mux = &alc262_HP_D7000_capture_source,
9119         },
9120         [ALC262_HP_TC_T5735] = {
9121                 .mixers = { alc262_hp_t5735_mixer },
9122                 .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
9123                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9124                 .dac_nids = alc262_dac_nids,
9125                 .hp_nid = 0x03,
9126                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9127                 .channel_mode = alc262_modes,
9128                 .input_mux = &alc262_capture_source,
9129                 .unsol_event = alc262_hp_t5735_unsol_event,
9130                 .init_hook = alc262_hp_t5735_init_hook,
9131         },
9132         [ALC262_HP_RP5700] = {
9133                 .mixers = { alc262_hp_rp5700_mixer },
9134                 .init_verbs = { alc262_init_verbs, alc262_hp_rp5700_verbs },
9135                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9136                 .dac_nids = alc262_dac_nids,
9137                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9138                 .channel_mode = alc262_modes,
9139                 .input_mux = &alc262_hp_rp5700_capture_source,
9140         },
9141         [ALC262_BENQ_ED8] = {
9142                 .mixers = { alc262_base_mixer },
9143                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
9144                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9145                 .dac_nids = alc262_dac_nids,
9146                 .hp_nid = 0x03,
9147                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9148                 .channel_mode = alc262_modes,
9149                 .input_mux = &alc262_capture_source,
9150         },
9151         [ALC262_SONY_ASSAMD] = {
9152                 .mixers = { alc262_sony_mixer },
9153                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
9154                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9155                 .dac_nids = alc262_dac_nids,
9156                 .hp_nid = 0x02,
9157                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9158                 .channel_mode = alc262_modes,
9159                 .input_mux = &alc262_capture_source,
9160                 .unsol_event = alc262_hippo_unsol_event,
9161                 .init_hook = alc262_hippo_automute,
9162         },
9163         [ALC262_BENQ_T31] = {
9164                 .mixers = { alc262_benq_t31_mixer },
9165                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs, alc262_hippo_unsol_verbs },
9166                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9167                 .dac_nids = alc262_dac_nids,
9168                 .hp_nid = 0x03,
9169                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9170                 .channel_mode = alc262_modes,
9171                 .input_mux = &alc262_capture_source,
9172                 .unsol_event = alc262_hippo_unsol_event,
9173                 .init_hook = alc262_hippo_automute,
9174         },      
9175         [ALC262_ULTRA] = {
9176                 .mixers = { alc262_ultra_mixer },
9177                 .init_verbs = { alc262_init_verbs, alc262_ultra_verbs },
9178                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9179                 .dac_nids = alc262_dac_nids,
9180                 .hp_nid = 0x03,
9181                 .dig_out_nid = ALC262_DIGOUT_NID,
9182                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9183                 .channel_mode = alc262_modes,
9184                 .input_mux = &alc262_ultra_capture_source,
9185                 .unsol_event = alc262_ultra_unsol_event,
9186                 .init_hook = alc262_ultra_automute,
9187         },
9188 };
9189
9190 static int patch_alc262(struct hda_codec *codec)
9191 {
9192         struct alc_spec *spec;
9193         int board_config;
9194         int err;
9195
9196         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
9197         if (spec == NULL)
9198                 return -ENOMEM;
9199
9200         codec->spec = spec;
9201 #if 0
9202         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
9203          * under-run
9204          */
9205         {
9206         int tmp;
9207         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
9208         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
9209         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
9210         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
9211         }
9212 #endif
9213
9214         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
9215                                                   alc262_models,
9216                                                   alc262_cfg_tbl);
9217
9218         if (board_config < 0) {
9219                 printk(KERN_INFO "hda_codec: Unknown model for ALC262, "
9220                        "trying auto-probe from BIOS...\n");
9221                 board_config = ALC262_AUTO;
9222         }
9223
9224         if (board_config == ALC262_AUTO) {
9225                 /* automatic parse from the BIOS config */
9226                 err = alc262_parse_auto_config(codec);
9227                 if (err < 0) {
9228                         alc_free(codec);
9229                         return err;
9230                 } else if (!err) {
9231                         printk(KERN_INFO
9232                                "hda_codec: Cannot set up configuration "
9233                                "from BIOS.  Using base mode...\n");
9234                         board_config = ALC262_BASIC;
9235                 }
9236         }
9237
9238         if (board_config != ALC262_AUTO)
9239                 setup_preset(spec, &alc262_presets[board_config]);
9240
9241         spec->stream_name_analog = "ALC262 Analog";
9242         spec->stream_analog_playback = &alc262_pcm_analog_playback;
9243         spec->stream_analog_capture = &alc262_pcm_analog_capture;
9244                 
9245         spec->stream_name_digital = "ALC262 Digital";
9246         spec->stream_digital_playback = &alc262_pcm_digital_playback;
9247         spec->stream_digital_capture = &alc262_pcm_digital_capture;
9248
9249         if (!spec->adc_nids && spec->input_mux) {
9250                 /* check whether NID 0x07 is valid */
9251                 unsigned int wcap = get_wcaps(codec, 0x07);
9252
9253                 /* get type */
9254                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
9255                 if (wcap != AC_WID_AUD_IN) {
9256                         spec->adc_nids = alc262_adc_nids_alt;
9257                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
9258                         spec->mixers[spec->num_mixers] =
9259                                 alc262_capture_alt_mixer;
9260                         spec->num_mixers++;
9261                 } else {
9262                         spec->adc_nids = alc262_adc_nids;
9263                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
9264                         spec->mixers[spec->num_mixers] = alc262_capture_mixer;
9265                         spec->num_mixers++;
9266                 }
9267         }
9268
9269         spec->vmaster_nid = 0x0c;
9270
9271         codec->patch_ops = alc_patch_ops;
9272         if (board_config == ALC262_AUTO)
9273                 spec->init_hook = alc262_auto_init;
9274 #ifdef CONFIG_SND_HDA_POWER_SAVE
9275         if (!spec->loopback.amplist)
9276                 spec->loopback.amplist = alc262_loopbacks;
9277 #endif
9278                 
9279         return 0;
9280 }
9281
9282 /*
9283  *  ALC268 channel source setting (2 channel)
9284  */
9285 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
9286 #define alc268_modes            alc260_modes
9287         
9288 static hda_nid_t alc268_dac_nids[2] = {
9289         /* front, hp */
9290         0x02, 0x03
9291 };
9292
9293 static hda_nid_t alc268_adc_nids[2] = {
9294         /* ADC0-1 */
9295         0x08, 0x07
9296 };
9297
9298 static hda_nid_t alc268_adc_nids_alt[1] = {
9299         /* ADC0 */
9300         0x08
9301 };
9302
9303 static struct snd_kcontrol_new alc268_base_mixer[] = {
9304         /* output mixer control */
9305         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
9306         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9307         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
9308         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9309         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9310         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9311         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
9312         { }
9313 };
9314
9315 static struct hda_verb alc268_eapd_verbs[] = {
9316         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
9317         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
9318         { }
9319 };
9320
9321 /* Toshiba specific */
9322 #define alc268_toshiba_automute alc262_hippo_automute
9323
9324 static struct hda_verb alc268_toshiba_verbs[] = {
9325         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9326         { } /* end */
9327 };
9328
9329 /* Acer specific */
9330 /* bind volumes of both NID 0x02 and 0x03 */
9331 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
9332         .ops = &snd_hda_bind_vol,
9333         .values = {
9334                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
9335                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
9336                 0
9337         },
9338 };
9339
9340 /* mute/unmute internal speaker according to the hp jack and mute state */
9341 static void alc268_acer_automute(struct hda_codec *codec, int force)
9342 {
9343         struct alc_spec *spec = codec->spec;
9344         unsigned int mute;
9345
9346         if (force || !spec->sense_updated) {
9347                 unsigned int present;
9348                 present = snd_hda_codec_read(codec, 0x14, 0,
9349                                          AC_VERB_GET_PIN_SENSE, 0);
9350                 spec->jack_present = (present & 0x80000000) != 0;
9351                 spec->sense_updated = 1;
9352         }
9353         if (spec->jack_present)
9354                 mute = HDA_AMP_MUTE; /* mute internal speaker */
9355         else /* unmute internal speaker if necessary */
9356                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
9357         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9358                                  HDA_AMP_MUTE, mute);
9359 }
9360
9361
9362 /* bind hp and internal speaker mute (with plug check) */
9363 static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
9364                                      struct snd_ctl_elem_value *ucontrol)
9365 {
9366         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9367         long *valp = ucontrol->value.integer.value;
9368         int change;
9369
9370         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
9371                                           HDA_AMP_MUTE,
9372                                           valp[0] ? 0 : HDA_AMP_MUTE);
9373         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
9374                                            HDA_AMP_MUTE,
9375                                            valp[1] ? 0 : HDA_AMP_MUTE);
9376         if (change)
9377                 alc268_acer_automute(codec, 0);
9378         return change;
9379 }
9380
9381 static struct snd_kcontrol_new alc268_acer_mixer[] = {
9382         /* output mixer control */
9383         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
9384         {
9385                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9386                 .name = "Master Playback Switch",
9387                 .info = snd_hda_mixer_amp_switch_info,
9388                 .get = snd_hda_mixer_amp_switch_get,
9389                 .put = alc268_acer_master_sw_put,
9390                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
9391         },
9392         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9393         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
9394         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
9395         { }
9396 };
9397
9398 static struct hda_verb alc268_acer_verbs[] = {
9399         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9400         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9401
9402         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9403         { }
9404 };
9405
9406 /* unsolicited event for HP jack sensing */
9407 static void alc268_toshiba_unsol_event(struct hda_codec *codec,
9408                                        unsigned int res)
9409 {
9410         if ((res >> 26) != ALC880_HP_EVENT)
9411                 return;
9412         alc268_toshiba_automute(codec);
9413 }
9414
9415 static void alc268_acer_unsol_event(struct hda_codec *codec,
9416                                        unsigned int res)
9417 {
9418         if ((res >> 26) != ALC880_HP_EVENT)
9419                 return;
9420         alc268_acer_automute(codec, 1);
9421 }
9422
9423 static void alc268_acer_init_hook(struct hda_codec *codec)
9424 {
9425         alc268_acer_automute(codec, 1);
9426 }
9427
9428 static struct snd_kcontrol_new alc268_dell_mixer[] = {
9429         /* output mixer control */
9430         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
9431         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9432         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
9433         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9434         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9435         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
9436         { }
9437 };
9438
9439 static struct hda_verb alc268_dell_verbs[] = {
9440         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9441         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9442         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9443         { }
9444 };
9445
9446 /* mute/unmute internal speaker according to the hp jack and mute state */
9447 static void alc268_dell_automute(struct hda_codec *codec)
9448 {
9449         unsigned int present;
9450         unsigned int mute;
9451
9452         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0);
9453         if (present & 0x80000000)
9454                 mute = HDA_AMP_MUTE;
9455         else
9456                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
9457         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9458                                  HDA_AMP_MUTE, mute);
9459 }
9460
9461 static void alc268_dell_unsol_event(struct hda_codec *codec,
9462                                     unsigned int res)
9463 {
9464         if ((res >> 26) != ALC880_HP_EVENT)
9465                 return;
9466         alc268_dell_automute(codec);
9467 }
9468
9469 #define alc268_dell_init_hook   alc268_dell_automute
9470
9471 /*
9472  * generic initialization of ADC, input mixers and output mixers
9473  */
9474 static struct hda_verb alc268_base_init_verbs[] = {
9475         /* Unmute DAC0-1 and set vol = 0 */
9476         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9477         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9478         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9479         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9480         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9481         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9482
9483         /*
9484          * Set up output mixers (0x0c - 0x0e)
9485          */
9486         /* set vol=0 to output mixers */
9487         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9488         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9489         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9490         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
9491
9492         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9493         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9494
9495         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9496         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9497         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9498         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9499         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9500         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9501         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9502         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9503
9504         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9505         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9506         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9507         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9508         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9509         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9510         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9511         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9512
9513         /* Unmute Selector 23h,24h and set the default input to mic-in */
9514         
9515         {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
9516         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9517         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
9518         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9519
9520         { }
9521 };
9522
9523 /*
9524  * generic initialization of ADC, input mixers and output mixers
9525  */
9526 static struct hda_verb alc268_volume_init_verbs[] = {
9527         /* set output DAC */
9528         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9529         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9530         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9531         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9532
9533         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9534         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9535         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9536         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9537         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9538
9539         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9540         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9541         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9542         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9543         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9544
9545         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9546         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9547         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9548         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9549
9550         /* set PCBEEP vol = 0 */
9551         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, (0xb000 | (0x00 << 8))},
9552
9553         { }
9554 };
9555
9556 #define alc268_mux_enum_info alc_mux_enum_info
9557 #define alc268_mux_enum_get alc_mux_enum_get
9558
9559 static int alc268_mux_enum_put(struct snd_kcontrol *kcontrol,
9560                                struct snd_ctl_elem_value *ucontrol)
9561 {
9562         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9563         struct alc_spec *spec = codec->spec;
9564
9565         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
9566         static hda_nid_t capture_mixers[3] = { 0x23, 0x24 };
9567         hda_nid_t nid = capture_mixers[adc_idx];
9568
9569         return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
9570                                      nid,
9571                                      &spec->cur_mux[adc_idx]);
9572 }
9573
9574 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
9575         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
9576         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
9577         {
9578                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9579                 /* The multiple "Capture Source" controls confuse alsamixer
9580                  * So call somewhat different..
9581                  */
9582                 /* .name = "Capture Source", */
9583                 .name = "Input Source",
9584                 .count = 1,
9585                 .info = alc268_mux_enum_info,
9586                 .get = alc268_mux_enum_get,
9587                 .put = alc268_mux_enum_put,
9588         },
9589         { } /* end */
9590 };
9591
9592 static struct snd_kcontrol_new alc268_capture_mixer[] = {
9593         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
9594         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
9595         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
9596         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
9597         {
9598                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9599                 /* The multiple "Capture Source" controls confuse alsamixer
9600                  * So call somewhat different..
9601                  */
9602                 /* .name = "Capture Source", */
9603                 .name = "Input Source",
9604                 .count = 2,
9605                 .info = alc268_mux_enum_info,
9606                 .get = alc268_mux_enum_get,
9607                 .put = alc268_mux_enum_put,
9608         },
9609         { } /* end */
9610 };
9611
9612 static struct hda_input_mux alc268_capture_source = {
9613         .num_items = 4,
9614         .items = {
9615                 { "Mic", 0x0 },
9616                 { "Front Mic", 0x1 },
9617                 { "Line", 0x2 },
9618                 { "CD", 0x3 },
9619         },
9620 };
9621
9622 #ifdef CONFIG_SND_DEBUG
9623 static struct snd_kcontrol_new alc268_test_mixer[] = {
9624         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
9625         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9626         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
9627         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9628
9629         /* Volume widgets */
9630         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
9631         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
9632         HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
9633         HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
9634         HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
9635         HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
9636         HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
9637         HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
9638         HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
9639         HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
9640         HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
9641         HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
9642         HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
9643         /* The below appears problematic on some hardwares */
9644         /*HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),*/
9645         HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
9646         HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
9647         HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
9648         HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),
9649
9650         /* Modes for retasking pin widgets */
9651         ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
9652         ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
9653         ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
9654         ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),
9655
9656         /* Controls for GPIO pins, assuming they are configured as outputs */
9657         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
9658         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
9659         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
9660         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
9661
9662         /* Switches to allow the digital SPDIF output pin to be enabled.
9663          * The ALC268 does not have an SPDIF input.
9664          */
9665         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),
9666
9667         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
9668          * this output to turn on an external amplifier.
9669          */
9670         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
9671         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
9672
9673         { } /* end */
9674 };
9675 #endif
9676
9677 /* create input playback/capture controls for the given pin */
9678 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
9679                                     const char *ctlname, int idx)
9680 {
9681         char name[32];
9682         int err;
9683
9684         sprintf(name, "%s Playback Volume", ctlname);
9685         if (nid == 0x14) {
9686                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
9687                                   HDA_COMPOSE_AMP_VAL(0x02, 3, idx,
9688                                                       HDA_OUTPUT));
9689                 if (err < 0)
9690                         return err;
9691         } else if (nid == 0x15) {
9692                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
9693                                   HDA_COMPOSE_AMP_VAL(0x03, 3, idx,
9694                                                       HDA_OUTPUT));
9695                 if (err < 0)
9696                         return err;
9697         } else
9698                 return -1;
9699         sprintf(name, "%s Playback Switch", ctlname);
9700         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
9701                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
9702         if (err < 0)
9703                 return err;
9704         return 0;
9705 }
9706
9707 /* add playback controls from the parsed DAC table */
9708 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
9709                                              const struct auto_pin_cfg *cfg)
9710 {
9711         hda_nid_t nid;
9712         int err;
9713
9714         spec->multiout.num_dacs = 2;    /* only use one dac */
9715         spec->multiout.dac_nids = spec->private_dac_nids;
9716         spec->multiout.dac_nids[0] = 2;
9717         spec->multiout.dac_nids[1] = 3;
9718
9719         nid = cfg->line_out_pins[0];
9720         if (nid)
9721                 alc268_new_analog_output(spec, nid, "Front", 0);        
9722
9723         nid = cfg->speaker_pins[0];
9724         if (nid == 0x1d) {
9725                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
9726                                   "Speaker Playback Volume",
9727                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
9728                 if (err < 0)
9729                         return err;
9730         }
9731         nid = cfg->hp_pins[0];
9732         if (nid)
9733                 alc268_new_analog_output(spec, nid, "Headphone", 0);
9734
9735         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
9736         if (nid == 0x16) {
9737                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9738                                   "Mono Playback Switch",
9739                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_INPUT));
9740                 if (err < 0)
9741                         return err;
9742         }
9743         return 0;       
9744 }
9745
9746 /* create playback/capture controls for input pins */
9747 static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
9748                                                 const struct auto_pin_cfg *cfg)
9749 {
9750         struct hda_input_mux *imux = &spec->private_imux;
9751         int i, idx1;
9752
9753         for (i = 0; i < AUTO_PIN_LAST; i++) {
9754                 switch(cfg->input_pins[i]) {
9755                 case 0x18:
9756                         idx1 = 0;       /* Mic 1 */
9757                         break;
9758                 case 0x19:
9759                         idx1 = 1;       /* Mic 2 */
9760                         break;
9761                 case 0x1a:
9762                         idx1 = 2;       /* Line In */
9763                         break;
9764                 case 0x1c:      
9765                         idx1 = 3;       /* CD */
9766                         break;
9767                 default:
9768                         continue;
9769                 }
9770                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
9771                 imux->items[imux->num_items].index = idx1;
9772                 imux->num_items++;      
9773         }
9774         return 0;
9775 }
9776
9777 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
9778 {
9779         struct alc_spec *spec = codec->spec;
9780         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
9781         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
9782         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
9783         unsigned int    dac_vol1, dac_vol2;
9784
9785         if (speaker_nid) {
9786                 snd_hda_codec_write(codec, speaker_nid, 0,
9787                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
9788                 snd_hda_codec_write(codec, 0x0f, 0,
9789                                     AC_VERB_SET_AMP_GAIN_MUTE,
9790                                     AMP_IN_UNMUTE(1));
9791                 snd_hda_codec_write(codec, 0x10, 0,
9792                                     AC_VERB_SET_AMP_GAIN_MUTE,
9793                                     AMP_IN_UNMUTE(1));
9794         } else {
9795                 snd_hda_codec_write(codec, 0x0f, 0,
9796                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
9797                 snd_hda_codec_write(codec, 0x10, 0,
9798                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
9799         }
9800
9801         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
9802         if (line_nid == 0x14)   
9803                 dac_vol2 = AMP_OUT_ZERO;
9804         else if (line_nid == 0x15)
9805                 dac_vol1 = AMP_OUT_ZERO;
9806         if (hp_nid == 0x14)     
9807                 dac_vol2 = AMP_OUT_ZERO;
9808         else if (hp_nid == 0x15)
9809                 dac_vol1 = AMP_OUT_ZERO;
9810         if (line_nid != 0x16 || hp_nid != 0x16 ||
9811             spec->autocfg.line_out_pins[1] != 0x16 ||
9812             spec->autocfg.line_out_pins[2] != 0x16)
9813                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
9814
9815         snd_hda_codec_write(codec, 0x02, 0,
9816                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
9817         snd_hda_codec_write(codec, 0x03, 0,
9818                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
9819 }
9820
9821 /* pcm configuration: identiacal with ALC880 */
9822 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
9823 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
9824 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
9825
9826 /*
9827  * BIOS auto configuration
9828  */
9829 static int alc268_parse_auto_config(struct hda_codec *codec)
9830 {
9831         struct alc_spec *spec = codec->spec;
9832         int err;
9833         static hda_nid_t alc268_ignore[] = { 0 };
9834
9835         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
9836                                            alc268_ignore);
9837         if (err < 0)
9838                 return err;
9839         if (!spec->autocfg.line_outs)
9840                 return 0; /* can't find valid BIOS pin config */
9841
9842         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
9843         if (err < 0)
9844                 return err;
9845         err = alc268_auto_create_analog_input_ctls(spec, &spec->autocfg);
9846         if (err < 0)
9847                 return err;
9848
9849         spec->multiout.max_channels = 2;
9850
9851         /* digital only support output */
9852         if (spec->autocfg.dig_out_pin)
9853                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
9854
9855         if (spec->kctl_alloc)
9856                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
9857
9858         spec->init_verbs[spec->num_init_verbs++] = alc268_volume_init_verbs;
9859         spec->num_mux_defs = 1;
9860         spec->input_mux = &spec->private_imux;
9861
9862         err = alc_auto_add_mic_boost(codec);
9863         if (err < 0)
9864                 return err;
9865
9866         return 1;
9867 }
9868
9869 #define alc268_auto_init_multi_out      alc882_auto_init_multi_out
9870 #define alc268_auto_init_hp_out         alc882_auto_init_hp_out
9871 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
9872
9873 /* init callback for auto-configuration model -- overriding the default init */
9874 static void alc268_auto_init(struct hda_codec *codec)
9875 {
9876         alc268_auto_init_multi_out(codec);
9877         alc268_auto_init_hp_out(codec);
9878         alc268_auto_init_mono_speaker_out(codec);
9879         alc268_auto_init_analog_input(codec);
9880 }
9881
9882 /*
9883  * configuration and preset
9884  */
9885 static const char *alc268_models[ALC268_MODEL_LAST] = {
9886         [ALC268_3ST]            = "3stack",
9887         [ALC268_TOSHIBA]        = "toshiba",
9888         [ALC268_ACER]           = "acer",
9889         [ALC268_DELL]           = "dell",
9890 #ifdef CONFIG_SND_DEBUG
9891         [ALC268_TEST]           = "test",
9892 #endif
9893         [ALC268_AUTO]           = "auto",
9894 };
9895
9896 static struct snd_pci_quirk alc268_cfg_tbl[] = {
9897         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
9898         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
9899         SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
9900         SND_PCI_QUIRK(0x103c, 0x30cc, "TOSHIBA", ALC268_TOSHIBA),
9901         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
9902         SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA),
9903         SND_PCI_QUIRK(0x1179, 0xff50, "TOSHIBA A305", ALC268_TOSHIBA),
9904         SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
9905         {}
9906 };
9907
9908 static struct alc_config_preset alc268_presets[] = {
9909         [ALC268_3ST] = {
9910                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer },
9911                 .init_verbs = { alc268_base_init_verbs },
9912                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
9913                 .dac_nids = alc268_dac_nids,
9914                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
9915                 .adc_nids = alc268_adc_nids_alt,
9916                 .hp_nid = 0x03,
9917                 .dig_out_nid = ALC268_DIGOUT_NID,
9918                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
9919                 .channel_mode = alc268_modes,
9920                 .input_mux = &alc268_capture_source,
9921         },
9922         [ALC268_TOSHIBA] = {
9923                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer },
9924                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
9925                                 alc268_toshiba_verbs },
9926                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
9927                 .dac_nids = alc268_dac_nids,
9928                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
9929                 .adc_nids = alc268_adc_nids_alt,
9930                 .hp_nid = 0x03,
9931                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
9932                 .channel_mode = alc268_modes,
9933                 .input_mux = &alc268_capture_source,
9934                 .unsol_event = alc268_toshiba_unsol_event,
9935                 .init_hook = alc268_toshiba_automute,
9936         },
9937         [ALC268_ACER] = {
9938                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer },
9939                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
9940                                 alc268_acer_verbs },
9941                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
9942                 .dac_nids = alc268_dac_nids,
9943                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
9944                 .adc_nids = alc268_adc_nids_alt,
9945                 .hp_nid = 0x02,
9946                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
9947                 .channel_mode = alc268_modes,
9948                 .input_mux = &alc268_capture_source,
9949                 .unsol_event = alc268_acer_unsol_event,
9950                 .init_hook = alc268_acer_init_hook,
9951         },
9952         [ALC268_DELL] = {
9953                 .mixers = { alc268_dell_mixer },
9954                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
9955                                 alc268_dell_verbs },
9956                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
9957                 .dac_nids = alc268_dac_nids,
9958                 .hp_nid = 0x02,
9959                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
9960                 .channel_mode = alc268_modes,
9961                 .unsol_event = alc268_dell_unsol_event,
9962                 .init_hook = alc268_dell_init_hook,
9963                 .input_mux = &alc268_capture_source,
9964         },
9965 #ifdef CONFIG_SND_DEBUG
9966         [ALC268_TEST] = {
9967                 .mixers = { alc268_test_mixer, alc268_capture_mixer },
9968                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
9969                                 alc268_volume_init_verbs },
9970                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
9971                 .dac_nids = alc268_dac_nids,
9972                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
9973                 .adc_nids = alc268_adc_nids_alt,
9974                 .hp_nid = 0x03,
9975                 .dig_out_nid = ALC268_DIGOUT_NID,
9976                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
9977                 .channel_mode = alc268_modes,
9978                 .input_mux = &alc268_capture_source,
9979         },
9980 #endif
9981 };
9982
9983 static int patch_alc268(struct hda_codec *codec)
9984 {
9985         struct alc_spec *spec;
9986         int board_config;
9987         int err;
9988
9989         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
9990         if (spec == NULL)
9991                 return -ENOMEM;
9992
9993         codec->spec = spec;
9994
9995         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
9996                                                   alc268_models,
9997                                                   alc268_cfg_tbl);
9998
9999         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
10000                 printk(KERN_INFO "hda_codec: Unknown model for ALC268, "
10001                        "trying auto-probe from BIOS...\n");
10002                 board_config = ALC268_AUTO;
10003         }
10004
10005         if (board_config == ALC268_AUTO) {
10006                 /* automatic parse from the BIOS config */
10007                 err = alc268_parse_auto_config(codec);
10008                 if (err < 0) {
10009                         alc_free(codec);
10010                         return err;
10011                 } else if (!err) {
10012                         printk(KERN_INFO
10013                                "hda_codec: Cannot set up configuration "
10014                                "from BIOS.  Using base mode...\n");
10015                         board_config = ALC268_3ST;
10016                 }
10017         }
10018
10019         if (board_config != ALC268_AUTO)
10020                 setup_preset(spec, &alc268_presets[board_config]);
10021
10022         spec->stream_name_analog = "ALC268 Analog";
10023         spec->stream_analog_playback = &alc268_pcm_analog_playback;
10024         spec->stream_analog_capture = &alc268_pcm_analog_capture;
10025
10026         spec->stream_name_digital = "ALC268 Digital";
10027         spec->stream_digital_playback = &alc268_pcm_digital_playback;
10028
10029         if (!spec->adc_nids && spec->input_mux) {
10030                 /* check whether NID 0x07 is valid */
10031                 unsigned int wcap = get_wcaps(codec, 0x07);
10032
10033                 /* get type */
10034                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
10035                 if (wcap != AC_WID_AUD_IN) {
10036                         spec->adc_nids = alc268_adc_nids_alt;
10037                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
10038                         spec->mixers[spec->num_mixers] =
10039                                         alc268_capture_alt_mixer;
10040                         spec->num_mixers++;
10041                 } else {
10042                         spec->adc_nids = alc268_adc_nids;
10043                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
10044                         spec->mixers[spec->num_mixers] =
10045                                 alc268_capture_mixer;
10046                         spec->num_mixers++;
10047                 }
10048         }
10049
10050         spec->vmaster_nid = 0x02;
10051
10052         codec->patch_ops = alc_patch_ops;
10053         if (board_config == ALC268_AUTO)
10054                 spec->init_hook = alc268_auto_init;
10055                 
10056         return 0;
10057 }
10058
10059 /*
10060  *  ALC269 channel source setting (2 channel)
10061  */
10062 #define ALC269_DIGOUT_NID       ALC880_DIGOUT_NID
10063
10064 #define alc269_dac_nids         alc260_dac_nids
10065
10066 static hda_nid_t alc269_adc_nids[1] = {
10067         /* ADC1 */
10068         0x07,
10069 };
10070
10071 #define alc269_modes            alc260_modes
10072 #define alc269_capture_source   alc880_lg_lw_capture_source
10073
10074 static struct snd_kcontrol_new alc269_base_mixer[] = {
10075         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10076         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10077         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10078         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10079         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10080         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10081         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10082         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10083         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10084         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10085         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10086         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
10087         { } /* end */
10088 };
10089
10090 /* capture mixer elements */
10091 static struct snd_kcontrol_new alc269_capture_mixer[] = {
10092         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
10093         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
10094         {
10095                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10096                 /* The multiple "Capture Source" controls confuse alsamixer
10097                  * So call somewhat different..
10098                  */
10099                 /* .name = "Capture Source", */
10100                 .name = "Input Source",
10101                 .count = 1,
10102                 .info = alc_mux_enum_info,
10103                 .get = alc_mux_enum_get,
10104                 .put = alc_mux_enum_put,
10105         },
10106         { } /* end */
10107 };
10108
10109 /*
10110  * generic initialization of ADC, input mixers and output mixers
10111  */
10112 static struct hda_verb alc269_init_verbs[] = {
10113         /*
10114          * Unmute ADC0 and set the default input to mic-in
10115          */
10116         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10117
10118         /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the
10119          * analog-loopback mixer widget
10120          * Note: PASD motherboards uses the Line In 2 as the input for
10121          * front panel mic (mic 2)
10122          */
10123         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10124         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10125         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10126         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10127         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10128         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10129
10130         /*
10131          * Set up output mixers (0x0c - 0x0e)
10132          */
10133         /* set vol=0 to output mixers */
10134         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10135         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10136
10137         /* set up input amps for analog loopback */
10138         /* Amp Indices: DAC = 0, mixer = 1 */
10139         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10140         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10141         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10142         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10143         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10144         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10145
10146         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10147         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10148         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10149         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10150         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10151         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10152         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10153
10154         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10155         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10156         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10157         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10158         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10159         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10160         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10161
10162         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
10163         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10164
10165         /* FIXME: use matrix-type input source selection */
10166         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
10167         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10168         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10169         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10170         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10171         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10172
10173         /* set EAPD */
10174         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
10175         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
10176         { }
10177 };
10178
10179 /* add playback controls from the parsed DAC table */
10180 static int alc269_auto_create_multi_out_ctls(struct alc_spec *spec,
10181                                              const struct auto_pin_cfg *cfg)
10182 {
10183         hda_nid_t nid;
10184         int err;
10185
10186         spec->multiout.num_dacs = 1;    /* only use one dac */
10187         spec->multiout.dac_nids = spec->private_dac_nids;
10188         spec->multiout.dac_nids[0] = 2;
10189
10190         nid = cfg->line_out_pins[0];
10191         if (nid) {
10192                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
10193                                   "Front Playback Volume",
10194                                   HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT));
10195                 if (err < 0)
10196                         return err;
10197                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10198                                   "Front Playback Switch",
10199                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
10200                 if (err < 0)
10201                         return err;
10202         }
10203
10204         nid = cfg->speaker_pins[0];
10205         if (nid) {
10206                 if (!cfg->line_out_pins[0]) {
10207                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10208                                           "Speaker Playback Volume",
10209                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
10210                                                               HDA_OUTPUT));
10211                         if (err < 0)
10212                                 return err;
10213                 }
10214                 if (nid == 0x16) {
10215                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10216                                           "Speaker Playback Switch",
10217                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10218                                                               HDA_OUTPUT));
10219                         if (err < 0)
10220                                 return err;
10221                 } else {
10222                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10223                                           "Speaker Playback Switch",
10224                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10225                                                               HDA_OUTPUT));
10226                         if (err < 0)
10227                                 return err;
10228                 }
10229         }
10230         nid = cfg->hp_pins[0];
10231         if (nid) {
10232                 /* spec->multiout.hp_nid = 2; */
10233                 if (!cfg->line_out_pins[0] && !cfg->speaker_pins[0]) {
10234                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10235                                           "Headphone Playback Volume",
10236                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
10237                                                               HDA_OUTPUT));
10238                         if (err < 0)
10239                                 return err;
10240                 }
10241                 if (nid == 0x16) {
10242                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10243                                           "Headphone Playback Switch",
10244                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10245                                                               HDA_OUTPUT));
10246                         if (err < 0)
10247                                 return err;
10248                 } else {
10249                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10250                                           "Headphone Playback Switch",
10251                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10252                                                               HDA_OUTPUT));
10253                         if (err < 0)
10254                                 return err;
10255                 }
10256         }
10257         return 0;
10258 }
10259
10260 #define alc269_auto_create_analog_input_ctls \
10261         alc880_auto_create_analog_input_ctls
10262
10263 #ifdef CONFIG_SND_HDA_POWER_SAVE
10264 #define alc269_loopbacks        alc880_loopbacks
10265 #endif
10266
10267 /* pcm configuration: identiacal with ALC880 */
10268 #define alc269_pcm_analog_playback      alc880_pcm_analog_playback
10269 #define alc269_pcm_analog_capture       alc880_pcm_analog_capture
10270 #define alc269_pcm_digital_playback     alc880_pcm_digital_playback
10271 #define alc269_pcm_digital_capture      alc880_pcm_digital_capture
10272
10273 /*
10274  * BIOS auto configuration
10275  */
10276 static int alc269_parse_auto_config(struct hda_codec *codec)
10277 {
10278         struct alc_spec *spec = codec->spec;
10279         int err;
10280         static hda_nid_t alc269_ignore[] = { 0x1d, 0 };
10281
10282         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
10283                                            alc269_ignore);
10284         if (err < 0)
10285                 return err;
10286
10287         err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
10288         if (err < 0)
10289                 return err;
10290         err = alc269_auto_create_analog_input_ctls(spec, &spec->autocfg);
10291         if (err < 0)
10292                 return err;
10293
10294         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
10295
10296         if (spec->autocfg.dig_out_pin)
10297                 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;
10298
10299         if (spec->kctl_alloc)
10300                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
10301
10302         spec->init_verbs[spec->num_init_verbs++] = alc269_init_verbs;
10303         spec->num_mux_defs = 1;
10304         spec->input_mux = &spec->private_imux;
10305
10306         err = alc_auto_add_mic_boost(codec);
10307         if (err < 0)
10308                 return err;
10309
10310         return 1;
10311 }
10312
10313 #define alc269_auto_init_multi_out      alc882_auto_init_multi_out
10314 #define alc269_auto_init_hp_out         alc882_auto_init_hp_out
10315 #define alc269_auto_init_analog_input   alc882_auto_init_analog_input
10316
10317
10318 /* init callback for auto-configuration model -- overriding the default init */
10319 static void alc269_auto_init(struct hda_codec *codec)
10320 {
10321         alc269_auto_init_multi_out(codec);
10322         alc269_auto_init_hp_out(codec);
10323         alc269_auto_init_analog_input(codec);
10324 }
10325
10326 /*
10327  * configuration and preset
10328  */
10329 static const char *alc269_models[ALC269_MODEL_LAST] = {
10330         [ALC269_BASIC]          = "basic",
10331 };
10332
10333 static struct snd_pci_quirk alc269_cfg_tbl[] = {
10334         {}
10335 };
10336
10337 static struct alc_config_preset alc269_presets[] = {
10338         [ALC269_BASIC] = {
10339                 .mixers = { alc269_base_mixer },
10340                 .init_verbs = { alc269_init_verbs },
10341                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
10342                 .dac_nids = alc269_dac_nids,
10343                 .hp_nid = 0x03,
10344                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
10345                 .channel_mode = alc269_modes,
10346                 .input_mux = &alc269_capture_source,
10347         },
10348 };
10349
10350 static int patch_alc269(struct hda_codec *codec)
10351 {
10352         struct alc_spec *spec;
10353         int board_config;
10354         int err;
10355
10356         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
10357         if (spec == NULL)
10358                 return -ENOMEM;
10359
10360         codec->spec = spec;
10361
10362         board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
10363                                                   alc269_models,
10364                                                   alc269_cfg_tbl);
10365
10366         if (board_config < 0) {
10367                 printk(KERN_INFO "hda_codec: Unknown model for ALC269, "
10368                        "trying auto-probe from BIOS...\n");
10369                 board_config = ALC269_AUTO;
10370         }
10371
10372         if (board_config == ALC269_AUTO) {
10373                 /* automatic parse from the BIOS config */
10374                 err = alc269_parse_auto_config(codec);
10375                 if (err < 0) {
10376                         alc_free(codec);
10377                         return err;
10378                 } else if (!err) {
10379                         printk(KERN_INFO
10380                                "hda_codec: Cannot set up configuration "
10381                                "from BIOS.  Using base mode...\n");
10382                         board_config = ALC269_BASIC;
10383                 }
10384         }
10385
10386         if (board_config != ALC269_AUTO)
10387                 setup_preset(spec, &alc269_presets[board_config]);
10388
10389         spec->stream_name_analog = "ALC269 Analog";
10390         spec->stream_analog_playback = &alc269_pcm_analog_playback;
10391         spec->stream_analog_capture = &alc269_pcm_analog_capture;
10392
10393         spec->stream_name_digital = "ALC269 Digital";
10394         spec->stream_digital_playback = &alc269_pcm_digital_playback;
10395         spec->stream_digital_capture = &alc269_pcm_digital_capture;
10396
10397         spec->adc_nids = alc269_adc_nids;
10398         spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
10399         spec->mixers[spec->num_mixers] = alc269_capture_mixer;
10400         spec->num_mixers++;
10401
10402         codec->patch_ops = alc_patch_ops;
10403         if (board_config == ALC269_AUTO)
10404                 spec->init_hook = alc269_auto_init;
10405 #ifdef CONFIG_SND_HDA_POWER_SAVE
10406         if (!spec->loopback.amplist)
10407                 spec->loopback.amplist = alc269_loopbacks;
10408 #endif
10409
10410         return 0;
10411 }
10412
10413 /*
10414  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
10415  */
10416
10417 /*
10418  * set the path ways for 2 channel output
10419  * need to set the codec line out and mic 1 pin widgets to inputs
10420  */
10421 static struct hda_verb alc861_threestack_ch2_init[] = {
10422         /* set pin widget 1Ah (line in) for input */
10423         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
10424         /* set pin widget 18h (mic1/2) for input, for mic also enable
10425          * the vref
10426          */
10427         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10428
10429         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
10430 #if 0
10431         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
10432         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
10433 #endif
10434         { } /* end */
10435 };
10436 /*
10437  * 6ch mode
10438  * need to set the codec line out and mic 1 pin widgets to outputs
10439  */
10440 static struct hda_verb alc861_threestack_ch6_init[] = {
10441         /* set pin widget 1Ah (line in) for output (Back Surround)*/
10442         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10443         /* set pin widget 18h (mic1) for output (CLFE)*/
10444         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10445
10446         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
10447         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
10448
10449         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
10450 #if 0
10451         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
10452         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
10453 #endif
10454         { } /* end */
10455 };
10456
10457 static struct hda_channel_mode alc861_threestack_modes[2] = {
10458         { 2, alc861_threestack_ch2_init },
10459         { 6, alc861_threestack_ch6_init },
10460 };
10461 /* Set mic1 as input and unmute the mixer */
10462 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
10463         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10464         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
10465         { } /* end */
10466 };
10467 /* Set mic1 as output and mute mixer */
10468 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
10469         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10470         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
10471         { } /* end */
10472 };
10473
10474 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
10475         { 2, alc861_uniwill_m31_ch2_init },
10476         { 4, alc861_uniwill_m31_ch4_init },
10477 };
10478
10479 /* Set mic1 and line-in as input and unmute the mixer */
10480 static struct hda_verb alc861_asus_ch2_init[] = {
10481         /* set pin widget 1Ah (line in) for input */
10482         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
10483         /* set pin widget 18h (mic1/2) for input, for mic also enable
10484          * the vref
10485          */
10486         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10487
10488         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
10489 #if 0
10490         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
10491         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
10492 #endif
10493         { } /* end */
10494 };
10495 /* Set mic1 nad line-in as output and mute mixer */
10496 static struct hda_verb alc861_asus_ch6_init[] = {
10497         /* set pin widget 1Ah (line in) for output (Back Surround)*/
10498         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10499         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
10500         /* set pin widget 18h (mic1) for output (CLFE)*/
10501         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10502         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
10503         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
10504         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
10505
10506         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
10507 #if 0
10508         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
10509         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
10510 #endif
10511         { } /* end */
10512 };
10513
10514 static struct hda_channel_mode alc861_asus_modes[2] = {
10515         { 2, alc861_asus_ch2_init },
10516         { 6, alc861_asus_ch6_init },
10517 };
10518
10519 /* patch-ALC861 */
10520
10521 static struct snd_kcontrol_new alc861_base_mixer[] = {
10522         /* output mixer control */
10523         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
10524         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
10525         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
10526         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
10527         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
10528
10529         /*Input mixer control */
10530         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
10531            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
10532         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
10533         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
10534         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
10535         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
10536         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
10537         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
10538         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
10539         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
10540
10541         /* Capture mixer control */
10542         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
10543         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
10544         {
10545                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10546                 .name = "Capture Source",
10547                 .count = 1,
10548                 .info = alc_mux_enum_info,
10549                 .get = alc_mux_enum_get,
10550                 .put = alc_mux_enum_put,
10551         },
10552         { } /* end */
10553 };
10554
10555 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
10556         /* output mixer control */
10557         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
10558         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
10559         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
10560         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
10561         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
10562
10563         /* Input mixer control */
10564         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
10565            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
10566         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
10567         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
10568         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
10569         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
10570         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
10571         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
10572         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
10573         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
10574
10575         /* Capture mixer control */
10576         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
10577         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
10578         {
10579                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10580                 .name = "Capture Source",
10581                 .count = 1,
10582                 .info = alc_mux_enum_info,
10583                 .get = alc_mux_enum_get,
10584                 .put = alc_mux_enum_put,
10585         },
10586         {
10587                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10588                 .name = "Channel Mode",
10589                 .info = alc_ch_mode_info,
10590                 .get = alc_ch_mode_get,
10591                 .put = alc_ch_mode_put,
10592                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
10593         },
10594         { } /* end */
10595 };
10596
10597 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
10598         /* output mixer control */
10599         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
10600         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
10601         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
10602         
10603         /*Capture mixer control */
10604         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
10605         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
10606         {
10607                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10608                 .name = "Capture Source",
10609                 .count = 1,
10610                 .info = alc_mux_enum_info,
10611                 .get = alc_mux_enum_get,
10612                 .put = alc_mux_enum_put,
10613         },
10614
10615         { } /* end */
10616 };
10617
10618 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
10619         /* output mixer control */
10620         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
10621         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
10622         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
10623         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
10624         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
10625
10626         /* Input mixer control */
10627         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
10628            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
10629         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
10630         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
10631         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
10632         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
10633         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
10634         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
10635         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
10636         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
10637
10638         /* Capture mixer control */
10639         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
10640         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
10641         {
10642                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10643                 .name = "Capture Source",
10644                 .count = 1,
10645                 .info = alc_mux_enum_info,
10646                 .get = alc_mux_enum_get,
10647                 .put = alc_mux_enum_put,
10648         },
10649         {
10650                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10651                 .name = "Channel Mode",
10652                 .info = alc_ch_mode_info,
10653                 .get = alc_ch_mode_get,
10654                 .put = alc_ch_mode_put,
10655                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
10656         },
10657         { } /* end */
10658 };
10659
10660 static struct snd_kcontrol_new alc861_asus_mixer[] = {
10661         /* output mixer control */
10662         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
10663         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
10664         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
10665         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
10666         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
10667
10668         /* Input mixer control */
10669         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
10670         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10671         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
10672         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
10673         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
10674         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
10675         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
10676         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
10677         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
10678         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
10679
10680         /* Capture mixer control */
10681         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
10682         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
10683         {
10684                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10685                 .name = "Capture Source",
10686                 .count = 1,
10687                 .info = alc_mux_enum_info,
10688                 .get = alc_mux_enum_get,
10689                 .put = alc_mux_enum_put,
10690         },
10691         {
10692                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10693                 .name = "Channel Mode",
10694                 .info = alc_ch_mode_info,
10695                 .get = alc_ch_mode_get,
10696                 .put = alc_ch_mode_put,
10697                 .private_value = ARRAY_SIZE(alc861_asus_modes),
10698         },
10699         { }
10700 };
10701
10702 /* additional mixer */
10703 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
10704         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
10705         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
10706         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x23, 0x0, HDA_OUTPUT),
10707         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x23, 0x0, HDA_OUTPUT),
10708         { }
10709 };
10710
10711 /*
10712  * generic initialization of ADC, input mixers and output mixers
10713  */
10714 static struct hda_verb alc861_base_init_verbs[] = {
10715         /*
10716          * Unmute ADC0 and set the default input to mic-in
10717          */
10718         /* port-A for surround (rear panel) */
10719         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10720         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
10721         /* port-B for mic-in (rear panel) with vref */
10722         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10723         /* port-C for line-in (rear panel) */
10724         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
10725         /* port-D for Front */
10726         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10727         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
10728         /* port-E for HP out (front panel) */
10729         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
10730         /* route front PCM to HP */
10731         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
10732         /* port-F for mic-in (front panel) with vref */
10733         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10734         /* port-G for CLFE (rear panel) */
10735         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10736         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
10737         /* port-H for side (rear panel) */
10738         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10739         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
10740         /* CD-in */
10741         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
10742         /* route front mic to ADC1*/
10743         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10744         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10745         
10746         /* Unmute DAC0~3 & spdif out*/
10747         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10748         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10749         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10750         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10751         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10752         
10753         /* Unmute Mixer 14 (mic) 1c (Line in)*/
10754         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10755         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10756         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10757         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10758         
10759         /* Unmute Stereo Mixer 15 */
10760         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10761         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10762         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10763         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
10764
10765         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10766         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10767         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10768         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10769         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10770         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10771         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10772         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10773         /* hp used DAC 3 (Front) */
10774         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
10775         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10776
10777         { }
10778 };
10779
10780 static struct hda_verb alc861_threestack_init_verbs[] = {
10781         /*
10782          * Unmute ADC0 and set the default input to mic-in
10783          */
10784         /* port-A for surround (rear panel) */
10785         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
10786         /* port-B for mic-in (rear panel) with vref */
10787         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10788         /* port-C for line-in (rear panel) */
10789         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
10790         /* port-D for Front */
10791         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10792         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
10793         /* port-E for HP out (front panel) */
10794         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
10795         /* route front PCM to HP */
10796         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
10797         /* port-F for mic-in (front panel) with vref */
10798         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10799         /* port-G for CLFE (rear panel) */
10800         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
10801         /* port-H for side (rear panel) */
10802         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
10803         /* CD-in */
10804         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
10805         /* route front mic to ADC1*/
10806         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10807         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10808         /* Unmute DAC0~3 & spdif out*/
10809         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10810         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10811         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10812         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10813         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10814         
10815         /* Unmute Mixer 14 (mic) 1c (Line in)*/
10816         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10817         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10818         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10819         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10820         
10821         /* Unmute Stereo Mixer 15 */
10822         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10823         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10824         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10825         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
10826
10827         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10828         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10829         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10830         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10831         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10832         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10833         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10834         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10835         /* hp used DAC 3 (Front) */
10836         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
10837         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10838         { }
10839 };
10840
10841 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
10842         /*
10843          * Unmute ADC0 and set the default input to mic-in
10844          */
10845         /* port-A for surround (rear panel) */
10846         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
10847         /* port-B for mic-in (rear panel) with vref */
10848         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10849         /* port-C for line-in (rear panel) */
10850         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
10851         /* port-D for Front */
10852         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10853         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
10854         /* port-E for HP out (front panel) */
10855         /* this has to be set to VREF80 */
10856         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10857         /* route front PCM to HP */
10858         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
10859         /* port-F for mic-in (front panel) with vref */
10860         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10861         /* port-G for CLFE (rear panel) */
10862         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
10863         /* port-H for side (rear panel) */
10864         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
10865         /* CD-in */
10866         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
10867         /* route front mic to ADC1*/
10868         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10869         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10870         /* Unmute DAC0~3 & spdif out*/
10871         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10872         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10873         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10874         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10875         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10876         
10877         /* Unmute Mixer 14 (mic) 1c (Line in)*/
10878         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10879         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10880         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10881         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10882         
10883         /* Unmute Stereo Mixer 15 */
10884         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10885         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10886         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10887         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
10888
10889         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10890         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10891         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10892         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10893         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10894         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10895         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10896         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10897         /* hp used DAC 3 (Front) */
10898         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
10899         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10900         { }
10901 };
10902
10903 static struct hda_verb alc861_asus_init_verbs[] = {
10904         /*
10905          * Unmute ADC0 and set the default input to mic-in
10906          */
10907         /* port-A for surround (rear panel)
10908          * according to codec#0 this is the HP jack
10909          */
10910         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
10911         /* route front PCM to HP */
10912         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
10913         /* port-B for mic-in (rear panel) with vref */
10914         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10915         /* port-C for line-in (rear panel) */
10916         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
10917         /* port-D for Front */
10918         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10919         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
10920         /* port-E for HP out (front panel) */
10921         /* this has to be set to VREF80 */
10922         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10923         /* route front PCM to HP */
10924         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
10925         /* port-F for mic-in (front panel) with vref */
10926         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10927         /* port-G for CLFE (rear panel) */
10928         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10929         /* port-H for side (rear panel) */
10930         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10931         /* CD-in */
10932         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
10933         /* route front mic to ADC1*/
10934         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10935         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10936         /* Unmute DAC0~3 & spdif out*/
10937         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10938         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10939         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10940         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10941         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10942         /* Unmute Mixer 14 (mic) 1c (Line in)*/
10943         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10944         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10945         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10946         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10947         
10948         /* Unmute Stereo Mixer 15 */
10949         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10950         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10951         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10952         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
10953
10954         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10955         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10956         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10957         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10958         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10959         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10960         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10961         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10962         /* hp used DAC 3 (Front) */
10963         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
10964         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10965         { }
10966 };
10967
10968 /* additional init verbs for ASUS laptops */
10969 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
10970         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
10971         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
10972         { }
10973 };
10974
10975 /*
10976  * generic initialization of ADC, input mixers and output mixers
10977  */
10978 static struct hda_verb alc861_auto_init_verbs[] = {
10979         /*
10980          * Unmute ADC0 and set the default input to mic-in
10981          */
10982         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
10983         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10984         
10985         /* Unmute DAC0~3 & spdif out*/
10986         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10987         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10988         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10989         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10990         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10991         
10992         /* Unmute Mixer 14 (mic) 1c (Line in)*/
10993         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10994         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10995         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10996         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10997         
10998         /* Unmute Stereo Mixer 15 */
10999         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11000         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11001         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11002         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
11003
11004         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11005         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11006         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11007         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11008         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11009         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11010         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11011         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11012
11013         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11014         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11015         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11016         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
11017         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11018         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11019         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11020         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
11021
11022         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
11023
11024         { }
11025 };
11026
11027 static struct hda_verb alc861_toshiba_init_verbs[] = {
11028         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11029
11030         { }
11031 };
11032
11033 /* toggle speaker-output according to the hp-jack state */
11034 static void alc861_toshiba_automute(struct hda_codec *codec)
11035 {
11036         unsigned int present;
11037
11038         present = snd_hda_codec_read(codec, 0x0f, 0,
11039                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11040         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
11041                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
11042         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
11043                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
11044 }
11045
11046 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
11047                                        unsigned int res)
11048 {
11049         if ((res >> 26) == ALC880_HP_EVENT)
11050                 alc861_toshiba_automute(codec);
11051 }
11052
11053 /* pcm configuration: identiacal with ALC880 */
11054 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
11055 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
11056 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
11057 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
11058
11059
11060 #define ALC861_DIGOUT_NID       0x07
11061
11062 static struct hda_channel_mode alc861_8ch_modes[1] = {
11063         { 8, NULL }
11064 };
11065
11066 static hda_nid_t alc861_dac_nids[4] = {
11067         /* front, surround, clfe, side */
11068         0x03, 0x06, 0x05, 0x04
11069 };
11070
11071 static hda_nid_t alc660_dac_nids[3] = {
11072         /* front, clfe, surround */
11073         0x03, 0x05, 0x06
11074 };
11075
11076 static hda_nid_t alc861_adc_nids[1] = {
11077         /* ADC0-2 */
11078         0x08,
11079 };
11080
11081 static struct hda_input_mux alc861_capture_source = {
11082         .num_items = 5,
11083         .items = {
11084                 { "Mic", 0x0 },
11085                 { "Front Mic", 0x3 },
11086                 { "Line", 0x1 },
11087                 { "CD", 0x4 },
11088                 { "Mixer", 0x5 },
11089         },
11090 };
11091
11092 /* fill in the dac_nids table from the parsed pin configuration */
11093 static int alc861_auto_fill_dac_nids(struct alc_spec *spec,
11094                                      const struct auto_pin_cfg *cfg)
11095 {
11096         int i;
11097         hda_nid_t nid;
11098
11099         spec->multiout.dac_nids = spec->private_dac_nids;
11100         for (i = 0; i < cfg->line_outs; i++) {
11101                 nid = cfg->line_out_pins[i];
11102                 if (nid) {
11103                         if (i >= ARRAY_SIZE(alc861_dac_nids))
11104                                 continue;
11105                         spec->multiout.dac_nids[i] = alc861_dac_nids[i];
11106                 }
11107         }
11108         spec->multiout.num_dacs = cfg->line_outs;
11109         return 0;
11110 }
11111
11112 /* add playback controls from the parsed DAC table */
11113 static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
11114                                              const struct auto_pin_cfg *cfg)
11115 {
11116         char name[32];
11117         static const char *chname[4] = {
11118                 "Front", "Surround", NULL /*CLFE*/, "Side"
11119         };
11120         hda_nid_t nid;
11121         int i, idx, err;
11122
11123         for (i = 0; i < cfg->line_outs; i++) {
11124                 nid = spec->multiout.dac_nids[i];
11125                 if (!nid)
11126                         continue;
11127                 if (nid == 0x05) {
11128                         /* Center/LFE */
11129                         err = add_control(spec, ALC_CTL_BIND_MUTE,
11130                                           "Center Playback Switch",
11131                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
11132                                                               HDA_OUTPUT));
11133                         if (err < 0)
11134                                 return err;
11135                         err = add_control(spec, ALC_CTL_BIND_MUTE,
11136                                           "LFE Playback Switch",
11137                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
11138                                                               HDA_OUTPUT));
11139                         if (err < 0)
11140                                 return err;
11141                 } else {
11142                         for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1;
11143                              idx++)
11144                                 if (nid == alc861_dac_nids[idx])
11145                                         break;
11146                         sprintf(name, "%s Playback Switch", chname[idx]);
11147                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
11148                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
11149                                                               HDA_OUTPUT));
11150                         if (err < 0)
11151                                 return err;
11152                 }
11153         }
11154         return 0;
11155 }
11156
11157 static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
11158 {
11159         int err;
11160         hda_nid_t nid;
11161
11162         if (!pin)
11163                 return 0;
11164
11165         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
11166                 nid = 0x03;
11167                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11168                                   "Headphone Playback Switch",
11169                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
11170                 if (err < 0)
11171                         return err;
11172                 spec->multiout.hp_nid = nid;
11173         }
11174         return 0;
11175 }
11176
11177 /* create playback/capture controls for input pins */
11178 static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec,
11179                                                 const struct auto_pin_cfg *cfg)
11180 {
11181         struct hda_input_mux *imux = &spec->private_imux;
11182         int i, err, idx, idx1;
11183
11184         for (i = 0; i < AUTO_PIN_LAST; i++) {
11185                 switch (cfg->input_pins[i]) {
11186                 case 0x0c:
11187                         idx1 = 1;
11188                         idx = 2;        /* Line In */
11189                         break;
11190                 case 0x0f:
11191                         idx1 = 2;
11192                         idx = 2;        /* Line In */
11193                         break;
11194                 case 0x0d:
11195                         idx1 = 0;
11196                         idx = 1;        /* Mic In */
11197                         break;
11198                 case 0x10:
11199                         idx1 = 3;
11200                         idx = 1;        /* Mic In */
11201                         break;
11202                 case 0x11:
11203                         idx1 = 4;
11204                         idx = 0;        /* CD */
11205                         break;
11206                 default:
11207                         continue;
11208                 }
11209
11210                 err = new_analog_input(spec, cfg->input_pins[i],
11211                                        auto_pin_cfg_labels[i], idx, 0x15);
11212                 if (err < 0)
11213                         return err;
11214
11215                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
11216                 imux->items[imux->num_items].index = idx1;
11217                 imux->num_items++;
11218         }
11219         return 0;
11220 }
11221
11222 static struct snd_kcontrol_new alc861_capture_mixer[] = {
11223         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11224         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11225
11226         {
11227                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11228                 /* The multiple "Capture Source" controls confuse alsamixer
11229                  * So call somewhat different..
11230                  */
11231                 /* .name = "Capture Source", */
11232                 .name = "Input Source",
11233                 .count = 1,
11234                 .info = alc_mux_enum_info,
11235                 .get = alc_mux_enum_get,
11236                 .put = alc_mux_enum_put,
11237         },
11238         { } /* end */
11239 };
11240
11241 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
11242                                               hda_nid_t nid,
11243                                               int pin_type, int dac_idx)
11244 {
11245         /* set as output */
11246
11247         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
11248                             pin_type);
11249         snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE,
11250                             AMP_OUT_UNMUTE);
11251
11252 }
11253
11254 static void alc861_auto_init_multi_out(struct hda_codec *codec)
11255 {
11256         struct alc_spec *spec = codec->spec;
11257         int i;
11258
11259         alc_subsystem_id(codec, 0x0e, 0x0f, 0x0b);
11260         for (i = 0; i < spec->autocfg.line_outs; i++) {
11261                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
11262                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
11263                 if (nid)
11264                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
11265                                                           spec->multiout.dac_nids[i]);
11266         }
11267 }
11268
11269 static void alc861_auto_init_hp_out(struct hda_codec *codec)
11270 {
11271         struct alc_spec *spec = codec->spec;
11272         hda_nid_t pin;
11273
11274         pin = spec->autocfg.hp_pins[0];
11275         if (pin) /* connect to front */
11276                 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
11277                                                   spec->multiout.dac_nids[0]);
11278 }
11279
11280 static void alc861_auto_init_analog_input(struct hda_codec *codec)
11281 {
11282         struct alc_spec *spec = codec->spec;
11283         int i;
11284
11285         for (i = 0; i < AUTO_PIN_LAST; i++) {
11286                 hda_nid_t nid = spec->autocfg.input_pins[i];
11287                 if (nid >= 0x0c && nid <= 0x11) {
11288                         snd_hda_codec_write(codec, nid, 0,
11289                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
11290                                             i <= AUTO_PIN_FRONT_MIC ?
11291                                             PIN_VREF80 : PIN_IN);
11292                 }
11293         }
11294 }
11295
11296 /* parse the BIOS configuration and set up the alc_spec */
11297 /* return 1 if successful, 0 if the proper config is not found,
11298  * or a negative error code
11299  */
11300 static int alc861_parse_auto_config(struct hda_codec *codec)
11301 {
11302         struct alc_spec *spec = codec->spec;
11303         int err;
11304         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
11305
11306         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11307                                            alc861_ignore);
11308         if (err < 0)
11309                 return err;
11310         if (!spec->autocfg.line_outs)
11311                 return 0; /* can't find valid BIOS pin config */
11312
11313         err = alc861_auto_fill_dac_nids(spec, &spec->autocfg);
11314         if (err < 0)
11315                 return err;
11316         err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg);
11317         if (err < 0)
11318                 return err;
11319         err = alc861_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
11320         if (err < 0)
11321                 return err;
11322         err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg);
11323         if (err < 0)
11324                 return err;
11325
11326         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
11327
11328         if (spec->autocfg.dig_out_pin)
11329                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
11330
11331         if (spec->kctl_alloc)
11332                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
11333
11334         spec->init_verbs[spec->num_init_verbs++] = alc861_auto_init_verbs;
11335
11336         spec->num_mux_defs = 1;
11337         spec->input_mux = &spec->private_imux;
11338
11339         spec->adc_nids = alc861_adc_nids;
11340         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
11341         spec->mixers[spec->num_mixers] = alc861_capture_mixer;
11342         spec->num_mixers++;
11343
11344         return 1;
11345 }
11346
11347 /* additional initialization for auto-configuration model */
11348 static void alc861_auto_init(struct hda_codec *codec)
11349 {
11350         alc861_auto_init_multi_out(codec);
11351         alc861_auto_init_hp_out(codec);
11352         alc861_auto_init_analog_input(codec);
11353 }
11354
11355 #ifdef CONFIG_SND_HDA_POWER_SAVE
11356 static struct hda_amp_list alc861_loopbacks[] = {
11357         { 0x15, HDA_INPUT, 0 },
11358         { 0x15, HDA_INPUT, 1 },
11359         { 0x15, HDA_INPUT, 2 },
11360         { 0x15, HDA_INPUT, 3 },
11361         { } /* end */
11362 };
11363 #endif
11364
11365
11366 /*
11367  * configuration and preset
11368  */
11369 static const char *alc861_models[ALC861_MODEL_LAST] = {
11370         [ALC861_3ST]            = "3stack",
11371         [ALC660_3ST]            = "3stack-660",
11372         [ALC861_3ST_DIG]        = "3stack-dig",
11373         [ALC861_6ST_DIG]        = "6stack-dig",
11374         [ALC861_UNIWILL_M31]    = "uniwill-m31",
11375         [ALC861_TOSHIBA]        = "toshiba",
11376         [ALC861_ASUS]           = "asus",
11377         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
11378         [ALC861_AUTO]           = "auto",
11379 };
11380
11381 static struct snd_pci_quirk alc861_cfg_tbl[] = {
11382         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
11383         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
11384         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
11385         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
11386         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
11387         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
11388         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
11389         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
11390          *        Any other models that need this preset?
11391          */
11392         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
11393         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
11394         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
11395         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
11396         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
11397         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
11398         /* FIXME: the below seems conflict */
11399         /* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
11400         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
11401         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
11402         {}
11403 };
11404
11405 static struct alc_config_preset alc861_presets[] = {
11406         [ALC861_3ST] = {
11407                 .mixers = { alc861_3ST_mixer },
11408                 .init_verbs = { alc861_threestack_init_verbs },
11409                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
11410                 .dac_nids = alc861_dac_nids,
11411                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
11412                 .channel_mode = alc861_threestack_modes,
11413                 .need_dac_fix = 1,
11414                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
11415                 .adc_nids = alc861_adc_nids,
11416                 .input_mux = &alc861_capture_source,
11417         },
11418         [ALC861_3ST_DIG] = {
11419                 .mixers = { alc861_base_mixer },
11420                 .init_verbs = { alc861_threestack_init_verbs },
11421                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
11422                 .dac_nids = alc861_dac_nids,
11423                 .dig_out_nid = ALC861_DIGOUT_NID,
11424                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
11425                 .channel_mode = alc861_threestack_modes,
11426                 .need_dac_fix = 1,
11427                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
11428                 .adc_nids = alc861_adc_nids,
11429                 .input_mux = &alc861_capture_source,
11430         },
11431         [ALC861_6ST_DIG] = {
11432                 .mixers = { alc861_base_mixer },
11433                 .init_verbs = { alc861_base_init_verbs },
11434                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
11435                 .dac_nids = alc861_dac_nids,
11436                 .dig_out_nid = ALC861_DIGOUT_NID,
11437                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
11438                 .channel_mode = alc861_8ch_modes,
11439                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
11440                 .adc_nids = alc861_adc_nids,
11441                 .input_mux = &alc861_capture_source,
11442         },
11443         [ALC660_3ST] = {
11444                 .mixers = { alc861_3ST_mixer },
11445                 .init_verbs = { alc861_threestack_init_verbs },
11446                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
11447                 .dac_nids = alc660_dac_nids,
11448                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
11449                 .channel_mode = alc861_threestack_modes,
11450                 .need_dac_fix = 1,
11451                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
11452                 .adc_nids = alc861_adc_nids,
11453                 .input_mux = &alc861_capture_source,
11454         },
11455         [ALC861_UNIWILL_M31] = {
11456                 .mixers = { alc861_uniwill_m31_mixer },
11457                 .init_verbs = { alc861_uniwill_m31_init_verbs },
11458                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
11459                 .dac_nids = alc861_dac_nids,
11460                 .dig_out_nid = ALC861_DIGOUT_NID,
11461                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
11462                 .channel_mode = alc861_uniwill_m31_modes,
11463                 .need_dac_fix = 1,
11464                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
11465                 .adc_nids = alc861_adc_nids,
11466                 .input_mux = &alc861_capture_source,
11467         },
11468         [ALC861_TOSHIBA] = {
11469                 .mixers = { alc861_toshiba_mixer },
11470                 .init_verbs = { alc861_base_init_verbs,
11471                                 alc861_toshiba_init_verbs },
11472                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
11473                 .dac_nids = alc861_dac_nids,
11474                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
11475                 .channel_mode = alc883_3ST_2ch_modes,
11476                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
11477                 .adc_nids = alc861_adc_nids,
11478                 .input_mux = &alc861_capture_source,
11479                 .unsol_event = alc861_toshiba_unsol_event,
11480                 .init_hook = alc861_toshiba_automute,
11481         },
11482         [ALC861_ASUS] = {
11483                 .mixers = { alc861_asus_mixer },
11484                 .init_verbs = { alc861_asus_init_verbs },
11485                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
11486                 .dac_nids = alc861_dac_nids,
11487                 .dig_out_nid = ALC861_DIGOUT_NID,
11488                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
11489                 .channel_mode = alc861_asus_modes,
11490                 .need_dac_fix = 1,
11491                 .hp_nid = 0x06,
11492                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
11493                 .adc_nids = alc861_adc_nids,
11494                 .input_mux = &alc861_capture_source,
11495         },
11496         [ALC861_ASUS_LAPTOP] = {
11497                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
11498                 .init_verbs = { alc861_asus_init_verbs,
11499                                 alc861_asus_laptop_init_verbs },
11500                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
11501                 .dac_nids = alc861_dac_nids,
11502                 .dig_out_nid = ALC861_DIGOUT_NID,
11503                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
11504                 .channel_mode = alc883_3ST_2ch_modes,
11505                 .need_dac_fix = 1,
11506                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
11507                 .adc_nids = alc861_adc_nids,
11508                 .input_mux = &alc861_capture_source,
11509         },
11510 };
11511
11512
11513 static int patch_alc861(struct hda_codec *codec)
11514 {
11515         struct alc_spec *spec;
11516         int board_config;
11517         int err;
11518
11519         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
11520         if (spec == NULL)
11521                 return -ENOMEM;
11522
11523         codec->spec = spec;
11524
11525         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
11526                                                   alc861_models,
11527                                                   alc861_cfg_tbl);
11528
11529         if (board_config < 0) {
11530                 printk(KERN_INFO "hda_codec: Unknown model for ALC861, "
11531                        "trying auto-probe from BIOS...\n");
11532                 board_config = ALC861_AUTO;
11533         }
11534
11535         if (board_config == ALC861_AUTO) {
11536                 /* automatic parse from the BIOS config */
11537                 err = alc861_parse_auto_config(codec);
11538                 if (err < 0) {
11539                         alc_free(codec);
11540                         return err;
11541                 } else if (!err) {
11542                         printk(KERN_INFO
11543                                "hda_codec: Cannot set up configuration "
11544                                "from BIOS.  Using base mode...\n");
11545                    board_config = ALC861_3ST_DIG;
11546                 }
11547         }
11548
11549         if (board_config != ALC861_AUTO)
11550                 setup_preset(spec, &alc861_presets[board_config]);
11551
11552         spec->stream_name_analog = "ALC861 Analog";
11553         spec->stream_analog_playback = &alc861_pcm_analog_playback;
11554         spec->stream_analog_capture = &alc861_pcm_analog_capture;
11555
11556         spec->stream_name_digital = "ALC861 Digital";
11557         spec->stream_digital_playback = &alc861_pcm_digital_playback;
11558         spec->stream_digital_capture = &alc861_pcm_digital_capture;
11559
11560         spec->vmaster_nid = 0x03;
11561
11562         codec->patch_ops = alc_patch_ops;
11563         if (board_config == ALC861_AUTO)
11564                 spec->init_hook = alc861_auto_init;
11565 #ifdef CONFIG_SND_HDA_POWER_SAVE
11566         if (!spec->loopback.amplist)
11567                 spec->loopback.amplist = alc861_loopbacks;
11568 #endif
11569                 
11570         return 0;
11571 }
11572
11573 /*
11574  * ALC861-VD support
11575  *
11576  * Based on ALC882
11577  *
11578  * In addition, an independent DAC
11579  */
11580 #define ALC861VD_DIGOUT_NID     0x06
11581
11582 static hda_nid_t alc861vd_dac_nids[4] = {
11583         /* front, surr, clfe, side surr */
11584         0x02, 0x03, 0x04, 0x05
11585 };
11586
11587 /* dac_nids for ALC660vd are in a different order - according to
11588  * Realtek's driver.
11589  * This should probably tesult in a different mixer for 6stack models
11590  * of ALC660vd codecs, but for now there is only 3stack mixer
11591  * - and it is the same as in 861vd.
11592  * adc_nids in ALC660vd are (is) the same as in 861vd
11593  */
11594 static hda_nid_t alc660vd_dac_nids[3] = {
11595         /* front, rear, clfe, rear_surr */
11596         0x02, 0x04, 0x03
11597 };
11598
11599 static hda_nid_t alc861vd_adc_nids[1] = {
11600         /* ADC0 */
11601         0x09,
11602 };
11603
11604 /* input MUX */
11605 /* FIXME: should be a matrix-type input source selection */
11606 static struct hda_input_mux alc861vd_capture_source = {
11607         .num_items = 4,
11608         .items = {
11609                 { "Mic", 0x0 },
11610                 { "Front Mic", 0x1 },
11611                 { "Line", 0x2 },
11612                 { "CD", 0x4 },
11613         },
11614 };
11615
11616 static struct hda_input_mux alc861vd_dallas_capture_source = {
11617         .num_items = 3,
11618         .items = {
11619                 { "Front Mic", 0x0 },
11620                 { "ATAPI Mic", 0x1 },
11621                 { "Line In", 0x5 },
11622         },
11623 };
11624
11625 static struct hda_input_mux alc861vd_hp_capture_source = {
11626         .num_items = 2,
11627         .items = {
11628                 { "Front Mic", 0x0 },
11629                 { "ATAPI Mic", 0x1 },
11630         },
11631 };
11632
11633 #define alc861vd_mux_enum_info alc_mux_enum_info
11634 #define alc861vd_mux_enum_get alc_mux_enum_get
11635
11636 static int alc861vd_mux_enum_put(struct snd_kcontrol *kcontrol,
11637                                 struct snd_ctl_elem_value *ucontrol)
11638 {
11639         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
11640         struct alc_spec *spec = codec->spec;
11641         const struct hda_input_mux *imux = spec->input_mux;
11642         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
11643         static hda_nid_t capture_mixers[1] = { 0x22 };
11644         hda_nid_t nid = capture_mixers[adc_idx];
11645         unsigned int *cur_val = &spec->cur_mux[adc_idx];
11646         unsigned int i, idx;
11647
11648         idx = ucontrol->value.enumerated.item[0];
11649         if (idx >= imux->num_items)
11650                 idx = imux->num_items - 1;
11651         if (*cur_val == idx)
11652                 return 0;
11653         for (i = 0; i < imux->num_items; i++) {
11654                 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
11655                 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
11656                                          imux->items[i].index,
11657                                          HDA_AMP_MUTE, v);
11658         }
11659         *cur_val = idx;
11660         return 1;
11661 }
11662
11663 /*
11664  * 2ch mode
11665  */
11666 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
11667         { 2, NULL }
11668 };
11669
11670 /*
11671  * 6ch mode
11672  */
11673 static struct hda_verb alc861vd_6stack_ch6_init[] = {
11674         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11675         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11676         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11677         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11678         { } /* end */
11679 };
11680
11681 /*
11682  * 8ch mode
11683  */
11684 static struct hda_verb alc861vd_6stack_ch8_init[] = {
11685         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11686         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11687         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11688         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11689         { } /* end */
11690 };
11691
11692 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
11693         { 6, alc861vd_6stack_ch6_init },
11694         { 8, alc861vd_6stack_ch8_init },
11695 };
11696
11697 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
11698         {
11699                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11700                 .name = "Channel Mode",
11701                 .info = alc_ch_mode_info,
11702                 .get = alc_ch_mode_get,
11703                 .put = alc_ch_mode_put,
11704         },
11705         { } /* end */
11706 };
11707
11708 static struct snd_kcontrol_new alc861vd_capture_mixer[] = {
11709         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
11710         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
11711
11712         {
11713                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11714                 /* The multiple "Capture Source" controls confuse alsamixer
11715                  * So call somewhat different..
11716                  */
11717                 /* .name = "Capture Source", */
11718                 .name = "Input Source",
11719                 .count = 1,
11720                 .info = alc861vd_mux_enum_info,
11721                 .get = alc861vd_mux_enum_get,
11722                 .put = alc861vd_mux_enum_put,
11723         },
11724         { } /* end */
11725 };
11726
11727 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
11728  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
11729  */
11730 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
11731         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11732         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
11733
11734         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11735         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
11736
11737         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
11738                                 HDA_OUTPUT),
11739         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
11740                                 HDA_OUTPUT),
11741         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
11742         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
11743
11744         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
11745         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
11746
11747         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
11748
11749         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11750         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11751         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11752
11753         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11754         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
11755         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
11756
11757         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
11758         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11759
11760         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
11761         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
11762
11763         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
11764         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
11765
11766         { } /* end */
11767 };
11768
11769 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
11770         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11771         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
11772
11773         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
11774
11775         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11776         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11777         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11778
11779         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11780         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
11781         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
11782
11783         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
11784         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11785
11786         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
11787         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
11788
11789         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
11790         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
11791
11792         { } /* end */
11793 };
11794
11795 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
11796         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11797         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
11798         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11799
11800         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
11801
11802         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11803         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11804         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11805
11806         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11807         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
11808         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
11809
11810         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
11811         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
11812
11813         { } /* end */
11814 };
11815
11816 /* Pin assignment: Front=0x14, HP = 0x15,
11817  *                 Front Mic=0x18, ATAPI Mic = 0x19, Line In = 0x1d
11818  */
11819 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
11820         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11821         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
11822         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11823         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
11824         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11825         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11826         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
11827         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
11828         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x05, HDA_INPUT),
11829         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x05, HDA_INPUT),
11830         { } /* end */
11831 };
11832
11833 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
11834  *                 Front Mic=0x18, ATAPI Mic = 0x19,
11835  */
11836 static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
11837         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11838         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
11839         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11840         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
11841         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11842         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11843         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
11844         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
11845         
11846         { } /* end */
11847 };
11848
11849 /*
11850  * generic initialization of ADC, input mixers and output mixers
11851  */
11852 static struct hda_verb alc861vd_volume_init_verbs[] = {
11853         /*
11854          * Unmute ADC0 and set the default input to mic-in
11855          */
11856         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
11857         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11858
11859         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
11860          * the analog-loopback mixer widget
11861          */
11862         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11863         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11864         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11865         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11866         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11867         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11868
11869         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
11870         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11871         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11872         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11873         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
11874
11875         /*
11876          * Set up output mixers (0x02 - 0x05)
11877          */
11878         /* set vol=0 to output mixers */
11879         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11880         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11881         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11882         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11883
11884         /* set up input amps for analog loopback */
11885         /* Amp Indices: DAC = 0, mixer = 1 */
11886         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11887         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11888         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11889         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11890         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11891         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11892         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11893         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11894
11895         { }
11896 };
11897
11898 /*
11899  * 3-stack pin configuration:
11900  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
11901  */
11902 static struct hda_verb alc861vd_3stack_init_verbs[] = {
11903         /*
11904          * Set pin mode and muting
11905          */
11906         /* set front pin widgets 0x14 for output */
11907         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11908         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11909         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
11910
11911         /* Mic (rear) pin: input vref at 80% */
11912         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11913         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11914         /* Front Mic pin: input vref at 80% */
11915         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11916         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11917         /* Line In pin: input */
11918         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11919         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11920         /* Line-2 In: Headphone output (output 0 - 0x0c) */
11921         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11922         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11923         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
11924         /* CD pin widget for input */
11925         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11926
11927         { }
11928 };
11929
11930 /*
11931  * 6-stack pin configuration:
11932  */
11933 static struct hda_verb alc861vd_6stack_init_verbs[] = {
11934         /*
11935          * Set pin mode and muting
11936          */
11937         /* set front pin widgets 0x14 for output */
11938         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11939         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11940         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
11941
11942         /* Rear Pin: output 1 (0x0d) */
11943         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11944         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11945         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
11946         /* CLFE Pin: output 2 (0x0e) */
11947         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11948         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11949         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
11950         /* Side Pin: output 3 (0x0f) */
11951         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11952         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11953         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
11954
11955         /* Mic (rear) pin: input vref at 80% */
11956         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11957         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11958         /* Front Mic pin: input vref at 80% */
11959         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11960         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11961         /* Line In pin: input */
11962         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11963         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11964         /* Line-2 In: Headphone output (output 0 - 0x0c) */
11965         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11966         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11967         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
11968         /* CD pin widget for input */
11969         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11970
11971         { }
11972 };
11973
11974 static struct hda_verb alc861vd_eapd_verbs[] = {
11975         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
11976         { }
11977 };
11978
11979 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
11980         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11981         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11982         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
11983         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11984         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT}, 
11985         {}
11986 };
11987
11988 /* toggle speaker-output according to the hp-jack state */
11989 static void alc861vd_lenovo_hp_automute(struct hda_codec *codec)
11990 {
11991         unsigned int present;
11992         unsigned char bits;
11993
11994         present = snd_hda_codec_read(codec, 0x1b, 0,
11995                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11996         bits = present ? HDA_AMP_MUTE : 0;
11997         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
11998                                  HDA_AMP_MUTE, bits);
11999 }
12000
12001 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
12002 {
12003         unsigned int present;
12004         unsigned char bits;
12005
12006         present = snd_hda_codec_read(codec, 0x18, 0,
12007                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12008         bits = present ? HDA_AMP_MUTE : 0;
12009         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
12010                                  HDA_AMP_MUTE, bits);
12011 }
12012
12013 static void alc861vd_lenovo_automute(struct hda_codec *codec)
12014 {
12015         alc861vd_lenovo_hp_automute(codec);
12016         alc861vd_lenovo_mic_automute(codec);
12017 }
12018
12019 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
12020                                         unsigned int res)
12021 {
12022         switch (res >> 26) {
12023         case ALC880_HP_EVENT:
12024                 alc861vd_lenovo_hp_automute(codec);
12025                 break;
12026         case ALC880_MIC_EVENT:
12027                 alc861vd_lenovo_mic_automute(codec);
12028                 break;
12029         }
12030 }
12031
12032 static struct hda_verb alc861vd_dallas_verbs[] = {
12033         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12034         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12035         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12036         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12037
12038         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12039         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12040         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12041         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12042         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12043         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12044         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12045         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12046         
12047         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12048         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12049         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12050         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12051         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12052         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12053         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12054         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12055
12056         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
12057         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12058         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
12059         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12060         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12061         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12062         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12063         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12064
12065         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12066         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12067         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12068         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
12069
12070         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12071         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},  
12072         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12073
12074         { } /* end */
12075 };
12076
12077 /* toggle speaker-output according to the hp-jack state */
12078 static void alc861vd_dallas_automute(struct hda_codec *codec)
12079 {
12080         unsigned int present;
12081
12082         present = snd_hda_codec_read(codec, 0x15, 0,
12083                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12084         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
12085                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
12086 }
12087
12088 static void alc861vd_dallas_unsol_event(struct hda_codec *codec, unsigned int res)
12089 {
12090         if ((res >> 26) == ALC880_HP_EVENT)
12091                 alc861vd_dallas_automute(codec);
12092 }
12093
12094 #ifdef CONFIG_SND_HDA_POWER_SAVE
12095 #define alc861vd_loopbacks      alc880_loopbacks
12096 #endif
12097
12098 /* pcm configuration: identiacal with ALC880 */
12099 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
12100 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
12101 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
12102 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
12103
12104 /*
12105  * configuration and preset
12106  */
12107 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
12108         [ALC660VD_3ST]          = "3stack-660",
12109         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
12110         [ALC861VD_3ST]          = "3stack",
12111         [ALC861VD_3ST_DIG]      = "3stack-digout",
12112         [ALC861VD_6ST_DIG]      = "6stack-digout",
12113         [ALC861VD_LENOVO]       = "lenovo",
12114         [ALC861VD_DALLAS]       = "dallas",
12115         [ALC861VD_HP]           = "hp",
12116         [ALC861VD_AUTO]         = "auto",
12117 };
12118
12119 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
12120         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
12121         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
12122         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
12123         SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),
12124         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
12125         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
12126         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
12127         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
12128         SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS),
12129         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
12130         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
12131         SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo", ALC861VD_LENOVO),
12132         SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo 3000 C200", ALC861VD_LENOVO),
12133         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
12134         {}
12135 };
12136
12137 static struct alc_config_preset alc861vd_presets[] = {
12138         [ALC660VD_3ST] = {
12139                 .mixers = { alc861vd_3st_mixer },
12140                 .init_verbs = { alc861vd_volume_init_verbs,
12141                                  alc861vd_3stack_init_verbs },
12142                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
12143                 .dac_nids = alc660vd_dac_nids,
12144                 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
12145                 .adc_nids = alc861vd_adc_nids,
12146                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12147                 .channel_mode = alc861vd_3stack_2ch_modes,
12148                 .input_mux = &alc861vd_capture_source,
12149         },
12150         [ALC660VD_3ST_DIG] = {
12151                 .mixers = { alc861vd_3st_mixer },
12152                 .init_verbs = { alc861vd_volume_init_verbs,
12153                                  alc861vd_3stack_init_verbs },
12154                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
12155                 .dac_nids = alc660vd_dac_nids,
12156                 .dig_out_nid = ALC861VD_DIGOUT_NID,
12157                 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
12158                 .adc_nids = alc861vd_adc_nids,
12159                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12160                 .channel_mode = alc861vd_3stack_2ch_modes,
12161                 .input_mux = &alc861vd_capture_source,
12162         },
12163         [ALC861VD_3ST] = {
12164                 .mixers = { alc861vd_3st_mixer },
12165                 .init_verbs = { alc861vd_volume_init_verbs,
12166                                  alc861vd_3stack_init_verbs },
12167                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
12168                 .dac_nids = alc861vd_dac_nids,
12169                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12170                 .channel_mode = alc861vd_3stack_2ch_modes,
12171                 .input_mux = &alc861vd_capture_source,
12172         },
12173         [ALC861VD_3ST_DIG] = {
12174                 .mixers = { alc861vd_3st_mixer },
12175                 .init_verbs = { alc861vd_volume_init_verbs,
12176                                  alc861vd_3stack_init_verbs },
12177                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
12178                 .dac_nids = alc861vd_dac_nids,
12179                 .dig_out_nid = ALC861VD_DIGOUT_NID,
12180                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12181                 .channel_mode = alc861vd_3stack_2ch_modes,
12182                 .input_mux = &alc861vd_capture_source,
12183         },
12184         [ALC861VD_6ST_DIG] = {
12185                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
12186                 .init_verbs = { alc861vd_volume_init_verbs,
12187                                 alc861vd_6stack_init_verbs },
12188                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
12189                 .dac_nids = alc861vd_dac_nids,
12190                 .dig_out_nid = ALC861VD_DIGOUT_NID,
12191                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
12192                 .channel_mode = alc861vd_6stack_modes,
12193                 .input_mux = &alc861vd_capture_source,
12194         },
12195         [ALC861VD_LENOVO] = {
12196                 .mixers = { alc861vd_lenovo_mixer },
12197                 .init_verbs = { alc861vd_volume_init_verbs,
12198                                 alc861vd_3stack_init_verbs,
12199                                 alc861vd_eapd_verbs,
12200                                 alc861vd_lenovo_unsol_verbs },
12201                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
12202                 .dac_nids = alc660vd_dac_nids,
12203                 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
12204                 .adc_nids = alc861vd_adc_nids,
12205                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12206                 .channel_mode = alc861vd_3stack_2ch_modes,
12207                 .input_mux = &alc861vd_capture_source,
12208                 .unsol_event = alc861vd_lenovo_unsol_event,
12209                 .init_hook = alc861vd_lenovo_automute,
12210         },
12211         [ALC861VD_DALLAS] = {
12212                 .mixers = { alc861vd_dallas_mixer },
12213                 .init_verbs = { alc861vd_dallas_verbs },
12214                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
12215                 .dac_nids = alc861vd_dac_nids,
12216                 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
12217                 .adc_nids = alc861vd_adc_nids,
12218                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12219                 .channel_mode = alc861vd_3stack_2ch_modes,
12220                 .input_mux = &alc861vd_dallas_capture_source,
12221                 .unsol_event = alc861vd_dallas_unsol_event,
12222                 .init_hook = alc861vd_dallas_automute,
12223         },
12224         [ALC861VD_HP] = {
12225                 .mixers = { alc861vd_hp_mixer },
12226                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
12227                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
12228                 .dac_nids = alc861vd_dac_nids,
12229                 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
12230                 .dig_out_nid = ALC861VD_DIGOUT_NID,
12231                 .adc_nids = alc861vd_adc_nids,
12232                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12233                 .channel_mode = alc861vd_3stack_2ch_modes,
12234                 .input_mux = &alc861vd_hp_capture_source,
12235                 .unsol_event = alc861vd_dallas_unsol_event,
12236                 .init_hook = alc861vd_dallas_automute,
12237         },              
12238 };
12239
12240 /*
12241  * BIOS auto configuration
12242  */
12243 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
12244                                 hda_nid_t nid, int pin_type, int dac_idx)
12245 {
12246         /* set as output */
12247         snd_hda_codec_write(codec, nid, 0,
12248                                 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
12249         snd_hda_codec_write(codec, nid, 0,
12250                                 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
12251 }
12252
12253 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
12254 {
12255         struct alc_spec *spec = codec->spec;
12256         int i;
12257
12258         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
12259         for (i = 0; i <= HDA_SIDE; i++) {
12260                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
12261                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
12262                 if (nid)
12263                         alc861vd_auto_set_output_and_unmute(codec, nid,
12264                                                             pin_type, i);
12265         }
12266 }
12267
12268
12269 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
12270 {
12271         struct alc_spec *spec = codec->spec;
12272         hda_nid_t pin;
12273
12274         pin = spec->autocfg.hp_pins[0];
12275         if (pin) /* connect to front and  use dac 0 */
12276                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
12277 }
12278
12279 #define alc861vd_is_input_pin(nid)      alc880_is_input_pin(nid)
12280 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
12281
12282 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
12283 {
12284         struct alc_spec *spec = codec->spec;
12285         int i;
12286
12287         for (i = 0; i < AUTO_PIN_LAST; i++) {
12288                 hda_nid_t nid = spec->autocfg.input_pins[i];
12289                 if (alc861vd_is_input_pin(nid)) {
12290                         snd_hda_codec_write(codec, nid, 0,
12291                                         AC_VERB_SET_PIN_WIDGET_CONTROL,
12292                                         i <= AUTO_PIN_FRONT_MIC ?
12293                                                         PIN_VREF80 : PIN_IN);
12294                         if (nid != ALC861VD_PIN_CD_NID)
12295                                 snd_hda_codec_write(codec, nid, 0,
12296                                                 AC_VERB_SET_AMP_GAIN_MUTE,
12297                                                 AMP_OUT_MUTE);
12298                 }
12299         }
12300 }
12301
12302 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
12303 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
12304
12305 /* add playback controls from the parsed DAC table */
12306 /* Based on ALC880 version. But ALC861VD has separate,
12307  * different NIDs for mute/unmute switch and volume control */
12308 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
12309                                              const struct auto_pin_cfg *cfg)
12310 {
12311         char name[32];
12312         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
12313         hda_nid_t nid_v, nid_s;
12314         int i, err;
12315
12316         for (i = 0; i < cfg->line_outs; i++) {
12317                 if (!spec->multiout.dac_nids[i])
12318                         continue;
12319                 nid_v = alc861vd_idx_to_mixer_vol(
12320                                 alc880_dac_to_idx(
12321                                         spec->multiout.dac_nids[i]));
12322                 nid_s = alc861vd_idx_to_mixer_switch(
12323                                 alc880_dac_to_idx(
12324                                         spec->multiout.dac_nids[i]));
12325
12326                 if (i == 2) {
12327                         /* Center/LFE */
12328                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12329                                           "Center Playback Volume",
12330                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
12331                                                               HDA_OUTPUT));
12332                         if (err < 0)
12333                                 return err;
12334                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12335                                           "LFE Playback Volume",
12336                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
12337                                                               HDA_OUTPUT));
12338                         if (err < 0)
12339                                 return err;
12340                         err = add_control(spec, ALC_CTL_BIND_MUTE,
12341                                           "Center Playback Switch",
12342                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
12343                                                               HDA_INPUT));
12344                         if (err < 0)
12345                                 return err;
12346                         err = add_control(spec, ALC_CTL_BIND_MUTE,
12347                                           "LFE Playback Switch",
12348                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
12349                                                               HDA_INPUT));
12350                         if (err < 0)
12351                                 return err;
12352                 } else {
12353                         sprintf(name, "%s Playback Volume", chname[i]);
12354                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
12355                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
12356                                                               HDA_OUTPUT));
12357                         if (err < 0)
12358                                 return err;
12359                         sprintf(name, "%s Playback Switch", chname[i]);
12360                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
12361                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
12362                                                               HDA_INPUT));
12363                         if (err < 0)
12364                                 return err;
12365                 }
12366         }
12367         return 0;
12368 }
12369
12370 /* add playback controls for speaker and HP outputs */
12371 /* Based on ALC880 version. But ALC861VD has separate,
12372  * different NIDs for mute/unmute switch and volume control */
12373 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
12374                                         hda_nid_t pin, const char *pfx)
12375 {
12376         hda_nid_t nid_v, nid_s;
12377         int err;
12378         char name[32];
12379
12380         if (!pin)
12381                 return 0;
12382
12383         if (alc880_is_fixed_pin(pin)) {
12384                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
12385                 /* specify the DAC as the extra output */
12386                 if (!spec->multiout.hp_nid)
12387                         spec->multiout.hp_nid = nid_v;
12388                 else
12389                         spec->multiout.extra_out_nid[0] = nid_v;
12390                 /* control HP volume/switch on the output mixer amp */
12391                 nid_v = alc861vd_idx_to_mixer_vol(
12392                                 alc880_fixed_pin_idx(pin));
12393                 nid_s = alc861vd_idx_to_mixer_switch(
12394                                 alc880_fixed_pin_idx(pin));
12395
12396                 sprintf(name, "%s Playback Volume", pfx);
12397                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
12398                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
12399                 if (err < 0)
12400                         return err;
12401                 sprintf(name, "%s Playback Switch", pfx);
12402                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
12403                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
12404                 if (err < 0)
12405                         return err;
12406         } else if (alc880_is_multi_pin(pin)) {
12407                 /* set manual connection */
12408                 /* we have only a switch on HP-out PIN */
12409                 sprintf(name, "%s Playback Switch", pfx);
12410                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
12411                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
12412                 if (err < 0)
12413                         return err;
12414         }
12415         return 0;
12416 }
12417
12418 /* parse the BIOS configuration and set up the alc_spec
12419  * return 1 if successful, 0 if the proper config is not found,
12420  * or a negative error code
12421  * Based on ALC880 version - had to change it to override
12422  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
12423 static int alc861vd_parse_auto_config(struct hda_codec *codec)
12424 {
12425         struct alc_spec *spec = codec->spec;
12426         int err;
12427         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
12428
12429         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
12430                                            alc861vd_ignore);
12431         if (err < 0)
12432                 return err;
12433         if (!spec->autocfg.line_outs)
12434                 return 0; /* can't find valid BIOS pin config */
12435
12436         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
12437         if (err < 0)
12438                 return err;
12439         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
12440         if (err < 0)
12441                 return err;
12442         err = alc861vd_auto_create_extra_out(spec,
12443                                              spec->autocfg.speaker_pins[0],
12444                                              "Speaker");
12445         if (err < 0)
12446                 return err;
12447         err = alc861vd_auto_create_extra_out(spec,
12448                                              spec->autocfg.hp_pins[0],
12449                                              "Headphone");
12450         if (err < 0)
12451                 return err;
12452         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
12453         if (err < 0)
12454                 return err;
12455
12456         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
12457
12458         if (spec->autocfg.dig_out_pin)
12459                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
12460
12461         if (spec->kctl_alloc)
12462                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
12463
12464         spec->init_verbs[spec->num_init_verbs++]
12465                 = alc861vd_volume_init_verbs;
12466
12467         spec->num_mux_defs = 1;
12468         spec->input_mux = &spec->private_imux;
12469
12470         err = alc_auto_add_mic_boost(codec);
12471         if (err < 0)
12472                 return err;
12473
12474         return 1;
12475 }
12476
12477 /* additional initialization for auto-configuration model */
12478 static void alc861vd_auto_init(struct hda_codec *codec)
12479 {
12480         alc861vd_auto_init_multi_out(codec);
12481         alc861vd_auto_init_hp_out(codec);
12482         alc861vd_auto_init_analog_input(codec);
12483 }
12484
12485 static int patch_alc861vd(struct hda_codec *codec)
12486 {
12487         struct alc_spec *spec;
12488         int err, board_config;
12489
12490         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
12491         if (spec == NULL)
12492                 return -ENOMEM;
12493
12494         codec->spec = spec;
12495
12496         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
12497                                                   alc861vd_models,
12498                                                   alc861vd_cfg_tbl);
12499
12500         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
12501                 printk(KERN_INFO "hda_codec: Unknown model for ALC660VD/"
12502                         "ALC861VD, trying auto-probe from BIOS...\n");
12503                 board_config = ALC861VD_AUTO;
12504         }
12505
12506         if (board_config == ALC861VD_AUTO) {
12507                 /* automatic parse from the BIOS config */
12508                 err = alc861vd_parse_auto_config(codec);
12509                 if (err < 0) {
12510                         alc_free(codec);
12511                         return err;
12512                 } else if (!err) {
12513                         printk(KERN_INFO
12514                                "hda_codec: Cannot set up configuration "
12515                                "from BIOS.  Using base mode...\n");
12516                         board_config = ALC861VD_3ST;
12517                 }
12518         }
12519
12520         if (board_config != ALC861VD_AUTO)
12521                 setup_preset(spec, &alc861vd_presets[board_config]);
12522
12523         spec->stream_name_analog = "ALC861VD Analog";
12524         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
12525         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
12526
12527         spec->stream_name_digital = "ALC861VD Digital";
12528         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
12529         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
12530
12531         spec->adc_nids = alc861vd_adc_nids;
12532         spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
12533
12534         spec->mixers[spec->num_mixers] = alc861vd_capture_mixer;
12535         spec->num_mixers++;
12536
12537         spec->vmaster_nid = 0x02;
12538
12539         codec->patch_ops = alc_patch_ops;
12540
12541         if (board_config == ALC861VD_AUTO)
12542                 spec->init_hook = alc861vd_auto_init;
12543 #ifdef CONFIG_SND_HDA_POWER_SAVE
12544         if (!spec->loopback.amplist)
12545                 spec->loopback.amplist = alc861vd_loopbacks;
12546 #endif
12547
12548         return 0;
12549 }
12550
12551 /*
12552  * ALC662 support
12553  *
12554  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
12555  * configuration.  Each pin widget can choose any input DACs and a mixer.
12556  * Each ADC is connected from a mixer of all inputs.  This makes possible
12557  * 6-channel independent captures.
12558  *
12559  * In addition, an independent DAC for the multi-playback (not used in this
12560  * driver yet).
12561  */
12562 #define ALC662_DIGOUT_NID       0x06
12563 #define ALC662_DIGIN_NID        0x0a
12564
12565 static hda_nid_t alc662_dac_nids[4] = {
12566         /* front, rear, clfe, rear_surr */
12567         0x02, 0x03, 0x04
12568 };
12569
12570 static hda_nid_t alc662_adc_nids[1] = {
12571         /* ADC1-2 */
12572         0x09,
12573 };
12574 /* input MUX */
12575 /* FIXME: should be a matrix-type input source selection */
12576
12577 static struct hda_input_mux alc662_capture_source = {
12578         .num_items = 4,
12579         .items = {
12580                 { "Mic", 0x0 },
12581                 { "Front Mic", 0x1 },
12582                 { "Line", 0x2 },
12583                 { "CD", 0x4 },
12584         },
12585 };
12586
12587 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
12588         .num_items = 2,
12589         .items = {
12590                 { "Mic", 0x1 },
12591                 { "Line", 0x2 },
12592         },
12593 };
12594
12595 static struct hda_input_mux alc662_eeepc_capture_source = {
12596         .num_items = 2,
12597         .items = {
12598                 { "i-Mic", 0x1 },
12599                 { "e-Mic", 0x0 },
12600         },
12601 };
12602
12603 #define alc662_mux_enum_info alc_mux_enum_info
12604 #define alc662_mux_enum_get alc_mux_enum_get
12605
12606 static int alc662_mux_enum_put(struct snd_kcontrol *kcontrol,
12607                                struct snd_ctl_elem_value *ucontrol)
12608 {
12609         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
12610         struct alc_spec *spec = codec->spec;
12611         const struct hda_input_mux *imux = spec->input_mux;
12612         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
12613         static hda_nid_t capture_mixers[2] = { 0x23, 0x22 };
12614         hda_nid_t nid = capture_mixers[adc_idx];
12615         unsigned int *cur_val = &spec->cur_mux[adc_idx];
12616         unsigned int i, idx;
12617
12618         idx = ucontrol->value.enumerated.item[0];
12619         if (idx >= imux->num_items)
12620                 idx = imux->num_items - 1;
12621         if (*cur_val == idx)
12622                 return 0;
12623         for (i = 0; i < imux->num_items; i++) {
12624                 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
12625                 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
12626                                          imux->items[i].index,
12627                                          HDA_AMP_MUTE, v);
12628         }
12629         *cur_val = idx;
12630         return 1;
12631 }
12632 /*
12633  * 2ch mode
12634  */
12635 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
12636         { 2, NULL }
12637 };
12638
12639 /*
12640  * 2ch mode
12641  */
12642 static struct hda_verb alc662_3ST_ch2_init[] = {
12643         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
12644         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
12645         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
12646         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
12647         { } /* end */
12648 };
12649
12650 /*
12651  * 6ch mode
12652  */
12653 static struct hda_verb alc662_3ST_ch6_init[] = {
12654         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12655         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
12656         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
12657         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12658         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
12659         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
12660         { } /* end */
12661 };
12662
12663 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
12664         { 2, alc662_3ST_ch2_init },
12665         { 6, alc662_3ST_ch6_init },
12666 };
12667
12668 /*
12669  * 2ch mode
12670  */
12671 static struct hda_verb alc662_sixstack_ch6_init[] = {
12672         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12673         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12674         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12675         { } /* end */
12676 };
12677
12678 /*
12679  * 6ch mode
12680  */
12681 static struct hda_verb alc662_sixstack_ch8_init[] = {
12682         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12683         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12684         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12685         { } /* end */
12686 };
12687
12688 static struct hda_channel_mode alc662_5stack_modes[2] = {
12689         { 2, alc662_sixstack_ch6_init },
12690         { 6, alc662_sixstack_ch8_init },
12691 };
12692
12693 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
12694  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
12695  */
12696
12697 static struct snd_kcontrol_new alc662_base_mixer[] = {
12698         /* output mixer control */
12699         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
12700         HDA_CODEC_MUTE("Front Playback Switch", 0x02, 0x0, HDA_OUTPUT),
12701         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
12702         HDA_CODEC_MUTE("Surround Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12703         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
12704         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
12705         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
12706         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
12707         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12708
12709         /*Input mixer control */
12710         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
12711         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
12712         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
12713         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
12714         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
12715         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
12716         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
12717         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
12718         { } /* end */
12719 };
12720
12721 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
12722         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12723         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
12724         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12725         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
12726         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
12727         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12728         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12729         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12730         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12731         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12732         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12733         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
12734         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
12735         { } /* end */
12736 };
12737
12738 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
12739         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12740         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
12741         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12742         HDA_BIND_MUTE("Surround Playback Switch", 0x03, 2, HDA_INPUT),
12743         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
12744         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
12745         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
12746         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
12747         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12748         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
12749         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
12750         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12751         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12752         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12753         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12754         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12755         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12756         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
12757         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
12758         { } /* end */
12759 };
12760
12761 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
12762         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12763         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
12764         HDA_CODEC_VOLUME("iSpeaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12765         HDA_BIND_MUTE("iSpeaker Playback Switch", 0x03, 2, HDA_INPUT),
12766         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12767         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12768         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12769         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12770         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12771         { } /* end */
12772 };
12773
12774 static struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
12775         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12776
12777         HDA_CODEC_VOLUME("LineOut Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12778         HDA_CODEC_MUTE("LineOut Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12779
12780         HDA_CODEC_VOLUME("e-Mic Boost", 0x18, 0, HDA_INPUT),
12781         HDA_CODEC_VOLUME("e-Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12782         HDA_CODEC_MUTE("e-Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12783
12784         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
12785         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12786         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12787         { } /* end */
12788 };
12789
12790 static struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
12791         HDA_CODEC_VOLUME("LineOut Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12792         HDA_CODEC_MUTE("LineOut Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12793         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12794         HDA_BIND_MUTE("Surround Playback Switch", 0x03, 2, HDA_INPUT),
12795         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
12796         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
12797         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
12798         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
12799         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12800         HDA_BIND_MUTE("MuteCtrl Playback Switch", 0x0c, 2, HDA_INPUT),
12801         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12802         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12803         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12804         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12805         { } /* end */
12806 };
12807
12808 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
12809         {
12810                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12811                 .name = "Channel Mode",
12812                 .info = alc_ch_mode_info,
12813                 .get = alc_ch_mode_get,
12814                 .put = alc_ch_mode_put,
12815         },
12816         { } /* end */
12817 };
12818
12819 static struct hda_verb alc662_init_verbs[] = {
12820         /* ADC: mute amp left and right */
12821         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12822         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
12823         /* Front mixer: unmute input/output amp left and right (volume = 0) */
12824
12825         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12826         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12827         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12828         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12829         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
12830
12831         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12832         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12833         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12834         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12835         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12836         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12837
12838         /* Front Pin: output 0 (0x0c) */
12839         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12840         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12841
12842         /* Rear Pin: output 1 (0x0d) */
12843         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12844         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12845
12846         /* CLFE Pin: output 2 (0x0e) */
12847         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12848         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12849
12850         /* Mic (rear) pin: input vref at 80% */
12851         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12852         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12853         /* Front Mic pin: input vref at 80% */
12854         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12855         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12856         /* Line In pin: input */
12857         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12858         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12859         /* Line-2 In: Headphone output (output 0 - 0x0c) */
12860         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12861         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12862         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
12863         /* CD pin widget for input */
12864         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12865
12866         /* FIXME: use matrix-type input source selection */
12867         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
12868         /* Input mixer */
12869         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12870         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12871         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12872         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
12873
12874         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12875         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12876         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12877         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
12878         { }
12879 };
12880
12881 static struct hda_verb alc662_sue_init_verbs[] = {
12882         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
12883         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
12884         {}
12885 };
12886
12887 static struct hda_verb alc662_eeepc_sue_init_verbs[] = {
12888         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12889         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12890         {}
12891 };
12892
12893 /* Set Unsolicited Event*/
12894 static struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
12895         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12896         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12897         {}
12898 };
12899
12900 /*
12901  * generic initialization of ADC, input mixers and output mixers
12902  */
12903 static struct hda_verb alc662_auto_init_verbs[] = {
12904         /*
12905          * Unmute ADC and set the default input to mic-in
12906          */
12907         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
12908         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12909
12910         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
12911          * mixer widget
12912          * Note: PASD motherboards uses the Line In 2 as the input for front
12913          * panel mic (mic 2)
12914          */
12915         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
12916         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12917         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12918         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12919         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12920         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
12921
12922         /*
12923          * Set up output mixers (0x0c - 0x0f)
12924          */
12925         /* set vol=0 to output mixers */
12926         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12927         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12928         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12929
12930         /* set up input amps for analog loopback */
12931         /* Amp Indices: DAC = 0, mixer = 1 */
12932         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12933         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12934         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12935         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12936         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12937         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12938
12939
12940         /* FIXME: use matrix-type input source selection */
12941         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
12942         /* Input mixer */
12943         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12944         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12945         { }
12946 };
12947
12948 /* capture mixer elements */
12949 static struct snd_kcontrol_new alc662_capture_mixer[] = {
12950         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
12951         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
12952         {
12953                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12954                 /* The multiple "Capture Source" controls confuse alsamixer
12955                  * So call somewhat different..
12956                  */
12957                 /* .name = "Capture Source", */
12958                 .name = "Input Source",
12959                 .count = 1,
12960                 .info = alc662_mux_enum_info,
12961                 .get = alc662_mux_enum_get,
12962                 .put = alc662_mux_enum_put,
12963         },
12964         { } /* end */
12965 };
12966
12967 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
12968 {
12969         unsigned int present;
12970         unsigned char bits;
12971
12972         present = snd_hda_codec_read(codec, 0x14, 0,
12973                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12974         bits = present ? HDA_AMP_MUTE : 0;
12975         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
12976                                  HDA_AMP_MUTE, bits);
12977 }
12978
12979 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
12980 {
12981         unsigned int present;
12982         unsigned char bits;
12983
12984         present = snd_hda_codec_read(codec, 0x1b, 0,
12985                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12986         bits = present ? HDA_AMP_MUTE : 0;
12987         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
12988                                  HDA_AMP_MUTE, bits);
12989         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
12990                                  HDA_AMP_MUTE, bits);
12991 }
12992
12993 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
12994                                            unsigned int res)
12995 {
12996         if ((res >> 26) == ALC880_HP_EVENT)
12997                 alc662_lenovo_101e_all_automute(codec);
12998         if ((res >> 26) == ALC880_FRONT_EVENT)
12999                 alc662_lenovo_101e_ispeaker_automute(codec);
13000 }
13001
13002 static void alc662_eeepc_mic_automute(struct hda_codec *codec)
13003 {
13004         unsigned int present;
13005
13006         present = snd_hda_codec_read(codec, 0x18, 0,
13007                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13008         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13009                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
13010         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13011                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
13012         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13013                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
13014         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13015                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
13016 }
13017
13018 /* unsolicited event for HP jack sensing */
13019 static void alc662_eeepc_unsol_event(struct hda_codec *codec,
13020                                      unsigned int res)
13021 {
13022         if ((res >> 26) == ALC880_HP_EVENT)
13023                 alc262_hippo1_automute( codec );
13024
13025         if ((res >> 26) == ALC880_MIC_EVENT)
13026                 alc662_eeepc_mic_automute(codec);
13027 }
13028
13029 static void alc662_eeepc_inithook(struct hda_codec *codec)
13030 {
13031         alc262_hippo1_automute( codec );
13032         alc662_eeepc_mic_automute(codec);
13033 }
13034
13035 static void alc662_eeepc_ep20_automute(struct hda_codec *codec)
13036 {
13037         unsigned int mute;
13038         unsigned int present;
13039
13040         snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
13041         present = snd_hda_codec_read(codec, 0x14, 0,
13042                                      AC_VERB_GET_PIN_SENSE, 0);
13043         present = (present & 0x80000000) != 0;
13044         if (present) {
13045                 /* mute internal speaker */
13046                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
13047                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
13048         } else {
13049                 /* unmute internal speaker if necessary */
13050                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
13051                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
13052                                          HDA_AMP_MUTE, mute);
13053         }
13054 }
13055
13056 /* unsolicited event for HP jack sensing */
13057 static void alc662_eeepc_ep20_unsol_event(struct hda_codec *codec,
13058                                           unsigned int res)
13059 {
13060         if ((res >> 26) == ALC880_HP_EVENT)
13061                 alc662_eeepc_ep20_automute(codec);
13062 }
13063
13064 static void alc662_eeepc_ep20_inithook(struct hda_codec *codec)
13065 {
13066         alc662_eeepc_ep20_automute(codec);
13067 }
13068
13069 #ifdef CONFIG_SND_HDA_POWER_SAVE
13070 #define alc662_loopbacks        alc880_loopbacks
13071 #endif
13072
13073
13074 /* pcm configuration: identiacal with ALC880 */
13075 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
13076 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
13077 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
13078 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
13079
13080 /*
13081  * configuration and preset
13082  */
13083 static const char *alc662_models[ALC662_MODEL_LAST] = {
13084         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
13085         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
13086         [ALC662_3ST_6ch]        = "3stack-6ch",
13087         [ALC662_5ST_DIG]        = "6stack-dig",
13088         [ALC662_LENOVO_101E]    = "lenovo-101e",
13089         [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
13090         [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
13091         [ALC662_AUTO]           = "auto",
13092 };
13093
13094 static struct snd_pci_quirk alc662_cfg_tbl[] = {
13095         SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
13096         SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
13097         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
13098         {}
13099 };
13100
13101 static struct alc_config_preset alc662_presets[] = {
13102         [ALC662_3ST_2ch_DIG] = {
13103                 .mixers = { alc662_3ST_2ch_mixer, alc662_capture_mixer },
13104                 .init_verbs = { alc662_init_verbs },
13105                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13106                 .dac_nids = alc662_dac_nids,
13107                 .dig_out_nid = ALC662_DIGOUT_NID,
13108                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
13109                 .adc_nids = alc662_adc_nids,
13110                 .dig_in_nid = ALC662_DIGIN_NID,
13111                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
13112                 .channel_mode = alc662_3ST_2ch_modes,
13113                 .input_mux = &alc662_capture_source,
13114         },
13115         [ALC662_3ST_6ch_DIG] = {
13116                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer,
13117                             alc662_capture_mixer },
13118                 .init_verbs = { alc662_init_verbs },
13119                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13120                 .dac_nids = alc662_dac_nids,
13121                 .dig_out_nid = ALC662_DIGOUT_NID,
13122                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
13123                 .adc_nids = alc662_adc_nids,
13124                 .dig_in_nid = ALC662_DIGIN_NID,
13125                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
13126                 .channel_mode = alc662_3ST_6ch_modes,
13127                 .need_dac_fix = 1,
13128                 .input_mux = &alc662_capture_source,
13129         },
13130         [ALC662_3ST_6ch] = {
13131                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer,
13132                             alc662_capture_mixer },
13133                 .init_verbs = { alc662_init_verbs },
13134                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13135                 .dac_nids = alc662_dac_nids,
13136                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
13137                 .adc_nids = alc662_adc_nids,
13138                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
13139                 .channel_mode = alc662_3ST_6ch_modes,
13140                 .need_dac_fix = 1,
13141                 .input_mux = &alc662_capture_source,
13142         },
13143         [ALC662_5ST_DIG] = {
13144                 .mixers = { alc662_base_mixer, alc662_chmode_mixer,
13145                             alc662_capture_mixer },
13146                 .init_verbs = { alc662_init_verbs },
13147                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13148                 .dac_nids = alc662_dac_nids,
13149                 .dig_out_nid = ALC662_DIGOUT_NID,
13150                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
13151                 .adc_nids = alc662_adc_nids,
13152                 .dig_in_nid = ALC662_DIGIN_NID,
13153                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
13154                 .channel_mode = alc662_5stack_modes,
13155                 .input_mux = &alc662_capture_source,
13156         },
13157         [ALC662_LENOVO_101E] = {
13158                 .mixers = { alc662_lenovo_101e_mixer, alc662_capture_mixer },
13159                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
13160                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13161                 .dac_nids = alc662_dac_nids,
13162                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
13163                 .adc_nids = alc662_adc_nids,
13164                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
13165                 .channel_mode = alc662_3ST_2ch_modes,
13166                 .input_mux = &alc662_lenovo_101e_capture_source,
13167                 .unsol_event = alc662_lenovo_101e_unsol_event,
13168                 .init_hook = alc662_lenovo_101e_all_automute,
13169         },
13170         [ALC662_ASUS_EEEPC_P701] = {
13171                 .mixers = { alc662_eeepc_p701_mixer, alc662_capture_mixer },
13172                 .init_verbs = { alc662_init_verbs,
13173                                 alc662_eeepc_sue_init_verbs },
13174                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13175                 .dac_nids = alc662_dac_nids,
13176                 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
13177                 .adc_nids = alc662_adc_nids,
13178                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
13179                 .channel_mode = alc662_3ST_2ch_modes,
13180                 .input_mux = &alc662_eeepc_capture_source,
13181                 .unsol_event = alc662_eeepc_unsol_event,
13182                 .init_hook = alc662_eeepc_inithook,
13183         },
13184         [ALC662_ASUS_EEEPC_EP20] = {
13185                 .mixers = { alc662_eeepc_ep20_mixer, alc662_capture_mixer,
13186                             alc662_chmode_mixer },
13187                 .init_verbs = { alc662_init_verbs,
13188                                 alc662_eeepc_ep20_sue_init_verbs },
13189                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13190                 .dac_nids = alc662_dac_nids,
13191                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
13192                 .adc_nids = alc662_adc_nids,
13193                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
13194                 .channel_mode = alc662_3ST_6ch_modes,
13195                 .input_mux = &alc662_lenovo_101e_capture_source,
13196                 .unsol_event = alc662_eeepc_ep20_unsol_event,
13197                 .init_hook = alc662_eeepc_ep20_inithook,
13198         },
13199
13200 };
13201
13202
13203 /*
13204  * BIOS auto configuration
13205  */
13206
13207 /* add playback controls from the parsed DAC table */
13208 static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec,
13209                                              const struct auto_pin_cfg *cfg)
13210 {
13211         char name[32];
13212         static const char *chname[4] = {
13213                 "Front", "Surround", NULL /*CLFE*/, "Side"
13214         };
13215         hda_nid_t nid;
13216         int i, err;
13217
13218         for (i = 0; i < cfg->line_outs; i++) {
13219                 if (!spec->multiout.dac_nids[i])
13220                         continue;
13221                 nid = alc880_idx_to_dac(i);
13222                 if (i == 2) {
13223                         /* Center/LFE */
13224                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
13225                                           "Center Playback Volume",
13226                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
13227                                                               HDA_OUTPUT));
13228                         if (err < 0)
13229                                 return err;
13230                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
13231                                           "LFE Playback Volume",
13232                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
13233                                                               HDA_OUTPUT));
13234                         if (err < 0)
13235                                 return err;
13236                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13237                                           "Center Playback Switch",
13238                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
13239                                                               HDA_INPUT));
13240                         if (err < 0)
13241                                 return err;
13242                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13243                                           "LFE Playback Switch",
13244                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
13245                                                               HDA_INPUT));
13246                         if (err < 0)
13247                                 return err;
13248                 } else {
13249                         sprintf(name, "%s Playback Volume", chname[i]);
13250                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
13251                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
13252                                                               HDA_OUTPUT));
13253                         if (err < 0)
13254                                 return err;
13255                         sprintf(name, "%s Playback Switch", chname[i]);
13256                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
13257                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
13258                                                               HDA_INPUT));
13259                         if (err < 0)
13260                                 return err;
13261                 }
13262         }
13263         return 0;
13264 }
13265
13266 /* add playback controls for speaker and HP outputs */
13267 static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
13268                                         const char *pfx)
13269 {
13270         hda_nid_t nid;
13271         int err;
13272         char name[32];
13273
13274         if (!pin)
13275                 return 0;
13276
13277         if (alc880_is_fixed_pin(pin)) {
13278                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
13279                 /* printk("DAC nid=%x\n",nid); */
13280                 /* specify the DAC as the extra output */
13281                 if (!spec->multiout.hp_nid)
13282                         spec->multiout.hp_nid = nid;
13283                 else
13284                         spec->multiout.extra_out_nid[0] = nid;
13285                 /* control HP volume/switch on the output mixer amp */
13286                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
13287                 sprintf(name, "%s Playback Volume", pfx);
13288                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
13289                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
13290                 if (err < 0)
13291                         return err;
13292                 sprintf(name, "%s Playback Switch", pfx);
13293                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
13294                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
13295                 if (err < 0)
13296                         return err;
13297         } else if (alc880_is_multi_pin(pin)) {
13298                 /* set manual connection */
13299                 /* we have only a switch on HP-out PIN */
13300                 sprintf(name, "%s Playback Switch", pfx);
13301                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
13302                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
13303                 if (err < 0)
13304                         return err;
13305         }
13306         return 0;
13307 }
13308
13309 /* create playback/capture controls for input pins */
13310 static int alc662_auto_create_analog_input_ctls(struct alc_spec *spec,
13311                                                 const struct auto_pin_cfg *cfg)
13312 {
13313         struct hda_input_mux *imux = &spec->private_imux;
13314         int i, err, idx;
13315
13316         for (i = 0; i < AUTO_PIN_LAST; i++) {
13317                 if (alc880_is_input_pin(cfg->input_pins[i])) {
13318                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
13319                         err = new_analog_input(spec, cfg->input_pins[i],
13320                                                auto_pin_cfg_labels[i],
13321                                                idx, 0x0b);
13322                         if (err < 0)
13323                                 return err;
13324                         imux->items[imux->num_items].label =
13325                                 auto_pin_cfg_labels[i];
13326                         imux->items[imux->num_items].index =
13327                                 alc880_input_pin_idx(cfg->input_pins[i]);
13328                         imux->num_items++;
13329                 }
13330         }
13331         return 0;
13332 }
13333
13334 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
13335                                               hda_nid_t nid, int pin_type,
13336                                               int dac_idx)
13337 {
13338         /* set as output */
13339         snd_hda_codec_write(codec, nid, 0,
13340                             AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
13341         snd_hda_codec_write(codec, nid, 0,
13342                             AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
13343         /* need the manual connection? */
13344         if (alc880_is_multi_pin(nid)) {
13345                 struct alc_spec *spec = codec->spec;
13346                 int idx = alc880_multi_pin_idx(nid);
13347                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
13348                                     AC_VERB_SET_CONNECT_SEL,
13349                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
13350         }
13351 }
13352
13353 static void alc662_auto_init_multi_out(struct hda_codec *codec)
13354 {
13355         struct alc_spec *spec = codec->spec;
13356         int i;
13357
13358         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
13359         for (i = 0; i <= HDA_SIDE; i++) {
13360                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
13361                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
13362                 if (nid)
13363                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
13364                                                           i);
13365         }
13366 }
13367
13368 static void alc662_auto_init_hp_out(struct hda_codec *codec)
13369 {
13370         struct alc_spec *spec = codec->spec;
13371         hda_nid_t pin;
13372
13373         pin = spec->autocfg.hp_pins[0];
13374         if (pin) /* connect to front */
13375                 /* use dac 0 */
13376                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
13377 }
13378
13379 #define alc662_is_input_pin(nid)        alc880_is_input_pin(nid)
13380 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
13381
13382 static void alc662_auto_init_analog_input(struct hda_codec *codec)
13383 {
13384         struct alc_spec *spec = codec->spec;
13385         int i;
13386
13387         for (i = 0; i < AUTO_PIN_LAST; i++) {
13388                 hda_nid_t nid = spec->autocfg.input_pins[i];
13389                 if (alc662_is_input_pin(nid)) {
13390                         snd_hda_codec_write(codec, nid, 0,
13391                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
13392                                             (i <= AUTO_PIN_FRONT_MIC ?
13393                                              PIN_VREF80 : PIN_IN));
13394                         if (nid != ALC662_PIN_CD_NID)
13395                                 snd_hda_codec_write(codec, nid, 0,
13396                                                     AC_VERB_SET_AMP_GAIN_MUTE,
13397                                                     AMP_OUT_MUTE);
13398                 }
13399         }
13400 }
13401
13402 static int alc662_parse_auto_config(struct hda_codec *codec)
13403 {
13404         struct alc_spec *spec = codec->spec;
13405         int err;
13406         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
13407
13408         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
13409                                            alc662_ignore);
13410         if (err < 0)
13411                 return err;
13412         if (!spec->autocfg.line_outs)
13413                 return 0; /* can't find valid BIOS pin config */
13414
13415         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
13416         if (err < 0)
13417                 return err;
13418         err = alc662_auto_create_multi_out_ctls(spec, &spec->autocfg);
13419         if (err < 0)
13420                 return err;
13421         err = alc662_auto_create_extra_out(spec,
13422                                            spec->autocfg.speaker_pins[0],
13423                                            "Speaker");
13424         if (err < 0)
13425                 return err;
13426         err = alc662_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
13427                                            "Headphone");
13428         if (err < 0)
13429                 return err;
13430         err = alc662_auto_create_analog_input_ctls(spec, &spec->autocfg);
13431         if (err < 0)
13432                 return err;
13433
13434         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
13435
13436         if (spec->autocfg.dig_out_pin)
13437                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
13438
13439         if (spec->kctl_alloc)
13440                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
13441
13442         spec->num_mux_defs = 1;
13443         spec->input_mux = &spec->private_imux;
13444         
13445         spec->init_verbs[spec->num_init_verbs++] = alc662_auto_init_verbs;
13446         spec->mixers[spec->num_mixers] = alc662_capture_mixer;
13447         spec->num_mixers++;
13448         return 1;
13449 }
13450
13451 /* additional initialization for auto-configuration model */
13452 static void alc662_auto_init(struct hda_codec *codec)
13453 {
13454         alc662_auto_init_multi_out(codec);
13455         alc662_auto_init_hp_out(codec);
13456         alc662_auto_init_analog_input(codec);
13457 }
13458
13459 static int patch_alc662(struct hda_codec *codec)
13460 {
13461         struct alc_spec *spec;
13462         int err, board_config;
13463
13464         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13465         if (!spec)
13466                 return -ENOMEM;
13467
13468         codec->spec = spec;
13469
13470         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
13471                                                   alc662_models,
13472                                                   alc662_cfg_tbl);
13473         if (board_config < 0) {
13474                 printk(KERN_INFO "hda_codec: Unknown model for ALC662, "
13475                        "trying auto-probe from BIOS...\n");
13476                 board_config = ALC662_AUTO;
13477         }
13478
13479         if (board_config == ALC662_AUTO) {
13480                 /* automatic parse from the BIOS config */
13481                 err = alc662_parse_auto_config(codec);
13482                 if (err < 0) {
13483                         alc_free(codec);
13484                         return err;
13485                 } else if (!err) {
13486                         printk(KERN_INFO
13487                                "hda_codec: Cannot set up configuration "
13488                                "from BIOS.  Using base mode...\n");
13489                         board_config = ALC662_3ST_2ch_DIG;
13490                 }
13491         }
13492
13493         if (board_config != ALC662_AUTO)
13494                 setup_preset(spec, &alc662_presets[board_config]);
13495
13496         spec->stream_name_analog = "ALC662 Analog";
13497         spec->stream_analog_playback = &alc662_pcm_analog_playback;
13498         spec->stream_analog_capture = &alc662_pcm_analog_capture;
13499
13500         spec->stream_name_digital = "ALC662 Digital";
13501         spec->stream_digital_playback = &alc662_pcm_digital_playback;
13502         spec->stream_digital_capture = &alc662_pcm_digital_capture;
13503
13504         if (!spec->adc_nids && spec->input_mux) {
13505                 spec->adc_nids = alc662_adc_nids;
13506                 spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
13507         }
13508
13509         spec->vmaster_nid = 0x02;
13510
13511         codec->patch_ops = alc_patch_ops;
13512         if (board_config == ALC662_AUTO)
13513                 spec->init_hook = alc662_auto_init;
13514 #ifdef CONFIG_SND_HDA_POWER_SAVE
13515         if (!spec->loopback.amplist)
13516                 spec->loopback.amplist = alc662_loopbacks;
13517 #endif
13518
13519         return 0;
13520 }
13521
13522 /*
13523  * patch entries
13524  */
13525 struct hda_codec_preset snd_hda_preset_realtek[] = {
13526         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
13527         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
13528         { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
13529         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
13530         { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
13531         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
13532           .patch = patch_alc861 },
13533         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
13534         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
13535         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
13536         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
13537           .patch = patch_alc883 },
13538         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
13539           .patch = patch_alc662 },
13540         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
13541         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
13542         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
13543         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
13544         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
13545         { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 },
13546         {} /* terminator */
13547 };