Merge git://git.kernel.org/pub/scm/linux/kernel/git/jk/spufs
[linux-2.6] / sound / pci / hda / patch_realtek.c
1 /*
2  * Universal Interface for Intel High Definition Audio Codec
3  *
4  * HD audio interface patch for ALC 260/880/882 codecs
5  *
6  * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7  *                    PeiSen Hou <pshou@realtek.com.tw>
8  *                    Takashi Iwai <tiwai@suse.de>
9  *                    Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
10  *
11  *  This driver is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This driver is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
24  */
25
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/slab.h>
29 #include <linux/pci.h>
30 #include <sound/core.h>
31 #include "hda_codec.h"
32 #include "hda_local.h"
33 #include "hda_patch.h"
34
35 #define ALC880_FRONT_EVENT              0x01
36 #define ALC880_DCVOL_EVENT              0x02
37 #define ALC880_HP_EVENT                 0x04
38 #define ALC880_MIC_EVENT                0x08
39
40 /* ALC880 board config type */
41 enum {
42         ALC880_3ST,
43         ALC880_3ST_DIG,
44         ALC880_5ST,
45         ALC880_5ST_DIG,
46         ALC880_W810,
47         ALC880_Z71V,
48         ALC880_6ST,
49         ALC880_6ST_DIG,
50         ALC880_F1734,
51         ALC880_ASUS,
52         ALC880_ASUS_DIG,
53         ALC880_ASUS_W1V,
54         ALC880_ASUS_DIG2,
55         ALC880_FUJITSU,
56         ALC880_UNIWILL_DIG,
57         ALC880_UNIWILL,
58         ALC880_UNIWILL_P53,
59         ALC880_CLEVO,
60         ALC880_TCL_S700,
61         ALC880_LG,
62         ALC880_LG_LW,
63 #ifdef CONFIG_SND_DEBUG
64         ALC880_TEST,
65 #endif
66         ALC880_AUTO,
67         ALC880_MODEL_LAST /* last tag */
68 };
69
70 /* ALC260 models */
71 enum {
72         ALC260_BASIC,
73         ALC260_HP,
74         ALC260_HP_3013,
75         ALC260_FUJITSU_S702X,
76         ALC260_ACER,
77         ALC260_WILL,
78         ALC260_REPLACER_672V,
79 #ifdef CONFIG_SND_DEBUG
80         ALC260_TEST,
81 #endif
82         ALC260_AUTO,
83         ALC260_MODEL_LAST /* last tag */
84 };
85
86 /* ALC262 models */
87 enum {
88         ALC262_BASIC,
89         ALC262_HIPPO,
90         ALC262_HIPPO_1,
91         ALC262_FUJITSU,
92         ALC262_HP_BPC,
93         ALC262_HP_BPC_D7000_WL,
94         ALC262_HP_BPC_D7000_WF,
95         ALC262_HP_TC_T5735,
96         ALC262_HP_RP5700,
97         ALC262_BENQ_ED8,
98         ALC262_SONY_ASSAMD,
99         ALC262_BENQ_T31,
100         ALC262_ULTRA,
101         ALC262_LENOVO_3000,
102         ALC262_AUTO,
103         ALC262_MODEL_LAST /* last tag */
104 };
105
106 /* ALC268 models */
107 enum {
108         ALC267_QUANTA_IL1,
109         ALC268_3ST,
110         ALC268_TOSHIBA,
111         ALC268_ACER,
112         ALC268_DELL,
113         ALC268_ZEPTO,
114 #ifdef CONFIG_SND_DEBUG
115         ALC268_TEST,
116 #endif
117         ALC268_AUTO,
118         ALC268_MODEL_LAST /* last tag */
119 };
120
121 /* ALC269 models */
122 enum {
123         ALC269_BASIC,
124         ALC269_AUTO,
125         ALC269_MODEL_LAST /* last tag */
126 };
127
128 /* ALC861 models */
129 enum {
130         ALC861_3ST,
131         ALC660_3ST,
132         ALC861_3ST_DIG,
133         ALC861_6ST_DIG,
134         ALC861_UNIWILL_M31,
135         ALC861_TOSHIBA,
136         ALC861_ASUS,
137         ALC861_ASUS_LAPTOP,
138         ALC861_AUTO,
139         ALC861_MODEL_LAST,
140 };
141
142 /* ALC861-VD models */
143 enum {
144         ALC660VD_3ST,
145         ALC660VD_3ST_DIG,
146         ALC861VD_3ST,
147         ALC861VD_3ST_DIG,
148         ALC861VD_6ST_DIG,
149         ALC861VD_LENOVO,
150         ALC861VD_DALLAS,
151         ALC861VD_HP,
152         ALC861VD_AUTO,
153         ALC861VD_MODEL_LAST,
154 };
155
156 /* ALC662 models */
157 enum {
158         ALC662_3ST_2ch_DIG,
159         ALC662_3ST_6ch_DIG,
160         ALC662_3ST_6ch,
161         ALC662_5ST_DIG,
162         ALC662_LENOVO_101E,
163         ALC662_ASUS_EEEPC_P701,
164         ALC662_ASUS_EEEPC_EP20,
165         ALC662_AUTO,
166         ALC662_MODEL_LAST,
167 };
168
169 /* ALC882 models */
170 enum {
171         ALC882_3ST_DIG,
172         ALC882_6ST_DIG,
173         ALC882_ARIMA,
174         ALC882_W2JC,
175         ALC882_TARGA,
176         ALC882_ASUS_A7J,
177         ALC882_ASUS_A7M,
178         ALC885_MACPRO,
179         ALC885_MBP3,
180         ALC885_IMAC24,
181         ALC882_AUTO,
182         ALC882_MODEL_LAST,
183 };
184
185 /* ALC883 models */
186 enum {
187         ALC883_3ST_2ch_DIG,
188         ALC883_3ST_6ch_DIG,
189         ALC883_3ST_6ch,
190         ALC883_6ST_DIG,
191         ALC883_TARGA_DIG,
192         ALC883_TARGA_2ch_DIG,
193         ALC883_ACER,
194         ALC883_ACER_ASPIRE,
195         ALC883_MEDION,
196         ALC883_MEDION_MD2,      
197         ALC883_LAPTOP_EAPD,
198         ALC883_LENOVO_101E_2ch,
199         ALC883_LENOVO_NB0763,
200         ALC888_LENOVO_MS7195_DIG,
201         ALC883_HAIER_W66,               
202         ALC888_3ST_HP,
203         ALC888_6ST_DELL,
204         ALC883_MITAC,
205         ALC883_CLEVO_M720,
206         ALC883_FUJITSU_PI2515,
207         ALC883_AUTO,
208         ALC883_MODEL_LAST,
209 };
210
211 /* for GPIO Poll */
212 #define GPIO_MASK       0x03
213
214 struct alc_spec {
215         /* codec parameterization */
216         struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
217         unsigned int num_mixers;
218
219         const struct hda_verb *init_verbs[5];   /* initialization verbs
220                                                  * don't forget NULL
221                                                  * termination!
222                                                  */
223         unsigned int num_init_verbs;
224
225         char *stream_name_analog;       /* analog PCM stream */
226         struct hda_pcm_stream *stream_analog_playback;
227         struct hda_pcm_stream *stream_analog_capture;
228         struct hda_pcm_stream *stream_analog_alt_playback;
229         struct hda_pcm_stream *stream_analog_alt_capture;
230
231         char *stream_name_digital;      /* digital PCM stream */
232         struct hda_pcm_stream *stream_digital_playback;
233         struct hda_pcm_stream *stream_digital_capture;
234
235         /* playback */
236         struct hda_multi_out multiout;  /* playback set-up
237                                          * max_channels, dacs must be set
238                                          * dig_out_nid and hp_nid are optional
239                                          */
240         hda_nid_t alt_dac_nid;
241
242         /* capture */
243         unsigned int num_adc_nids;
244         hda_nid_t *adc_nids;
245         hda_nid_t *capsrc_nids;
246         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
247
248         /* capture source */
249         unsigned int num_mux_defs;
250         const struct hda_input_mux *input_mux;
251         unsigned int cur_mux[3];
252
253         /* channel model */
254         const struct hda_channel_mode *channel_mode;
255         int num_channel_mode;
256         int need_dac_fix;
257
258         /* PCM information */
259         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
260
261         /* dynamic controls, init_verbs and input_mux */
262         struct auto_pin_cfg autocfg;
263         unsigned int num_kctl_alloc, num_kctl_used;
264         struct snd_kcontrol_new *kctl_alloc;
265         struct hda_input_mux private_imux;
266         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
267
268         /* hooks */
269         void (*init_hook)(struct hda_codec *codec);
270         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
271
272         /* for pin sensing */
273         unsigned int sense_updated: 1;
274         unsigned int jack_present: 1;
275         unsigned int master_sw: 1;
276
277         /* for virtual master */
278         hda_nid_t vmaster_nid;
279 #ifdef CONFIG_SND_HDA_POWER_SAVE
280         struct hda_loopback_check loopback;
281 #endif
282 };
283
284 /*
285  * configuration template - to be copied to the spec instance
286  */
287 struct alc_config_preset {
288         struct snd_kcontrol_new *mixers[5]; /* should be identical size
289                                              * with spec
290                                              */
291         const struct hda_verb *init_verbs[5];
292         unsigned int num_dacs;
293         hda_nid_t *dac_nids;
294         hda_nid_t dig_out_nid;          /* optional */
295         hda_nid_t hp_nid;               /* optional */
296         unsigned int num_adc_nids;
297         hda_nid_t *adc_nids;
298         hda_nid_t *capsrc_nids;
299         hda_nid_t dig_in_nid;
300         unsigned int num_channel_mode;
301         const struct hda_channel_mode *channel_mode;
302         int need_dac_fix;
303         unsigned int num_mux_defs;
304         const struct hda_input_mux *input_mux;
305         void (*unsol_event)(struct hda_codec *, unsigned int);
306         void (*init_hook)(struct hda_codec *);
307 #ifdef CONFIG_SND_HDA_POWER_SAVE
308         struct hda_amp_list *loopbacks;
309 #endif
310 };
311
312
313 /*
314  * input MUX handling
315  */
316 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
317                              struct snd_ctl_elem_info *uinfo)
318 {
319         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
320         struct alc_spec *spec = codec->spec;
321         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
322         if (mux_idx >= spec->num_mux_defs)
323                 mux_idx = 0;
324         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
325 }
326
327 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
328                             struct snd_ctl_elem_value *ucontrol)
329 {
330         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
331         struct alc_spec *spec = codec->spec;
332         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
333
334         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
335         return 0;
336 }
337
338 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
339                             struct snd_ctl_elem_value *ucontrol)
340 {
341         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
342         struct alc_spec *spec = codec->spec;
343         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
344         unsigned int mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
345         hda_nid_t nid = spec->capsrc_nids ?
346                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
347         return snd_hda_input_mux_put(codec, &spec->input_mux[mux_idx], ucontrol,
348                                      nid, &spec->cur_mux[adc_idx]);
349 }
350
351
352 /*
353  * channel mode setting
354  */
355 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
356                             struct snd_ctl_elem_info *uinfo)
357 {
358         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
359         struct alc_spec *spec = codec->spec;
360         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
361                                     spec->num_channel_mode);
362 }
363
364 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
365                            struct snd_ctl_elem_value *ucontrol)
366 {
367         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
368         struct alc_spec *spec = codec->spec;
369         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
370                                    spec->num_channel_mode,
371                                    spec->multiout.max_channels);
372 }
373
374 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
375                            struct snd_ctl_elem_value *ucontrol)
376 {
377         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
378         struct alc_spec *spec = codec->spec;
379         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
380                                       spec->num_channel_mode,
381                                       &spec->multiout.max_channels);
382         if (err >= 0 && spec->need_dac_fix)
383                 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
384         return err;
385 }
386
387 /*
388  * Control the mode of pin widget settings via the mixer.  "pc" is used
389  * instead of "%" to avoid consequences of accidently treating the % as 
390  * being part of a format specifier.  Maximum allowed length of a value is
391  * 63 characters plus NULL terminator.
392  *
393  * Note: some retasking pin complexes seem to ignore requests for input
394  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
395  * are requested.  Therefore order this list so that this behaviour will not
396  * cause problems when mixer clients move through the enum sequentially.
397  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
398  * March 2006.
399  */
400 static char *alc_pin_mode_names[] = {
401         "Mic 50pc bias", "Mic 80pc bias",
402         "Line in", "Line out", "Headphone out",
403 };
404 static unsigned char alc_pin_mode_values[] = {
405         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
406 };
407 /* The control can present all 5 options, or it can limit the options based
408  * in the pin being assumed to be exclusively an input or an output pin.  In
409  * addition, "input" pins may or may not process the mic bias option
410  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
411  * accept requests for bias as of chip versions up to March 2006) and/or
412  * wiring in the computer.
413  */
414 #define ALC_PIN_DIR_IN              0x00
415 #define ALC_PIN_DIR_OUT             0x01
416 #define ALC_PIN_DIR_INOUT           0x02
417 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
418 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
419
420 /* Info about the pin modes supported by the different pin direction modes. 
421  * For each direction the minimum and maximum values are given.
422  */
423 static signed char alc_pin_mode_dir_info[5][2] = {
424         { 0, 2 },    /* ALC_PIN_DIR_IN */
425         { 3, 4 },    /* ALC_PIN_DIR_OUT */
426         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
427         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
428         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
429 };
430 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
431 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
432 #define alc_pin_mode_n_items(_dir) \
433         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
434
435 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
436                              struct snd_ctl_elem_info *uinfo)
437 {
438         unsigned int item_num = uinfo->value.enumerated.item;
439         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
440
441         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
442         uinfo->count = 1;
443         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
444
445         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
446                 item_num = alc_pin_mode_min(dir);
447         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
448         return 0;
449 }
450
451 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
452                             struct snd_ctl_elem_value *ucontrol)
453 {
454         unsigned int i;
455         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
456         hda_nid_t nid = kcontrol->private_value & 0xffff;
457         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
458         long *valp = ucontrol->value.integer.value;
459         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
460                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
461                                                  0x00);
462
463         /* Find enumerated value for current pinctl setting */
464         i = alc_pin_mode_min(dir);
465         while (alc_pin_mode_values[i] != pinctl && i <= alc_pin_mode_max(dir))
466                 i++;
467         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
468         return 0;
469 }
470
471 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
472                             struct snd_ctl_elem_value *ucontrol)
473 {
474         signed int change;
475         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
476         hda_nid_t nid = kcontrol->private_value & 0xffff;
477         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
478         long val = *ucontrol->value.integer.value;
479         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
480                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
481                                                  0x00);
482
483         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
484                 val = alc_pin_mode_min(dir);
485
486         change = pinctl != alc_pin_mode_values[val];
487         if (change) {
488                 /* Set pin mode to that requested */
489                 snd_hda_codec_write_cache(codec, nid, 0,
490                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
491                                           alc_pin_mode_values[val]);
492
493                 /* Also enable the retasking pin's input/output as required 
494                  * for the requested pin mode.  Enum values of 2 or less are
495                  * input modes.
496                  *
497                  * Dynamically switching the input/output buffers probably
498                  * reduces noise slightly (particularly on input) so we'll
499                  * do it.  However, having both input and output buffers
500                  * enabled simultaneously doesn't seem to be problematic if
501                  * this turns out to be necessary in the future.
502                  */
503                 if (val <= 2) {
504                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
505                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
506                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
507                                                  HDA_AMP_MUTE, 0);
508                 } else {
509                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
510                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
511                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
512                                                  HDA_AMP_MUTE, 0);
513                 }
514         }
515         return change;
516 }
517
518 #define ALC_PIN_MODE(xname, nid, dir) \
519         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
520           .info = alc_pin_mode_info, \
521           .get = alc_pin_mode_get, \
522           .put = alc_pin_mode_put, \
523           .private_value = nid | (dir<<16) }
524
525 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
526  * together using a mask with more than one bit set.  This control is
527  * currently used only by the ALC260 test model.  At this stage they are not
528  * needed for any "production" models.
529  */
530 #ifdef CONFIG_SND_DEBUG
531 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
532
533 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
534                              struct snd_ctl_elem_value *ucontrol)
535 {
536         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
537         hda_nid_t nid = kcontrol->private_value & 0xffff;
538         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
539         long *valp = ucontrol->value.integer.value;
540         unsigned int val = snd_hda_codec_read(codec, nid, 0,
541                                               AC_VERB_GET_GPIO_DATA, 0x00);
542
543         *valp = (val & mask) != 0;
544         return 0;
545 }
546 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
547                              struct snd_ctl_elem_value *ucontrol)
548 {
549         signed int change;
550         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
551         hda_nid_t nid = kcontrol->private_value & 0xffff;
552         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
553         long val = *ucontrol->value.integer.value;
554         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
555                                                     AC_VERB_GET_GPIO_DATA,
556                                                     0x00);
557
558         /* Set/unset the masked GPIO bit(s) as needed */
559         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
560         if (val == 0)
561                 gpio_data &= ~mask;
562         else
563                 gpio_data |= mask;
564         snd_hda_codec_write_cache(codec, nid, 0,
565                                   AC_VERB_SET_GPIO_DATA, gpio_data);
566
567         return change;
568 }
569 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
570         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
571           .info = alc_gpio_data_info, \
572           .get = alc_gpio_data_get, \
573           .put = alc_gpio_data_put, \
574           .private_value = nid | (mask<<16) }
575 #endif   /* CONFIG_SND_DEBUG */
576
577 /* A switch control to allow the enabling of the digital IO pins on the
578  * ALC260.  This is incredibly simplistic; the intention of this control is
579  * to provide something in the test model allowing digital outputs to be
580  * identified if present.  If models are found which can utilise these
581  * outputs a more complete mixer control can be devised for those models if
582  * necessary.
583  */
584 #ifdef CONFIG_SND_DEBUG
585 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
586
587 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
588                               struct snd_ctl_elem_value *ucontrol)
589 {
590         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
591         hda_nid_t nid = kcontrol->private_value & 0xffff;
592         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
593         long *valp = ucontrol->value.integer.value;
594         unsigned int val = snd_hda_codec_read(codec, nid, 0,
595                                               AC_VERB_GET_DIGI_CONVERT_1, 0x00);
596
597         *valp = (val & mask) != 0;
598         return 0;
599 }
600 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
601                               struct snd_ctl_elem_value *ucontrol)
602 {
603         signed int change;
604         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
605         hda_nid_t nid = kcontrol->private_value & 0xffff;
606         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
607         long val = *ucontrol->value.integer.value;
608         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
609                                                     AC_VERB_GET_DIGI_CONVERT_1,
610                                                     0x00);
611
612         /* Set/unset the masked control bit(s) as needed */
613         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
614         if (val==0)
615                 ctrl_data &= ~mask;
616         else
617                 ctrl_data |= mask;
618         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
619                                   ctrl_data);
620
621         return change;
622 }
623 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
624         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
625           .info = alc_spdif_ctrl_info, \
626           .get = alc_spdif_ctrl_get, \
627           .put = alc_spdif_ctrl_put, \
628           .private_value = nid | (mask<<16) }
629 #endif   /* CONFIG_SND_DEBUG */
630
631 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
632  * Again, this is only used in the ALC26x test models to help identify when
633  * the EAPD line must be asserted for features to work.
634  */
635 #ifdef CONFIG_SND_DEBUG
636 #define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
637
638 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
639                               struct snd_ctl_elem_value *ucontrol)
640 {
641         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
642         hda_nid_t nid = kcontrol->private_value & 0xffff;
643         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
644         long *valp = ucontrol->value.integer.value;
645         unsigned int val = snd_hda_codec_read(codec, nid, 0,
646                                               AC_VERB_GET_EAPD_BTLENABLE, 0x00);
647
648         *valp = (val & mask) != 0;
649         return 0;
650 }
651
652 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
653                               struct snd_ctl_elem_value *ucontrol)
654 {
655         int change;
656         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
657         hda_nid_t nid = kcontrol->private_value & 0xffff;
658         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
659         long val = *ucontrol->value.integer.value;
660         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
661                                                     AC_VERB_GET_EAPD_BTLENABLE,
662                                                     0x00);
663
664         /* Set/unset the masked control bit(s) as needed */
665         change = (!val ? 0 : mask) != (ctrl_data & mask);
666         if (!val)
667                 ctrl_data &= ~mask;
668         else
669                 ctrl_data |= mask;
670         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
671                                   ctrl_data);
672
673         return change;
674 }
675
676 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
677         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
678           .info = alc_eapd_ctrl_info, \
679           .get = alc_eapd_ctrl_get, \
680           .put = alc_eapd_ctrl_put, \
681           .private_value = nid | (mask<<16) }
682 #endif   /* CONFIG_SND_DEBUG */
683
684 /*
685  * set up from the preset table
686  */
687 static void setup_preset(struct alc_spec *spec,
688                          const struct alc_config_preset *preset)
689 {
690         int i;
691
692         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
693                 spec->mixers[spec->num_mixers++] = preset->mixers[i];
694         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
695              i++)
696                 spec->init_verbs[spec->num_init_verbs++] =
697                         preset->init_verbs[i];
698         
699         spec->channel_mode = preset->channel_mode;
700         spec->num_channel_mode = preset->num_channel_mode;
701         spec->need_dac_fix = preset->need_dac_fix;
702
703         spec->multiout.max_channels = spec->channel_mode[0].channels;
704
705         spec->multiout.num_dacs = preset->num_dacs;
706         spec->multiout.dac_nids = preset->dac_nids;
707         spec->multiout.dig_out_nid = preset->dig_out_nid;
708         spec->multiout.hp_nid = preset->hp_nid;
709         
710         spec->num_mux_defs = preset->num_mux_defs;
711         if (!spec->num_mux_defs)
712                 spec->num_mux_defs = 1;
713         spec->input_mux = preset->input_mux;
714
715         spec->num_adc_nids = preset->num_adc_nids;
716         spec->adc_nids = preset->adc_nids;
717         spec->capsrc_nids = preset->capsrc_nids;
718         spec->dig_in_nid = preset->dig_in_nid;
719
720         spec->unsol_event = preset->unsol_event;
721         spec->init_hook = preset->init_hook;
722 #ifdef CONFIG_SND_HDA_POWER_SAVE
723         spec->loopback.amplist = preset->loopbacks;
724 #endif
725 }
726
727 /* Enable GPIO mask and set output */
728 static struct hda_verb alc_gpio1_init_verbs[] = {
729         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
730         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
731         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
732         { }
733 };
734
735 static struct hda_verb alc_gpio2_init_verbs[] = {
736         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
737         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
738         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
739         { }
740 };
741
742 static struct hda_verb alc_gpio3_init_verbs[] = {
743         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
744         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
745         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
746         { }
747 };
748
749 static void alc_sku_automute(struct hda_codec *codec)
750 {
751         struct alc_spec *spec = codec->spec;
752         unsigned int present;
753         unsigned int hp_nid = spec->autocfg.hp_pins[0];
754         unsigned int sp_nid = spec->autocfg.speaker_pins[0];
755
756         /* need to execute and sync at first */
757         snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
758         present = snd_hda_codec_read(codec, hp_nid, 0,
759                                      AC_VERB_GET_PIN_SENSE, 0);
760         spec->jack_present = (present & 0x80000000) != 0;
761         snd_hda_codec_write(codec, sp_nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
762                             spec->jack_present ? 0 : PIN_OUT);
763 }
764
765 /* unsolicited event for HP jack sensing */
766 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
767 {
768         if (codec->vendor_id == 0x10ec0880)
769                 res >>= 28;
770         else
771                 res >>= 26;
772         if (res != ALC880_HP_EVENT)
773                 return;
774
775         alc_sku_automute(codec);
776 }
777
778 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
779  *      31 ~ 16 :       Manufacture ID
780  *      15 ~ 8  :       SKU ID
781  *      7  ~ 0  :       Assembly ID
782  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
783  */
784 static void alc_subsystem_id(struct hda_codec *codec,
785                              unsigned int porta, unsigned int porte,
786                              unsigned int portd)
787 {
788         unsigned int ass, tmp, i;
789         unsigned nid;
790         struct alc_spec *spec = codec->spec;
791
792         ass = codec->subsystem_id & 0xffff;
793         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
794                 goto do_sku;
795
796         /*      
797          * 31~30        : port conetcivity
798          * 29~21        : reserve
799          * 20           : PCBEEP input
800          * 19~16        : Check sum (15:1)
801          * 15~1         : Custom
802          * 0            : override
803         */
804         nid = 0x1d;
805         if (codec->vendor_id == 0x10ec0260)
806                 nid = 0x17;
807         ass = snd_hda_codec_read(codec, nid, 0,
808                                  AC_VERB_GET_CONFIG_DEFAULT, 0);
809         if (!(ass & 1) && !(ass & 0x100000))
810                 return;
811         if ((ass >> 30) != 1)   /* no physical connection */
812                 return;
813
814         /* check sum */
815         tmp = 0;
816         for (i = 1; i < 16; i++) {
817                 if ((ass >> i) & 1)
818                         tmp++;
819         }
820         if (((ass >> 16) & 0xf) != tmp)
821                 return;
822 do_sku:
823         /*
824          * 0 : override
825          * 1 :  Swap Jack
826          * 2 : 0 --> Desktop, 1 --> Laptop
827          * 3~5 : External Amplifier control
828          * 7~6 : Reserved
829         */
830         tmp = (ass & 0x38) >> 3;        /* external Amp control */
831         switch (tmp) {
832         case 1:
833                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
834                 break;
835         case 3:
836                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
837                 break;
838         case 7:
839                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
840                 break;
841         case 5: /* set EAPD output high */
842                 switch (codec->vendor_id) {
843                 case 0x10ec0260:
844                         snd_hda_codec_write(codec, 0x0f, 0,
845                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
846                         snd_hda_codec_write(codec, 0x10, 0,
847                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
848                         break;
849                 case 0x10ec0262:
850                 case 0x10ec0267:
851                 case 0x10ec0268:
852                 case 0x10ec0269:
853                 case 0x10ec0862:
854                 case 0x10ec0662:        
855                         snd_hda_codec_write(codec, 0x14, 0,
856                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
857                         snd_hda_codec_write(codec, 0x15, 0,
858                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
859                         break;
860                 }
861                 switch (codec->vendor_id) {
862                 case 0x10ec0260:
863                         snd_hda_codec_write(codec, 0x1a, 0,
864                                             AC_VERB_SET_COEF_INDEX, 7);
865                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
866                                                  AC_VERB_GET_PROC_COEF, 0);
867                         snd_hda_codec_write(codec, 0x1a, 0,
868                                             AC_VERB_SET_COEF_INDEX, 7);
869                         snd_hda_codec_write(codec, 0x1a, 0,
870                                             AC_VERB_SET_PROC_COEF,
871                                             tmp | 0x2010);
872                         break;
873                 case 0x10ec0262:
874                 case 0x10ec0880:
875                 case 0x10ec0882:
876                 case 0x10ec0883:
877                 case 0x10ec0885:
878                 case 0x10ec0888:
879                         snd_hda_codec_write(codec, 0x20, 0,
880                                             AC_VERB_SET_COEF_INDEX, 7);
881                         tmp = snd_hda_codec_read(codec, 0x20, 0,
882                                                  AC_VERB_GET_PROC_COEF, 0);
883                         snd_hda_codec_write(codec, 0x20, 0,
884                                             AC_VERB_SET_COEF_INDEX, 7); 
885                         snd_hda_codec_write(codec, 0x20, 0,
886                                             AC_VERB_SET_PROC_COEF,
887                                             tmp | 0x2010);
888                         break;
889                 case 0x10ec0267:
890                 case 0x10ec0268:
891                         snd_hda_codec_write(codec, 0x20, 0,
892                                             AC_VERB_SET_COEF_INDEX, 7);
893                         tmp = snd_hda_codec_read(codec, 0x20, 0,
894                                                  AC_VERB_GET_PROC_COEF, 0);
895                         snd_hda_codec_write(codec, 0x20, 0,
896                                             AC_VERB_SET_COEF_INDEX, 7); 
897                         snd_hda_codec_write(codec, 0x20, 0,
898                                             AC_VERB_SET_PROC_COEF,
899                                             tmp | 0x3000);
900                         break;
901                 }
902         default:
903                 break;
904         }
905         
906         /* is laptop or Desktop and enable the function "Mute internal speaker
907          * when the external headphone out jack is plugged"
908          */
909         if (!(ass & 0x8000))
910                 return;
911         /*
912          * 10~8 : Jack location
913          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
914          * 14~13: Resvered
915          * 15   : 1 --> enable the function "Mute internal speaker
916          *              when the external headphone out jack is plugged"
917          */
918         if (!spec->autocfg.speaker_pins[0]) {
919                 if (spec->autocfg.line_out_pins[0])
920                         spec->autocfg.speaker_pins[0] =
921                                 spec->autocfg.line_out_pins[0];
922                 else
923                         return;
924         }
925
926         if (!spec->autocfg.hp_pins[0]) {
927                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
928                 if (tmp == 0)
929                         spec->autocfg.hp_pins[0] = porta;
930                 else if (tmp == 1)
931                         spec->autocfg.hp_pins[0] = porte;
932                 else if (tmp == 2)
933                         spec->autocfg.hp_pins[0] = portd;
934                 else
935                         return;
936         }
937
938         snd_hda_codec_write(codec, spec->autocfg.hp_pins[0], 0,
939                             AC_VERB_SET_UNSOLICITED_ENABLE,
940                             AC_USRSP_EN | ALC880_HP_EVENT);
941         spec->unsol_event = alc_sku_unsol_event;
942         spec->init_hook = alc_sku_automute;     
943 }
944
945 /*
946  * Fix-up pin default configurations
947  */
948
949 struct alc_pincfg {
950         hda_nid_t nid;
951         u32 val;
952 };
953
954 static void alc_fix_pincfg(struct hda_codec *codec,
955                            const struct snd_pci_quirk *quirk,
956                            const struct alc_pincfg **pinfix)
957 {
958         const struct alc_pincfg *cfg;
959
960         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
961         if (!quirk)
962                 return;
963
964         cfg = pinfix[quirk->value];
965         for (; cfg->nid; cfg++) {
966                 int i;
967                 u32 val = cfg->val;
968                 for (i = 0; i < 4; i++) {
969                         snd_hda_codec_write(codec, cfg->nid, 0,
970                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0 + i,
971                                     val & 0xff);
972                         val >>= 8;
973                 }
974         }
975 }
976
977 /*
978  * ALC880 3-stack model
979  *
980  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
981  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
982  *                 F-Mic = 0x1b, HP = 0x19
983  */
984
985 static hda_nid_t alc880_dac_nids[4] = {
986         /* front, rear, clfe, rear_surr */
987         0x02, 0x05, 0x04, 0x03
988 };
989
990 static hda_nid_t alc880_adc_nids[3] = {
991         /* ADC0-2 */
992         0x07, 0x08, 0x09,
993 };
994
995 /* The datasheet says the node 0x07 is connected from inputs,
996  * but it shows zero connection in the real implementation on some devices.
997  * Note: this is a 915GAV bug, fixed on 915GLV
998  */
999 static hda_nid_t alc880_adc_nids_alt[2] = {
1000         /* ADC1-2 */
1001         0x08, 0x09,
1002 };
1003
1004 #define ALC880_DIGOUT_NID       0x06
1005 #define ALC880_DIGIN_NID        0x0a
1006
1007 static struct hda_input_mux alc880_capture_source = {
1008         .num_items = 4,
1009         .items = {
1010                 { "Mic", 0x0 },
1011                 { "Front Mic", 0x3 },
1012                 { "Line", 0x2 },
1013                 { "CD", 0x4 },
1014         },
1015 };
1016
1017 /* channel source setting (2/6 channel selection for 3-stack) */
1018 /* 2ch mode */
1019 static struct hda_verb alc880_threestack_ch2_init[] = {
1020         /* set line-in to input, mute it */
1021         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1022         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1023         /* set mic-in to input vref 80%, mute it */
1024         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1025         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1026         { } /* end */
1027 };
1028
1029 /* 6ch mode */
1030 static struct hda_verb alc880_threestack_ch6_init[] = {
1031         /* set line-in to output, unmute it */
1032         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1033         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1034         /* set mic-in to output, unmute it */
1035         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1036         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1037         { } /* end */
1038 };
1039
1040 static struct hda_channel_mode alc880_threestack_modes[2] = {
1041         { 2, alc880_threestack_ch2_init },
1042         { 6, alc880_threestack_ch6_init },
1043 };
1044
1045 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1046         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1047         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1048         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1049         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1050         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1051         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1052         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1053         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1054         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1055         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1056         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1057         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1058         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1059         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1060         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
1061         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
1062         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1063         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1064         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
1065         {
1066                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1067                 .name = "Channel Mode",
1068                 .info = alc_ch_mode_info,
1069                 .get = alc_ch_mode_get,
1070                 .put = alc_ch_mode_put,
1071         },
1072         { } /* end */
1073 };
1074
1075 /* capture mixer elements */
1076 static struct snd_kcontrol_new alc880_capture_mixer[] = {
1077         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
1078         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
1079         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
1080         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
1081         HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
1082         HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
1083         {
1084                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1085                 /* The multiple "Capture Source" controls confuse alsamixer
1086                  * So call somewhat different..
1087                  */
1088                 /* .name = "Capture Source", */
1089                 .name = "Input Source",
1090                 .count = 3,
1091                 .info = alc_mux_enum_info,
1092                 .get = alc_mux_enum_get,
1093                 .put = alc_mux_enum_put,
1094         },
1095         { } /* end */
1096 };
1097
1098 /* capture mixer elements (in case NID 0x07 not available) */
1099 static struct snd_kcontrol_new alc880_capture_alt_mixer[] = {
1100         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1101         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1102         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
1103         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
1104         {
1105                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1106                 /* The multiple "Capture Source" controls confuse alsamixer
1107                  * So call somewhat different..
1108                  */
1109                 /* .name = "Capture Source", */
1110                 .name = "Input Source",
1111                 .count = 2,
1112                 .info = alc_mux_enum_info,
1113                 .get = alc_mux_enum_get,
1114                 .put = alc_mux_enum_put,
1115         },
1116         { } /* end */
1117 };
1118
1119
1120
1121 /*
1122  * ALC880 5-stack model
1123  *
1124  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
1125  *      Side = 0x02 (0xd)
1126  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
1127  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
1128  */
1129
1130 /* additional mixers to alc880_three_stack_mixer */
1131 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
1132         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1133         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
1134         { } /* end */
1135 };
1136
1137 /* channel source setting (6/8 channel selection for 5-stack) */
1138 /* 6ch mode */
1139 static struct hda_verb alc880_fivestack_ch6_init[] = {
1140         /* set line-in to input, mute it */
1141         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1142         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1143         { } /* end */
1144 };
1145
1146 /* 8ch mode */
1147 static struct hda_verb alc880_fivestack_ch8_init[] = {
1148         /* set line-in to output, unmute it */
1149         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1150         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1151         { } /* end */
1152 };
1153
1154 static struct hda_channel_mode alc880_fivestack_modes[2] = {
1155         { 6, alc880_fivestack_ch6_init },
1156         { 8, alc880_fivestack_ch8_init },
1157 };
1158
1159
1160 /*
1161  * ALC880 6-stack model
1162  *
1163  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
1164  *      Side = 0x05 (0x0f)
1165  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
1166  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
1167  */
1168
1169 static hda_nid_t alc880_6st_dac_nids[4] = {
1170         /* front, rear, clfe, rear_surr */
1171         0x02, 0x03, 0x04, 0x05
1172 };
1173
1174 static struct hda_input_mux alc880_6stack_capture_source = {
1175         .num_items = 4,
1176         .items = {
1177                 { "Mic", 0x0 },
1178                 { "Front Mic", 0x1 },
1179                 { "Line", 0x2 },
1180                 { "CD", 0x4 },
1181         },
1182 };
1183
1184 /* fixed 8-channels */
1185 static struct hda_channel_mode alc880_sixstack_modes[1] = {
1186         { 8, NULL },
1187 };
1188
1189 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
1190         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1191         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1192         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1193         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1194         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1195         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1196         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1197         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1198         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1199         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1200         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1201         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1202         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1203         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1204         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1205         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1206         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1207         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1208         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1209         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1210         {
1211                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1212                 .name = "Channel Mode",
1213                 .info = alc_ch_mode_info,
1214                 .get = alc_ch_mode_get,
1215                 .put = alc_ch_mode_put,
1216         },
1217         { } /* end */
1218 };
1219
1220
1221 /*
1222  * ALC880 W810 model
1223  *
1224  * W810 has rear IO for:
1225  * Front (DAC 02)
1226  * Surround (DAC 03)
1227  * Center/LFE (DAC 04)
1228  * Digital out (06)
1229  *
1230  * The system also has a pair of internal speakers, and a headphone jack.
1231  * These are both connected to Line2 on the codec, hence to DAC 02.
1232  * 
1233  * There is a variable resistor to control the speaker or headphone
1234  * volume. This is a hardware-only device without a software API.
1235  *
1236  * Plugging headphones in will disable the internal speakers. This is
1237  * implemented in hardware, not via the driver using jack sense. In
1238  * a similar fashion, plugging into the rear socket marked "front" will
1239  * disable both the speakers and headphones.
1240  *
1241  * For input, there's a microphone jack, and an "audio in" jack.
1242  * These may not do anything useful with this driver yet, because I
1243  * haven't setup any initialization verbs for these yet...
1244  */
1245
1246 static hda_nid_t alc880_w810_dac_nids[3] = {
1247         /* front, rear/surround, clfe */
1248         0x02, 0x03, 0x04
1249 };
1250
1251 /* fixed 6 channels */
1252 static struct hda_channel_mode alc880_w810_modes[1] = {
1253         { 6, NULL }
1254 };
1255
1256 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
1257 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
1258         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1259         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1260         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1261         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1262         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1263         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1264         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1265         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1266         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1267         { } /* end */
1268 };
1269
1270
1271 /*
1272  * Z710V model
1273  *
1274  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
1275  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
1276  *                 Line = 0x1a
1277  */
1278
1279 static hda_nid_t alc880_z71v_dac_nids[1] = {
1280         0x02
1281 };
1282 #define ALC880_Z71V_HP_DAC      0x03
1283
1284 /* fixed 2 channels */
1285 static struct hda_channel_mode alc880_2_jack_modes[1] = {
1286         { 2, NULL }
1287 };
1288
1289 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
1290         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1291         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1292         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1293         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
1294         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1295         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1296         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1297         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1298         { } /* end */
1299 };
1300
1301
1302 /*
1303  * ALC880 F1734 model
1304  *
1305  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
1306  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
1307  */
1308
1309 static hda_nid_t alc880_f1734_dac_nids[1] = {
1310         0x03
1311 };
1312 #define ALC880_F1734_HP_DAC     0x02
1313
1314 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
1315         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1316         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1317         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1318         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1319         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1320         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1321         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1322         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1323         { } /* end */
1324 };
1325
1326 static struct hda_input_mux alc880_f1734_capture_source = {
1327         .num_items = 2,
1328         .items = {
1329                 { "Mic", 0x1 },
1330                 { "CD", 0x4 },
1331         },
1332 };
1333
1334
1335 /*
1336  * ALC880 ASUS model
1337  *
1338  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1339  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1340  *  Mic = 0x18, Line = 0x1a
1341  */
1342
1343 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
1344 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
1345
1346 static struct snd_kcontrol_new alc880_asus_mixer[] = {
1347         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1348         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1349         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1350         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1351         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1352         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1353         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1354         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1355         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1356         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1357         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1358         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1359         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1360         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1361         {
1362                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1363                 .name = "Channel Mode",
1364                 .info = alc_ch_mode_info,
1365                 .get = alc_ch_mode_get,
1366                 .put = alc_ch_mode_put,
1367         },
1368         { } /* end */
1369 };
1370
1371 /*
1372  * ALC880 ASUS W1V model
1373  *
1374  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1375  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1376  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
1377  */
1378
1379 /* additional mixers to alc880_asus_mixer */
1380 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
1381         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
1382         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
1383         { } /* end */
1384 };
1385
1386 /* additional mixers to alc880_asus_mixer */
1387 static struct snd_kcontrol_new alc880_pcbeep_mixer[] = {
1388         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1389         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1390         { } /* end */
1391 };
1392
1393 /* TCL S700 */
1394 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
1395         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1396         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1397         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1398         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
1399         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
1400         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
1401         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
1402         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1403         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1404         {
1405                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1406                 /* The multiple "Capture Source" controls confuse alsamixer
1407                  * So call somewhat different..
1408                  */
1409                 /* .name = "Capture Source", */
1410                 .name = "Input Source",
1411                 .count = 1,
1412                 .info = alc_mux_enum_info,
1413                 .get = alc_mux_enum_get,
1414                 .put = alc_mux_enum_put,
1415         },
1416         { } /* end */
1417 };
1418
1419 /* Uniwill */
1420 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
1421         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1422         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1423         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1424         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1425         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1426         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1427         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1428         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1429         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1430         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1431         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1432         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1433         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1434         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1435         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1436         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1437         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1438         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1439         {
1440                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1441                 .name = "Channel Mode",
1442                 .info = alc_ch_mode_info,
1443                 .get = alc_ch_mode_get,
1444                 .put = alc_ch_mode_put,
1445         },
1446         { } /* end */
1447 };
1448
1449 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
1450         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1451         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1452         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1453         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1454         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1455         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1456         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1457         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1458         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1459         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1460         { } /* end */
1461 };
1462
1463 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
1464         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1465         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1466         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1467         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1468         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1469         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1470         { } /* end */
1471 };
1472
1473 /*
1474  * virtual master controls
1475  */
1476
1477 /*
1478  * slave controls for virtual master
1479  */
1480 static const char *alc_slave_vols[] = {
1481         "Front Playback Volume",
1482         "Surround Playback Volume",
1483         "Center Playback Volume",
1484         "LFE Playback Volume",
1485         "Side Playback Volume",
1486         "Headphone Playback Volume",
1487         "Speaker Playback Volume",
1488         "Mono Playback Volume",
1489         "Line-Out Playback Volume",
1490         NULL,
1491 };
1492
1493 static const char *alc_slave_sws[] = {
1494         "Front Playback Switch",
1495         "Surround Playback Switch",
1496         "Center Playback Switch",
1497         "LFE Playback Switch",
1498         "Side Playback Switch",
1499         "Headphone Playback Switch",
1500         "Speaker Playback Switch",
1501         "Mono Playback Switch",
1502         "IEC958 Playback Switch",
1503         NULL,
1504 };
1505
1506 /*
1507  * build control elements
1508  */
1509 static int alc_build_controls(struct hda_codec *codec)
1510 {
1511         struct alc_spec *spec = codec->spec;
1512         int err;
1513         int i;
1514
1515         for (i = 0; i < spec->num_mixers; i++) {
1516                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1517                 if (err < 0)
1518                         return err;
1519         }
1520
1521         if (spec->multiout.dig_out_nid) {
1522                 err = snd_hda_create_spdif_out_ctls(codec,
1523                                                     spec->multiout.dig_out_nid);
1524                 if (err < 0)
1525                         return err;
1526                 err = snd_hda_create_spdif_share_sw(codec,
1527                                                     &spec->multiout);
1528                 if (err < 0)
1529                         return err;
1530                 spec->multiout.share_spdif = 1;
1531         }
1532         if (spec->dig_in_nid) {
1533                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1534                 if (err < 0)
1535                         return err;
1536         }
1537
1538         /* if we have no master control, let's create it */
1539         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1540                 unsigned int vmaster_tlv[4];
1541                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1542                                         HDA_OUTPUT, vmaster_tlv);
1543                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1544                                           vmaster_tlv, alc_slave_vols);
1545                 if (err < 0)
1546                         return err;
1547         }
1548         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1549                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1550                                           NULL, alc_slave_sws);
1551                 if (err < 0)
1552                         return err;
1553         }
1554
1555         return 0;
1556 }
1557
1558
1559 /*
1560  * initialize the codec volumes, etc
1561  */
1562
1563 /*
1564  * generic initialization of ADC, input mixers and output mixers
1565  */
1566 static struct hda_verb alc880_volume_init_verbs[] = {
1567         /*
1568          * Unmute ADC0-2 and set the default input to mic-in
1569          */
1570         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
1571         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1572         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
1573         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1574         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
1575         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1576
1577         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1578          * mixer widget
1579          * Note: PASD motherboards uses the Line In 2 as the input for front
1580          * panel mic (mic 2)
1581          */
1582         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
1583         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1584         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1585         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
1586         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
1587         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
1588         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
1589         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
1590
1591         /*
1592          * Set up output mixers (0x0c - 0x0f)
1593          */
1594         /* set vol=0 to output mixers */
1595         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1596         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1597         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1598         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1599         /* set up input amps for analog loopback */
1600         /* Amp Indices: DAC = 0, mixer = 1 */
1601         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1602         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1603         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1604         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1605         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1606         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1607         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1608         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1609
1610         { }
1611 };
1612
1613 /*
1614  * 3-stack pin configuration:
1615  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
1616  */
1617 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
1618         /*
1619          * preset connection lists of input pins
1620          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1621          */
1622         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
1623         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1624         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
1625
1626         /*
1627          * Set pin mode and muting
1628          */
1629         /* set front pin widgets 0x14 for output */
1630         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1631         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1632         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1633         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1634         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1635         /* Mic2 (as headphone out) for HP output */
1636         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1637         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1638         /* Line In pin widget for input */
1639         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1640         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1641         /* Line2 (as front mic) pin widget for input and vref at 80% */
1642         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1643         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1644         /* CD pin widget for input */
1645         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1646
1647         { }
1648 };
1649
1650 /*
1651  * 5-stack pin configuration:
1652  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
1653  * line-in/side = 0x1a, f-mic = 0x1b
1654  */
1655 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
1656         /*
1657          * preset connection lists of input pins
1658          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1659          */
1660         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1661         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
1662
1663         /*
1664          * Set pin mode and muting
1665          */
1666         /* set pin widgets 0x14-0x17 for output */
1667         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1668         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1669         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1670         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1671         /* unmute pins for output (no gain on this amp) */
1672         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1673         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1674         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1675         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1676
1677         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1678         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1679         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1680         /* Mic2 (as headphone out) for HP output */
1681         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1682         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1683         /* Line In pin widget for input */
1684         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1685         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1686         /* Line2 (as front mic) pin widget for input and vref at 80% */
1687         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1688         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1689         /* CD pin widget for input */
1690         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1691
1692         { }
1693 };
1694
1695 /*
1696  * W810 pin configuration:
1697  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
1698  */
1699 static struct hda_verb alc880_pin_w810_init_verbs[] = {
1700         /* hphone/speaker input selector: front DAC */
1701         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
1702
1703         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1704         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1705         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1706         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1707         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1708         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1709
1710         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1711         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1712
1713         { }
1714 };
1715
1716 /*
1717  * Z71V pin configuration:
1718  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
1719  */
1720 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
1721         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1722         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1723         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1724         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1725
1726         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1727         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1728         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1729         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1730
1731         { }
1732 };
1733
1734 /*
1735  * 6-stack pin configuration:
1736  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
1737  * f-mic = 0x19, line = 0x1a, HP = 0x1b
1738  */
1739 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
1740         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1741
1742         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1743         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1744         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1745         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1746         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1747         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1748         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1749         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1750
1751         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1752         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1753         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1754         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1755         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1756         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1757         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1758         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1759         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1760         
1761         { }
1762 };
1763
1764 /*
1765  * Uniwill pin configuration:
1766  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
1767  * line = 0x1a
1768  */
1769 static struct hda_verb alc880_uniwill_init_verbs[] = {
1770         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1771
1772         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1773         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1774         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1775         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1776         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1777         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1778         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1779         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1780         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1781         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1782         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1783         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1784         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1785         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1786
1787         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1788         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1789         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1790         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1791         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1792         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1793         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
1794         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
1795         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1796
1797         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
1798         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
1799
1800         { }
1801 };
1802
1803 /*
1804 * Uniwill P53
1805 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19, 
1806  */
1807 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
1808         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1809
1810         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1811         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1812         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1813         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1814         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1815         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1816         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1817         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1818         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1819         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1820         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1821         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1822
1823         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1824         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1825         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1826         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1827         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1828         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1829
1830         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
1831         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
1832
1833         { }
1834 };
1835
1836 static struct hda_verb alc880_beep_init_verbs[] = {
1837         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
1838         { }
1839 };
1840
1841 /* toggle speaker-output according to the hp-jack state */
1842 static void alc880_uniwill_hp_automute(struct hda_codec *codec)
1843 {
1844         unsigned int present;
1845         unsigned char bits;
1846
1847         present = snd_hda_codec_read(codec, 0x14, 0,
1848                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1849         bits = present ? HDA_AMP_MUTE : 0;
1850         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
1851                                  HDA_AMP_MUTE, bits);
1852         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
1853                                  HDA_AMP_MUTE, bits);
1854 }
1855
1856 /* auto-toggle front mic */
1857 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
1858 {
1859         unsigned int present;
1860         unsigned char bits;
1861
1862         present = snd_hda_codec_read(codec, 0x18, 0,
1863                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1864         bits = present ? HDA_AMP_MUTE : 0;
1865         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
1866 }
1867
1868 static void alc880_uniwill_automute(struct hda_codec *codec)
1869 {
1870         alc880_uniwill_hp_automute(codec);
1871         alc880_uniwill_mic_automute(codec);
1872 }
1873
1874 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
1875                                        unsigned int res)
1876 {
1877         /* Looks like the unsol event is incompatible with the standard
1878          * definition.  4bit tag is placed at 28 bit!
1879          */
1880         switch (res >> 28) {
1881         case ALC880_HP_EVENT:
1882                 alc880_uniwill_hp_automute(codec);
1883                 break;
1884         case ALC880_MIC_EVENT:
1885                 alc880_uniwill_mic_automute(codec);
1886                 break;
1887         }
1888 }
1889
1890 static void alc880_uniwill_p53_hp_automute(struct hda_codec *codec)
1891 {
1892         unsigned int present;
1893         unsigned char bits;
1894
1895         present = snd_hda_codec_read(codec, 0x14, 0,
1896                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1897         bits = present ? HDA_AMP_MUTE : 0;
1898         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, HDA_AMP_MUTE, bits);
1899 }
1900
1901 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
1902 {
1903         unsigned int present;
1904         
1905         present = snd_hda_codec_read(codec, 0x21, 0,
1906                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
1907         present &= HDA_AMP_VOLMASK;
1908         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
1909                                  HDA_AMP_VOLMASK, present);
1910         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
1911                                  HDA_AMP_VOLMASK, present);
1912 }
1913
1914 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
1915                                            unsigned int res)
1916 {
1917         /* Looks like the unsol event is incompatible with the standard
1918          * definition.  4bit tag is placed at 28 bit!
1919          */
1920         if ((res >> 28) == ALC880_HP_EVENT)
1921                 alc880_uniwill_p53_hp_automute(codec);
1922         if ((res >> 28) == ALC880_DCVOL_EVENT)
1923                 alc880_uniwill_p53_dcvol_automute(codec);
1924 }
1925
1926 /*
1927  * F1734 pin configuration:
1928  * HP = 0x14, speaker-out = 0x15, mic = 0x18
1929  */
1930 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
1931         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
1932         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
1933         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
1934         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
1935         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
1936
1937         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1938         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1939         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1940         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1941
1942         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1943         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1944         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
1945         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1946         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1947         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1948         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1949         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1950         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1951
1952         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
1953         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
1954
1955         { }
1956 };
1957
1958 /*
1959  * ASUS pin configuration:
1960  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
1961  */
1962 static struct hda_verb alc880_pin_asus_init_verbs[] = {
1963         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
1964         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
1965         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
1966         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
1967
1968         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1969         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1970         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1971         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1972         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1973         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1974         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1975         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1976
1977         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1978         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1979         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1980         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1981         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1982         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1983         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1984         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1985         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1986         
1987         { }
1988 };
1989
1990 /* Enable GPIO mask and set output */
1991 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
1992 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
1993
1994 /* Clevo m520g init */
1995 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
1996         /* headphone output */
1997         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
1998         /* line-out */
1999         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2000         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2001         /* Line-in */
2002         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2003         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2004         /* CD */
2005         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2006         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2007         /* Mic1 (rear panel) */
2008         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2009         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2010         /* Mic2 (front panel) */
2011         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2012         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2013         /* headphone */
2014         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2015         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2016         /* change to EAPD mode */
2017         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2018         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2019
2020         { }
2021 };
2022
2023 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
2024         /* change to EAPD mode */
2025         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2026         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2027
2028         /* Headphone output */
2029         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2030         /* Front output*/
2031         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2032         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2033
2034         /* Line In pin widget for input */
2035         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2036         /* CD pin widget for input */
2037         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2038         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2039         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2040
2041         /* change to EAPD mode */
2042         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2043         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
2044
2045         { }
2046 };
2047
2048 /*
2049  * LG m1 express dual
2050  *
2051  * Pin assignment:
2052  *   Rear Line-In/Out (blue): 0x14
2053  *   Build-in Mic-In: 0x15
2054  *   Speaker-out: 0x17
2055  *   HP-Out (green): 0x1b
2056  *   Mic-In/Out (red): 0x19
2057  *   SPDIF-Out: 0x1e
2058  */
2059
2060 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
2061 static hda_nid_t alc880_lg_dac_nids[3] = {
2062         0x05, 0x02, 0x03
2063 };
2064
2065 /* seems analog CD is not working */
2066 static struct hda_input_mux alc880_lg_capture_source = {
2067         .num_items = 3,
2068         .items = {
2069                 { "Mic", 0x1 },
2070                 { "Line", 0x5 },
2071                 { "Internal Mic", 0x6 },
2072         },
2073 };
2074
2075 /* 2,4,6 channel modes */
2076 static struct hda_verb alc880_lg_ch2_init[] = {
2077         /* set line-in and mic-in to input */
2078         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2079         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2080         { }
2081 };
2082
2083 static struct hda_verb alc880_lg_ch4_init[] = {
2084         /* set line-in to out and mic-in to input */
2085         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2086         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2087         { }
2088 };
2089
2090 static struct hda_verb alc880_lg_ch6_init[] = {
2091         /* set line-in and mic-in to output */
2092         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2093         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2094         { }
2095 };
2096
2097 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
2098         { 2, alc880_lg_ch2_init },
2099         { 4, alc880_lg_ch4_init },
2100         { 6, alc880_lg_ch6_init },
2101 };
2102
2103 static struct snd_kcontrol_new alc880_lg_mixer[] = {
2104         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2105         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
2106         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2107         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
2108         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
2109         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
2110         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
2111         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
2112         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2113         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2114         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
2115         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
2116         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
2117         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
2118         {
2119                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2120                 .name = "Channel Mode",
2121                 .info = alc_ch_mode_info,
2122                 .get = alc_ch_mode_get,
2123                 .put = alc_ch_mode_put,
2124         },
2125         { } /* end */
2126 };
2127
2128 static struct hda_verb alc880_lg_init_verbs[] = {
2129         /* set capture source to mic-in */
2130         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2131         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2132         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2133         /* mute all amp mixer inputs */
2134         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
2135         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2136         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2137         /* line-in to input */
2138         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2139         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2140         /* built-in mic */
2141         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2142         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2143         /* speaker-out */
2144         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2145         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2146         /* mic-in to input */
2147         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2148         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2149         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2150         /* HP-out */
2151         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
2152         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2153         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2154         /* jack sense */
2155         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2156         { }
2157 };
2158
2159 /* toggle speaker-output according to the hp-jack state */
2160 static void alc880_lg_automute(struct hda_codec *codec)
2161 {
2162         unsigned int present;
2163         unsigned char bits;
2164
2165         present = snd_hda_codec_read(codec, 0x1b, 0,
2166                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2167         bits = present ? HDA_AMP_MUTE : 0;
2168         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
2169                                  HDA_AMP_MUTE, bits);
2170 }
2171
2172 static void alc880_lg_unsol_event(struct hda_codec *codec, unsigned int res)
2173 {
2174         /* Looks like the unsol event is incompatible with the standard
2175          * definition.  4bit tag is placed at 28 bit!
2176          */
2177         if ((res >> 28) == 0x01)
2178                 alc880_lg_automute(codec);
2179 }
2180
2181 /*
2182  * LG LW20
2183  *
2184  * Pin assignment:
2185  *   Speaker-out: 0x14
2186  *   Mic-In: 0x18
2187  *   Built-in Mic-In: 0x19
2188  *   Line-In: 0x1b
2189  *   HP-Out: 0x1a
2190  *   SPDIF-Out: 0x1e
2191  */
2192
2193 static struct hda_input_mux alc880_lg_lw_capture_source = {
2194         .num_items = 3,
2195         .items = {
2196                 { "Mic", 0x0 },
2197                 { "Internal Mic", 0x1 },
2198                 { "Line In", 0x2 },
2199         },
2200 };
2201
2202 #define alc880_lg_lw_modes alc880_threestack_modes
2203
2204 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
2205         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2206         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2207         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2208         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
2209         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2210         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2211         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2212         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2213         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2214         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2215         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2216         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2217         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
2218         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
2219         {
2220                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2221                 .name = "Channel Mode",
2222                 .info = alc_ch_mode_info,
2223                 .get = alc_ch_mode_get,
2224                 .put = alc_ch_mode_put,
2225         },
2226         { } /* end */
2227 };
2228
2229 static struct hda_verb alc880_lg_lw_init_verbs[] = {
2230         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2231         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2232         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2233
2234         /* set capture source to mic-in */
2235         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2236         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2237         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2238         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2239         /* speaker-out */
2240         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2241         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2242         /* HP-out */
2243         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2244         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2245         /* mic-in to input */
2246         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2247         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2248         /* built-in mic */
2249         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2250         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2251         /* jack sense */
2252         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2253         { }
2254 };
2255
2256 /* toggle speaker-output according to the hp-jack state */
2257 static void alc880_lg_lw_automute(struct hda_codec *codec)
2258 {
2259         unsigned int present;
2260         unsigned char bits;
2261
2262         present = snd_hda_codec_read(codec, 0x1b, 0,
2263                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2264         bits = present ? HDA_AMP_MUTE : 0;
2265         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
2266                                  HDA_AMP_MUTE, bits);
2267 }
2268
2269 static void alc880_lg_lw_unsol_event(struct hda_codec *codec, unsigned int res)
2270 {
2271         /* Looks like the unsol event is incompatible with the standard
2272          * definition.  4bit tag is placed at 28 bit!
2273          */
2274         if ((res >> 28) == 0x01)
2275                 alc880_lg_lw_automute(codec);
2276 }
2277
2278 #ifdef CONFIG_SND_HDA_POWER_SAVE
2279 static struct hda_amp_list alc880_loopbacks[] = {
2280         { 0x0b, HDA_INPUT, 0 },
2281         { 0x0b, HDA_INPUT, 1 },
2282         { 0x0b, HDA_INPUT, 2 },
2283         { 0x0b, HDA_INPUT, 3 },
2284         { 0x0b, HDA_INPUT, 4 },
2285         { } /* end */
2286 };
2287
2288 static struct hda_amp_list alc880_lg_loopbacks[] = {
2289         { 0x0b, HDA_INPUT, 1 },
2290         { 0x0b, HDA_INPUT, 6 },
2291         { 0x0b, HDA_INPUT, 7 },
2292         { } /* end */
2293 };
2294 #endif
2295
2296 /*
2297  * Common callbacks
2298  */
2299
2300 static int alc_init(struct hda_codec *codec)
2301 {
2302         struct alc_spec *spec = codec->spec;
2303         unsigned int i;
2304
2305         for (i = 0; i < spec->num_init_verbs; i++)
2306                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2307
2308         if (spec->init_hook)
2309                 spec->init_hook(codec);
2310
2311         return 0;
2312 }
2313
2314 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2315 {
2316         struct alc_spec *spec = codec->spec;
2317
2318         if (spec->unsol_event)
2319                 spec->unsol_event(codec, res);
2320 }
2321
2322 #ifdef CONFIG_SND_HDA_POWER_SAVE
2323 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2324 {
2325         struct alc_spec *spec = codec->spec;
2326         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2327 }
2328 #endif
2329
2330 /*
2331  * Analog playback callbacks
2332  */
2333 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
2334                                     struct hda_codec *codec,
2335                                     struct snd_pcm_substream *substream)
2336 {
2337         struct alc_spec *spec = codec->spec;
2338         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2339                                              hinfo);
2340 }
2341
2342 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2343                                        struct hda_codec *codec,
2344                                        unsigned int stream_tag,
2345                                        unsigned int format,
2346                                        struct snd_pcm_substream *substream)
2347 {
2348         struct alc_spec *spec = codec->spec;
2349         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2350                                                 stream_tag, format, substream);
2351 }
2352
2353 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2354                                        struct hda_codec *codec,
2355                                        struct snd_pcm_substream *substream)
2356 {
2357         struct alc_spec *spec = codec->spec;
2358         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2359 }
2360
2361 /*
2362  * Digital out
2363  */
2364 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2365                                         struct hda_codec *codec,
2366                                         struct snd_pcm_substream *substream)
2367 {
2368         struct alc_spec *spec = codec->spec;
2369         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2370 }
2371
2372 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2373                                            struct hda_codec *codec,
2374                                            unsigned int stream_tag,
2375                                            unsigned int format,
2376                                            struct snd_pcm_substream *substream)
2377 {
2378         struct alc_spec *spec = codec->spec;
2379         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2380                                              stream_tag, format, substream);
2381 }
2382
2383 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2384                                          struct hda_codec *codec,
2385                                          struct snd_pcm_substream *substream)
2386 {
2387         struct alc_spec *spec = codec->spec;
2388         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2389 }
2390
2391 /*
2392  * Analog capture
2393  */
2394 static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2395                                       struct hda_codec *codec,
2396                                       unsigned int stream_tag,
2397                                       unsigned int format,
2398                                       struct snd_pcm_substream *substream)
2399 {
2400         struct alc_spec *spec = codec->spec;
2401
2402         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2403                                    stream_tag, 0, format);
2404         return 0;
2405 }
2406
2407 static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2408                                       struct hda_codec *codec,
2409                                       struct snd_pcm_substream *substream)
2410 {
2411         struct alc_spec *spec = codec->spec;
2412
2413         snd_hda_codec_cleanup_stream(codec,
2414                                      spec->adc_nids[substream->number + 1]);
2415         return 0;
2416 }
2417
2418
2419 /*
2420  */
2421 static struct hda_pcm_stream alc880_pcm_analog_playback = {
2422         .substreams = 1,
2423         .channels_min = 2,
2424         .channels_max = 8,
2425         /* NID is set in alc_build_pcms */
2426         .ops = {
2427                 .open = alc880_playback_pcm_open,
2428                 .prepare = alc880_playback_pcm_prepare,
2429                 .cleanup = alc880_playback_pcm_cleanup
2430         },
2431 };
2432
2433 static struct hda_pcm_stream alc880_pcm_analog_capture = {
2434         .substreams = 1,
2435         .channels_min = 2,
2436         .channels_max = 2,
2437         /* NID is set in alc_build_pcms */
2438 };
2439
2440 static struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
2441         .substreams = 1,
2442         .channels_min = 2,
2443         .channels_max = 2,
2444         /* NID is set in alc_build_pcms */
2445 };
2446
2447 static struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
2448         .substreams = 2, /* can be overridden */
2449         .channels_min = 2,
2450         .channels_max = 2,
2451         /* NID is set in alc_build_pcms */
2452         .ops = {
2453                 .prepare = alc880_alt_capture_pcm_prepare,
2454                 .cleanup = alc880_alt_capture_pcm_cleanup
2455         },
2456 };
2457
2458 static struct hda_pcm_stream alc880_pcm_digital_playback = {
2459         .substreams = 1,
2460         .channels_min = 2,
2461         .channels_max = 2,
2462         /* NID is set in alc_build_pcms */
2463         .ops = {
2464                 .open = alc880_dig_playback_pcm_open,
2465                 .close = alc880_dig_playback_pcm_close,
2466                 .prepare = alc880_dig_playback_pcm_prepare
2467         },
2468 };
2469
2470 static struct hda_pcm_stream alc880_pcm_digital_capture = {
2471         .substreams = 1,
2472         .channels_min = 2,
2473         .channels_max = 2,
2474         /* NID is set in alc_build_pcms */
2475 };
2476
2477 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2478 static struct hda_pcm_stream alc_pcm_null_stream = {
2479         .substreams = 0,
2480         .channels_min = 0,
2481         .channels_max = 0,
2482 };
2483
2484 static int alc_build_pcms(struct hda_codec *codec)
2485 {
2486         struct alc_spec *spec = codec->spec;
2487         struct hda_pcm *info = spec->pcm_rec;
2488         int i;
2489
2490         codec->num_pcms = 1;
2491         codec->pcm_info = info;
2492
2493         info->name = spec->stream_name_analog;
2494         if (spec->stream_analog_playback) {
2495                 snd_assert(spec->multiout.dac_nids, return -EINVAL);
2496                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
2497                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2498         }
2499         if (spec->stream_analog_capture) {
2500                 snd_assert(spec->adc_nids, return -EINVAL);
2501                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
2502                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2503         }
2504
2505         if (spec->channel_mode) {
2506                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2507                 for (i = 0; i < spec->num_channel_mode; i++) {
2508                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2509                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2510                         }
2511                 }
2512         }
2513
2514         /* SPDIF for stream index #1 */
2515         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2516                 codec->num_pcms = 2;
2517                 info = spec->pcm_rec + 1;
2518                 info->name = spec->stream_name_digital;
2519                 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2520                 if (spec->multiout.dig_out_nid &&
2521                     spec->stream_digital_playback) {
2522                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
2523                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2524                 }
2525                 if (spec->dig_in_nid &&
2526                     spec->stream_digital_capture) {
2527                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
2528                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2529                 }
2530         }
2531
2532         /* If the use of more than one ADC is requested for the current
2533          * model, configure a second analog capture-only PCM.
2534          */
2535         /* Additional Analaog capture for index #2 */
2536         if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
2537             (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
2538                 codec->num_pcms = 3;
2539                 info = spec->pcm_rec + 2;
2540                 info->name = spec->stream_name_analog;
2541                 if (spec->alt_dac_nid) {
2542                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2543                                 *spec->stream_analog_alt_playback;
2544                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2545                                 spec->alt_dac_nid;
2546                 } else {
2547                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2548                                 alc_pcm_null_stream;
2549                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2550                 }
2551                 if (spec->num_adc_nids > 1) {
2552                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2553                                 *spec->stream_analog_alt_capture;
2554                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2555                                 spec->adc_nids[1];
2556                         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2557                                 spec->num_adc_nids - 1;
2558                 } else {
2559                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2560                                 alc_pcm_null_stream;
2561                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
2562                 }
2563         }
2564
2565         return 0;
2566 }
2567
2568 static void alc_free(struct hda_codec *codec)
2569 {
2570         struct alc_spec *spec = codec->spec;
2571         unsigned int i;
2572
2573         if (!spec)
2574                 return;
2575
2576         if (spec->kctl_alloc) {
2577                 for (i = 0; i < spec->num_kctl_used; i++)
2578                         kfree(spec->kctl_alloc[i].name);
2579                 kfree(spec->kctl_alloc);
2580         }
2581         kfree(spec);
2582         codec->spec = NULL; /* to be sure */
2583 }
2584
2585 /*
2586  */
2587 static struct hda_codec_ops alc_patch_ops = {
2588         .build_controls = alc_build_controls,
2589         .build_pcms = alc_build_pcms,
2590         .init = alc_init,
2591         .free = alc_free,
2592         .unsol_event = alc_unsol_event,
2593 #ifdef CONFIG_SND_HDA_POWER_SAVE
2594         .check_power_status = alc_check_power_status,
2595 #endif
2596 };
2597
2598
2599 /*
2600  * Test configuration for debugging
2601  *
2602  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
2603  * enum controls.
2604  */
2605 #ifdef CONFIG_SND_DEBUG
2606 static hda_nid_t alc880_test_dac_nids[4] = {
2607         0x02, 0x03, 0x04, 0x05
2608 };
2609
2610 static struct hda_input_mux alc880_test_capture_source = {
2611         .num_items = 7,
2612         .items = {
2613                 { "In-1", 0x0 },
2614                 { "In-2", 0x1 },
2615                 { "In-3", 0x2 },
2616                 { "In-4", 0x3 },
2617                 { "CD", 0x4 },
2618                 { "Front", 0x5 },
2619                 { "Surround", 0x6 },
2620         },
2621 };
2622
2623 static struct hda_channel_mode alc880_test_modes[4] = {
2624         { 2, NULL },
2625         { 4, NULL },
2626         { 6, NULL },
2627         { 8, NULL },
2628 };
2629
2630 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
2631                                  struct snd_ctl_elem_info *uinfo)
2632 {
2633         static char *texts[] = {
2634                 "N/A", "Line Out", "HP Out",
2635                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
2636         };
2637         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2638         uinfo->count = 1;
2639         uinfo->value.enumerated.items = 8;
2640         if (uinfo->value.enumerated.item >= 8)
2641                 uinfo->value.enumerated.item = 7;
2642         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2643         return 0;
2644 }
2645
2646 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
2647                                 struct snd_ctl_elem_value *ucontrol)
2648 {
2649         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2650         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2651         unsigned int pin_ctl, item = 0;
2652
2653         pin_ctl = snd_hda_codec_read(codec, nid, 0,
2654                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2655         if (pin_ctl & AC_PINCTL_OUT_EN) {
2656                 if (pin_ctl & AC_PINCTL_HP_EN)
2657                         item = 2;
2658                 else
2659                         item = 1;
2660         } else if (pin_ctl & AC_PINCTL_IN_EN) {
2661                 switch (pin_ctl & AC_PINCTL_VREFEN) {
2662                 case AC_PINCTL_VREF_HIZ: item = 3; break;
2663                 case AC_PINCTL_VREF_50:  item = 4; break;
2664                 case AC_PINCTL_VREF_GRD: item = 5; break;
2665                 case AC_PINCTL_VREF_80:  item = 6; break;
2666                 case AC_PINCTL_VREF_100: item = 7; break;
2667                 }
2668         }
2669         ucontrol->value.enumerated.item[0] = item;
2670         return 0;
2671 }
2672
2673 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
2674                                 struct snd_ctl_elem_value *ucontrol)
2675 {
2676         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2677         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2678         static unsigned int ctls[] = {
2679                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
2680                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
2681                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
2682                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
2683                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
2684                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
2685         };
2686         unsigned int old_ctl, new_ctl;
2687
2688         old_ctl = snd_hda_codec_read(codec, nid, 0,
2689                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2690         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
2691         if (old_ctl != new_ctl) {
2692                 int val;
2693                 snd_hda_codec_write_cache(codec, nid, 0,
2694                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
2695                                           new_ctl);
2696                 val = ucontrol->value.enumerated.item[0] >= 3 ?
2697                         HDA_AMP_MUTE : 0;
2698                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
2699                                          HDA_AMP_MUTE, val);
2700                 return 1;
2701         }
2702         return 0;
2703 }
2704
2705 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
2706                                  struct snd_ctl_elem_info *uinfo)
2707 {
2708         static char *texts[] = {
2709                 "Front", "Surround", "CLFE", "Side"
2710         };
2711         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2712         uinfo->count = 1;
2713         uinfo->value.enumerated.items = 4;
2714         if (uinfo->value.enumerated.item >= 4)
2715                 uinfo->value.enumerated.item = 3;
2716         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2717         return 0;
2718 }
2719
2720 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
2721                                 struct snd_ctl_elem_value *ucontrol)
2722 {
2723         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2724         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2725         unsigned int sel;
2726
2727         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
2728         ucontrol->value.enumerated.item[0] = sel & 3;
2729         return 0;
2730 }
2731
2732 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
2733                                 struct snd_ctl_elem_value *ucontrol)
2734 {
2735         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2736         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2737         unsigned int sel;
2738
2739         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
2740         if (ucontrol->value.enumerated.item[0] != sel) {
2741                 sel = ucontrol->value.enumerated.item[0] & 3;
2742                 snd_hda_codec_write_cache(codec, nid, 0,
2743                                           AC_VERB_SET_CONNECT_SEL, sel);
2744                 return 1;
2745         }
2746         return 0;
2747 }
2748
2749 #define PIN_CTL_TEST(xname,nid) {                       \
2750                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
2751                         .name = xname,                 \
2752                         .info = alc_test_pin_ctl_info, \
2753                         .get = alc_test_pin_ctl_get,   \
2754                         .put = alc_test_pin_ctl_put,   \
2755                         .private_value = nid           \
2756                         }
2757
2758 #define PIN_SRC_TEST(xname,nid) {                       \
2759                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
2760                         .name = xname,                 \
2761                         .info = alc_test_pin_src_info, \
2762                         .get = alc_test_pin_src_get,   \
2763                         .put = alc_test_pin_src_put,   \
2764                         .private_value = nid           \
2765                         }
2766
2767 static struct snd_kcontrol_new alc880_test_mixer[] = {
2768         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2769         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2770         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
2771         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2772         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2773         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2774         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
2775         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2776         PIN_CTL_TEST("Front Pin Mode", 0x14),
2777         PIN_CTL_TEST("Surround Pin Mode", 0x15),
2778         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
2779         PIN_CTL_TEST("Side Pin Mode", 0x17),
2780         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
2781         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
2782         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
2783         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
2784         PIN_SRC_TEST("In-1 Pin Source", 0x18),
2785         PIN_SRC_TEST("In-2 Pin Source", 0x19),
2786         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
2787         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
2788         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
2789         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
2790         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
2791         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
2792         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
2793         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
2794         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
2795         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
2796         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
2797         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
2798         {
2799                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2800                 .name = "Channel Mode",
2801                 .info = alc_ch_mode_info,
2802                 .get = alc_ch_mode_get,
2803                 .put = alc_ch_mode_put,
2804         },
2805         { } /* end */
2806 };
2807
2808 static struct hda_verb alc880_test_init_verbs[] = {
2809         /* Unmute inputs of 0x0c - 0x0f */
2810         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2811         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2812         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2813         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2814         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2815         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2816         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2817         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2818         /* Vol output for 0x0c-0x0f */
2819         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2820         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2821         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2822         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2823         /* Set output pins 0x14-0x17 */
2824         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2825         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2826         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2827         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2828         /* Unmute output pins 0x14-0x17 */
2829         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2830         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2831         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2832         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2833         /* Set input pins 0x18-0x1c */
2834         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2835         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2836         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2837         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2838         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2839         /* Mute input pins 0x18-0x1b */
2840         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2841         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2842         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2843         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2844         /* ADC set up */
2845         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2846         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2847         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2848         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2849         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2850         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2851         /* Analog input/passthru */
2852         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2853         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2854         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2855         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2856         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2857         { }
2858 };
2859 #endif
2860
2861 /*
2862  */
2863
2864 static const char *alc880_models[ALC880_MODEL_LAST] = {
2865         [ALC880_3ST]            = "3stack",
2866         [ALC880_TCL_S700]       = "tcl",
2867         [ALC880_3ST_DIG]        = "3stack-digout",
2868         [ALC880_CLEVO]          = "clevo",
2869         [ALC880_5ST]            = "5stack",
2870         [ALC880_5ST_DIG]        = "5stack-digout",
2871         [ALC880_W810]           = "w810",
2872         [ALC880_Z71V]           = "z71v",
2873         [ALC880_6ST]            = "6stack",
2874         [ALC880_6ST_DIG]        = "6stack-digout",
2875         [ALC880_ASUS]           = "asus",
2876         [ALC880_ASUS_W1V]       = "asus-w1v",
2877         [ALC880_ASUS_DIG]       = "asus-dig",
2878         [ALC880_ASUS_DIG2]      = "asus-dig2",
2879         [ALC880_UNIWILL_DIG]    = "uniwill",
2880         [ALC880_UNIWILL_P53]    = "uniwill-p53",
2881         [ALC880_FUJITSU]        = "fujitsu",
2882         [ALC880_F1734]          = "F1734",
2883         [ALC880_LG]             = "lg",
2884         [ALC880_LG_LW]          = "lg-lw",
2885 #ifdef CONFIG_SND_DEBUG
2886         [ALC880_TEST]           = "test",
2887 #endif
2888         [ALC880_AUTO]           = "auto",
2889 };
2890
2891 static struct snd_pci_quirk alc880_cfg_tbl[] = {
2892         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
2893         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
2894         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
2895         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
2896         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
2897         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
2898         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
2899         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
2900         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
2901         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
2902         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
2903         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
2904         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
2905         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
2906         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
2907         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
2908         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
2909         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
2910         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
2911         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
2912         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
2913         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS", ALC880_ASUS),
2914         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
2915         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
2916         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
2917         SND_PCI_QUIRK(0x1043, 0, "ASUS", ALC880_ASUS), /* default ASUS */
2918         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
2919         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
2920         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
2921         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
2922         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
2923         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
2924         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
2925         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
2926         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
2927         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
2928         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
2929         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
2930         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
2931         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
2932         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
2933         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
2934         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
2935         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
2936         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
2937         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
2938         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
2939         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
2940         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
2941         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
2942         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
2943         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
2944         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
2945         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
2946         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
2947         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
2948         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
2949         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
2950         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
2951         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
2952         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
2953         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
2954         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
2955         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
2956         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
2957         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
2958         SND_PCI_QUIRK(0x8086, 0, "Intel mobo", ALC880_3ST), /* default Intel */
2959         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
2960         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
2961         {}
2962 };
2963
2964 /*
2965  * ALC880 codec presets
2966  */
2967 static struct alc_config_preset alc880_presets[] = {
2968         [ALC880_3ST] = {
2969                 .mixers = { alc880_three_stack_mixer },
2970                 .init_verbs = { alc880_volume_init_verbs,
2971                                 alc880_pin_3stack_init_verbs },
2972                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2973                 .dac_nids = alc880_dac_nids,
2974                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
2975                 .channel_mode = alc880_threestack_modes,
2976                 .need_dac_fix = 1,
2977                 .input_mux = &alc880_capture_source,
2978         },
2979         [ALC880_3ST_DIG] = {
2980                 .mixers = { alc880_three_stack_mixer },
2981                 .init_verbs = { alc880_volume_init_verbs,
2982                                 alc880_pin_3stack_init_verbs },
2983                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2984                 .dac_nids = alc880_dac_nids,
2985                 .dig_out_nid = ALC880_DIGOUT_NID,
2986                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
2987                 .channel_mode = alc880_threestack_modes,
2988                 .need_dac_fix = 1,
2989                 .input_mux = &alc880_capture_source,
2990         },
2991         [ALC880_TCL_S700] = {
2992                 .mixers = { alc880_tcl_s700_mixer },
2993                 .init_verbs = { alc880_volume_init_verbs,
2994                                 alc880_pin_tcl_S700_init_verbs,
2995                                 alc880_gpio2_init_verbs },
2996                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2997                 .dac_nids = alc880_dac_nids,
2998                 .hp_nid = 0x03,
2999                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3000                 .channel_mode = alc880_2_jack_modes,
3001                 .input_mux = &alc880_capture_source,
3002         },
3003         [ALC880_5ST] = {
3004                 .mixers = { alc880_three_stack_mixer,
3005                             alc880_five_stack_mixer},
3006                 .init_verbs = { alc880_volume_init_verbs,
3007                                 alc880_pin_5stack_init_verbs },
3008                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3009                 .dac_nids = alc880_dac_nids,
3010                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3011                 .channel_mode = alc880_fivestack_modes,
3012                 .input_mux = &alc880_capture_source,
3013         },
3014         [ALC880_5ST_DIG] = {
3015                 .mixers = { alc880_three_stack_mixer,
3016                             alc880_five_stack_mixer },
3017                 .init_verbs = { alc880_volume_init_verbs,
3018                                 alc880_pin_5stack_init_verbs },
3019                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3020                 .dac_nids = alc880_dac_nids,
3021                 .dig_out_nid = ALC880_DIGOUT_NID,
3022                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3023                 .channel_mode = alc880_fivestack_modes,
3024                 .input_mux = &alc880_capture_source,
3025         },
3026         [ALC880_6ST] = {
3027                 .mixers = { alc880_six_stack_mixer },
3028                 .init_verbs = { alc880_volume_init_verbs,
3029                                 alc880_pin_6stack_init_verbs },
3030                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3031                 .dac_nids = alc880_6st_dac_nids,
3032                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3033                 .channel_mode = alc880_sixstack_modes,
3034                 .input_mux = &alc880_6stack_capture_source,
3035         },
3036         [ALC880_6ST_DIG] = {
3037                 .mixers = { alc880_six_stack_mixer },
3038                 .init_verbs = { alc880_volume_init_verbs,
3039                                 alc880_pin_6stack_init_verbs },
3040                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3041                 .dac_nids = alc880_6st_dac_nids,
3042                 .dig_out_nid = ALC880_DIGOUT_NID,
3043                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3044                 .channel_mode = alc880_sixstack_modes,
3045                 .input_mux = &alc880_6stack_capture_source,
3046         },
3047         [ALC880_W810] = {
3048                 .mixers = { alc880_w810_base_mixer },
3049                 .init_verbs = { alc880_volume_init_verbs,
3050                                 alc880_pin_w810_init_verbs,
3051                                 alc880_gpio2_init_verbs },
3052                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
3053                 .dac_nids = alc880_w810_dac_nids,
3054                 .dig_out_nid = ALC880_DIGOUT_NID,
3055                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3056                 .channel_mode = alc880_w810_modes,
3057                 .input_mux = &alc880_capture_source,
3058         },
3059         [ALC880_Z71V] = {
3060                 .mixers = { alc880_z71v_mixer },
3061                 .init_verbs = { alc880_volume_init_verbs,
3062                                 alc880_pin_z71v_init_verbs },
3063                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
3064                 .dac_nids = alc880_z71v_dac_nids,
3065                 .dig_out_nid = ALC880_DIGOUT_NID,
3066                 .hp_nid = 0x03,
3067                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3068                 .channel_mode = alc880_2_jack_modes,
3069                 .input_mux = &alc880_capture_source,
3070         },
3071         [ALC880_F1734] = {
3072                 .mixers = { alc880_f1734_mixer },
3073                 .init_verbs = { alc880_volume_init_verbs,
3074                                 alc880_pin_f1734_init_verbs },
3075                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
3076                 .dac_nids = alc880_f1734_dac_nids,
3077                 .hp_nid = 0x02,
3078                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3079                 .channel_mode = alc880_2_jack_modes,
3080                 .input_mux = &alc880_f1734_capture_source,
3081                 .unsol_event = alc880_uniwill_p53_unsol_event,
3082                 .init_hook = alc880_uniwill_p53_hp_automute,
3083         },
3084         [ALC880_ASUS] = {
3085                 .mixers = { alc880_asus_mixer },
3086                 .init_verbs = { alc880_volume_init_verbs,
3087                                 alc880_pin_asus_init_verbs,
3088                                 alc880_gpio1_init_verbs },
3089                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3090                 .dac_nids = alc880_asus_dac_nids,
3091                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3092                 .channel_mode = alc880_asus_modes,
3093                 .need_dac_fix = 1,
3094                 .input_mux = &alc880_capture_source,
3095         },
3096         [ALC880_ASUS_DIG] = {
3097                 .mixers = { alc880_asus_mixer },
3098                 .init_verbs = { alc880_volume_init_verbs,
3099                                 alc880_pin_asus_init_verbs,
3100                                 alc880_gpio1_init_verbs },
3101                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3102                 .dac_nids = alc880_asus_dac_nids,
3103                 .dig_out_nid = ALC880_DIGOUT_NID,
3104                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3105                 .channel_mode = alc880_asus_modes,
3106                 .need_dac_fix = 1,
3107                 .input_mux = &alc880_capture_source,
3108         },
3109         [ALC880_ASUS_DIG2] = {
3110                 .mixers = { alc880_asus_mixer },
3111                 .init_verbs = { alc880_volume_init_verbs,
3112                                 alc880_pin_asus_init_verbs,
3113                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
3114                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3115                 .dac_nids = alc880_asus_dac_nids,
3116                 .dig_out_nid = ALC880_DIGOUT_NID,
3117                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3118                 .channel_mode = alc880_asus_modes,
3119                 .need_dac_fix = 1,
3120                 .input_mux = &alc880_capture_source,
3121         },
3122         [ALC880_ASUS_W1V] = {
3123                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
3124                 .init_verbs = { alc880_volume_init_verbs,
3125                                 alc880_pin_asus_init_verbs,
3126                                 alc880_gpio1_init_verbs },
3127                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3128                 .dac_nids = alc880_asus_dac_nids,
3129                 .dig_out_nid = ALC880_DIGOUT_NID,
3130                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3131                 .channel_mode = alc880_asus_modes,
3132                 .need_dac_fix = 1,
3133                 .input_mux = &alc880_capture_source,
3134         },
3135         [ALC880_UNIWILL_DIG] = {
3136                 .mixers = { alc880_asus_mixer, alc880_pcbeep_mixer },
3137                 .init_verbs = { alc880_volume_init_verbs,
3138                                 alc880_pin_asus_init_verbs },
3139                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3140                 .dac_nids = alc880_asus_dac_nids,
3141                 .dig_out_nid = ALC880_DIGOUT_NID,
3142                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3143                 .channel_mode = alc880_asus_modes,
3144                 .need_dac_fix = 1,
3145                 .input_mux = &alc880_capture_source,
3146         },
3147         [ALC880_UNIWILL] = {
3148                 .mixers = { alc880_uniwill_mixer },
3149                 .init_verbs = { alc880_volume_init_verbs,
3150                                 alc880_uniwill_init_verbs },
3151                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3152                 .dac_nids = alc880_asus_dac_nids,
3153                 .dig_out_nid = ALC880_DIGOUT_NID,
3154                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3155                 .channel_mode = alc880_threestack_modes,
3156                 .need_dac_fix = 1,
3157                 .input_mux = &alc880_capture_source,
3158                 .unsol_event = alc880_uniwill_unsol_event,
3159                 .init_hook = alc880_uniwill_automute,
3160         },
3161         [ALC880_UNIWILL_P53] = {
3162                 .mixers = { alc880_uniwill_p53_mixer },
3163                 .init_verbs = { alc880_volume_init_verbs,
3164                                 alc880_uniwill_p53_init_verbs },
3165                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3166                 .dac_nids = alc880_asus_dac_nids,
3167                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3168                 .channel_mode = alc880_threestack_modes,
3169                 .input_mux = &alc880_capture_source,
3170                 .unsol_event = alc880_uniwill_p53_unsol_event,
3171                 .init_hook = alc880_uniwill_p53_hp_automute,
3172         },
3173         [ALC880_FUJITSU] = {
3174                 .mixers = { alc880_fujitsu_mixer,
3175                             alc880_pcbeep_mixer, },
3176                 .init_verbs = { alc880_volume_init_verbs,
3177                                 alc880_uniwill_p53_init_verbs,
3178                                 alc880_beep_init_verbs },
3179                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3180                 .dac_nids = alc880_dac_nids,
3181                 .dig_out_nid = ALC880_DIGOUT_NID,
3182                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3183                 .channel_mode = alc880_2_jack_modes,
3184                 .input_mux = &alc880_capture_source,
3185                 .unsol_event = alc880_uniwill_p53_unsol_event,
3186                 .init_hook = alc880_uniwill_p53_hp_automute,
3187         },
3188         [ALC880_CLEVO] = {
3189                 .mixers = { alc880_three_stack_mixer },
3190                 .init_verbs = { alc880_volume_init_verbs,
3191                                 alc880_pin_clevo_init_verbs },
3192                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3193                 .dac_nids = alc880_dac_nids,
3194                 .hp_nid = 0x03,
3195                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3196                 .channel_mode = alc880_threestack_modes,
3197                 .need_dac_fix = 1,
3198                 .input_mux = &alc880_capture_source,
3199         },
3200         [ALC880_LG] = {
3201                 .mixers = { alc880_lg_mixer },
3202                 .init_verbs = { alc880_volume_init_verbs,
3203                                 alc880_lg_init_verbs },
3204                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
3205                 .dac_nids = alc880_lg_dac_nids,
3206                 .dig_out_nid = ALC880_DIGOUT_NID,
3207                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
3208                 .channel_mode = alc880_lg_ch_modes,
3209                 .need_dac_fix = 1,
3210                 .input_mux = &alc880_lg_capture_source,
3211                 .unsol_event = alc880_lg_unsol_event,
3212                 .init_hook = alc880_lg_automute,
3213 #ifdef CONFIG_SND_HDA_POWER_SAVE
3214                 .loopbacks = alc880_lg_loopbacks,
3215 #endif
3216         },
3217         [ALC880_LG_LW] = {
3218                 .mixers = { alc880_lg_lw_mixer },
3219                 .init_verbs = { alc880_volume_init_verbs,
3220                                 alc880_lg_lw_init_verbs },
3221                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3222                 .dac_nids = alc880_dac_nids,
3223                 .dig_out_nid = ALC880_DIGOUT_NID,
3224                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
3225                 .channel_mode = alc880_lg_lw_modes,
3226                 .input_mux = &alc880_lg_lw_capture_source,
3227                 .unsol_event = alc880_lg_lw_unsol_event,
3228                 .init_hook = alc880_lg_lw_automute,
3229         },
3230 #ifdef CONFIG_SND_DEBUG
3231         [ALC880_TEST] = {
3232                 .mixers = { alc880_test_mixer },
3233                 .init_verbs = { alc880_test_init_verbs },
3234                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
3235                 .dac_nids = alc880_test_dac_nids,
3236                 .dig_out_nid = ALC880_DIGOUT_NID,
3237                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
3238                 .channel_mode = alc880_test_modes,
3239                 .input_mux = &alc880_test_capture_source,
3240         },
3241 #endif
3242 };
3243
3244 /*
3245  * Automatic parse of I/O pins from the BIOS configuration
3246  */
3247
3248 #define NUM_CONTROL_ALLOC       32
3249 #define NUM_VERB_ALLOC          32
3250
3251 enum {
3252         ALC_CTL_WIDGET_VOL,
3253         ALC_CTL_WIDGET_MUTE,
3254         ALC_CTL_BIND_MUTE,
3255 };
3256 static struct snd_kcontrol_new alc880_control_templates[] = {
3257         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
3258         HDA_CODEC_MUTE(NULL, 0, 0, 0),
3259         HDA_BIND_MUTE(NULL, 0, 0, 0),
3260 };
3261
3262 /* add dynamic controls */
3263 static int add_control(struct alc_spec *spec, int type, const char *name,
3264                        unsigned long val)
3265 {
3266         struct snd_kcontrol_new *knew;
3267
3268         if (spec->num_kctl_used >= spec->num_kctl_alloc) {
3269                 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
3270
3271                 /* array + terminator */
3272                 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL);
3273                 if (!knew)
3274                         return -ENOMEM;
3275                 if (spec->kctl_alloc) {
3276                         memcpy(knew, spec->kctl_alloc,
3277                                sizeof(*knew) * spec->num_kctl_alloc);
3278                         kfree(spec->kctl_alloc);
3279                 }
3280                 spec->kctl_alloc = knew;
3281                 spec->num_kctl_alloc = num;
3282         }
3283
3284         knew = &spec->kctl_alloc[spec->num_kctl_used];
3285         *knew = alc880_control_templates[type];
3286         knew->name = kstrdup(name, GFP_KERNEL);
3287         if (!knew->name)
3288                 return -ENOMEM;
3289         knew->private_value = val;
3290         spec->num_kctl_used++;
3291         return 0;
3292 }
3293
3294 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
3295 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
3296 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
3297 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
3298 #define alc880_is_input_pin(nid)        ((nid) >= 0x18)
3299 #define alc880_input_pin_idx(nid)       ((nid) - 0x18)
3300 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
3301 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
3302 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
3303 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
3304 #define ALC880_PIN_CD_NID               0x1c
3305
3306 /* fill in the dac_nids table from the parsed pin configuration */
3307 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
3308                                      const struct auto_pin_cfg *cfg)
3309 {
3310         hda_nid_t nid;
3311         int assigned[4];
3312         int i, j;
3313
3314         memset(assigned, 0, sizeof(assigned));
3315         spec->multiout.dac_nids = spec->private_dac_nids;
3316
3317         /* check the pins hardwired to audio widget */
3318         for (i = 0; i < cfg->line_outs; i++) {
3319                 nid = cfg->line_out_pins[i];
3320                 if (alc880_is_fixed_pin(nid)) {
3321                         int idx = alc880_fixed_pin_idx(nid);
3322                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
3323                         assigned[idx] = 1;
3324                 }
3325         }
3326         /* left pins can be connect to any audio widget */
3327         for (i = 0; i < cfg->line_outs; i++) {
3328                 nid = cfg->line_out_pins[i];
3329                 if (alc880_is_fixed_pin(nid))
3330                         continue;
3331                 /* search for an empty channel */
3332                 for (j = 0; j < cfg->line_outs; j++) {
3333                         if (!assigned[j]) {
3334                                 spec->multiout.dac_nids[i] =
3335                                         alc880_idx_to_dac(j);
3336                                 assigned[j] = 1;
3337                                 break;
3338                         }
3339                 }
3340         }
3341         spec->multiout.num_dacs = cfg->line_outs;
3342         return 0;
3343 }
3344
3345 /* add playback controls from the parsed DAC table */
3346 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
3347                                              const struct auto_pin_cfg *cfg)
3348 {
3349         char name[32];
3350         static const char *chname[4] = {
3351                 "Front", "Surround", NULL /*CLFE*/, "Side"
3352         };
3353         hda_nid_t nid;
3354         int i, err;
3355
3356         for (i = 0; i < cfg->line_outs; i++) {
3357                 if (!spec->multiout.dac_nids[i])
3358                         continue;
3359                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
3360                 if (i == 2) {
3361                         /* Center/LFE */
3362                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3363                                           "Center Playback Volume",
3364                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
3365                                                               HDA_OUTPUT));
3366                         if (err < 0)
3367                                 return err;
3368                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3369                                           "LFE Playback Volume",
3370                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
3371                                                               HDA_OUTPUT));
3372                         if (err < 0)
3373                                 return err;
3374                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3375                                           "Center Playback Switch",
3376                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
3377                                                               HDA_INPUT));
3378                         if (err < 0)
3379                                 return err;
3380                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3381                                           "LFE Playback Switch",
3382                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
3383                                                               HDA_INPUT));
3384                         if (err < 0)
3385                                 return err;
3386                 } else {
3387                         sprintf(name, "%s Playback Volume", chname[i]);
3388                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3389                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3390                                                               HDA_OUTPUT));
3391                         if (err < 0)
3392                                 return err;
3393                         sprintf(name, "%s Playback Switch", chname[i]);
3394                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3395                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
3396                                                               HDA_INPUT));
3397                         if (err < 0)
3398                                 return err;
3399                 }
3400         }
3401         return 0;
3402 }
3403
3404 /* add playback controls for speaker and HP outputs */
3405 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
3406                                         const char *pfx)
3407 {
3408         hda_nid_t nid;
3409         int err;
3410         char name[32];
3411
3412         if (!pin)
3413                 return 0;
3414
3415         if (alc880_is_fixed_pin(pin)) {
3416                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
3417                 /* specify the DAC as the extra output */
3418                 if (!spec->multiout.hp_nid)
3419                         spec->multiout.hp_nid = nid;
3420                 else
3421                         spec->multiout.extra_out_nid[0] = nid;
3422                 /* control HP volume/switch on the output mixer amp */
3423                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
3424                 sprintf(name, "%s Playback Volume", pfx);
3425                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3426                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3427                 if (err < 0)
3428                         return err;
3429                 sprintf(name, "%s Playback Switch", pfx);
3430                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3431                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
3432                 if (err < 0)
3433                         return err;
3434         } else if (alc880_is_multi_pin(pin)) {
3435                 /* set manual connection */
3436                 /* we have only a switch on HP-out PIN */
3437                 sprintf(name, "%s Playback Switch", pfx);
3438                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3439                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3440                 if (err < 0)
3441                         return err;
3442         }
3443         return 0;
3444 }
3445
3446 /* create input playback/capture controls for the given pin */
3447 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
3448                             const char *ctlname,
3449                             int idx, hda_nid_t mix_nid)
3450 {
3451         char name[32];
3452         int err;
3453
3454         sprintf(name, "%s Playback Volume", ctlname);
3455         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3456                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3457         if (err < 0)
3458                 return err;
3459         sprintf(name, "%s Playback Switch", ctlname);
3460         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3461                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3462         if (err < 0)
3463                 return err;
3464         return 0;
3465 }
3466
3467 /* create playback/capture controls for input pins */
3468 static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
3469                                                 const struct auto_pin_cfg *cfg)
3470 {
3471         struct hda_input_mux *imux = &spec->private_imux;
3472         int i, err, idx;
3473
3474         for (i = 0; i < AUTO_PIN_LAST; i++) {
3475                 if (alc880_is_input_pin(cfg->input_pins[i])) {
3476                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
3477                         err = new_analog_input(spec, cfg->input_pins[i],
3478                                                auto_pin_cfg_labels[i],
3479                                                idx, 0x0b);
3480                         if (err < 0)
3481                                 return err;
3482                         imux->items[imux->num_items].label =
3483                                 auto_pin_cfg_labels[i];
3484                         imux->items[imux->num_items].index =
3485                                 alc880_input_pin_idx(cfg->input_pins[i]);
3486                         imux->num_items++;
3487                 }
3488         }
3489         return 0;
3490 }
3491
3492 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
3493                                unsigned int pin_type)
3494 {
3495         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3496                             pin_type);
3497         /* unmute pin */
3498         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3499                             AMP_OUT_UNMUTE);
3500 }
3501
3502 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
3503                                               hda_nid_t nid, int pin_type,
3504                                               int dac_idx)
3505 {
3506         alc_set_pin_output(codec, nid, pin_type);
3507         /* need the manual connection? */
3508         if (alc880_is_multi_pin(nid)) {
3509                 struct alc_spec *spec = codec->spec;
3510                 int idx = alc880_multi_pin_idx(nid);
3511                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
3512                                     AC_VERB_SET_CONNECT_SEL,
3513                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
3514         }
3515 }
3516
3517 static int get_pin_type(int line_out_type)
3518 {
3519         if (line_out_type == AUTO_PIN_HP_OUT)
3520                 return PIN_HP;
3521         else
3522                 return PIN_OUT;
3523 }
3524
3525 static void alc880_auto_init_multi_out(struct hda_codec *codec)
3526 {
3527         struct alc_spec *spec = codec->spec;
3528         int i;
3529         
3530         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
3531         for (i = 0; i < spec->autocfg.line_outs; i++) {
3532                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3533                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3534                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
3535         }
3536 }
3537
3538 static void alc880_auto_init_extra_out(struct hda_codec *codec)
3539 {
3540         struct alc_spec *spec = codec->spec;
3541         hda_nid_t pin;
3542
3543         pin = spec->autocfg.speaker_pins[0];
3544         if (pin) /* connect to front */
3545                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
3546         pin = spec->autocfg.hp_pins[0];
3547         if (pin) /* connect to front */
3548                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
3549 }
3550
3551 static void alc880_auto_init_analog_input(struct hda_codec *codec)
3552 {
3553         struct alc_spec *spec = codec->spec;
3554         int i;
3555
3556         for (i = 0; i < AUTO_PIN_LAST; i++) {
3557                 hda_nid_t nid = spec->autocfg.input_pins[i];
3558                 if (alc880_is_input_pin(nid)) {
3559                         snd_hda_codec_write(codec, nid, 0,
3560                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
3561                                             i <= AUTO_PIN_FRONT_MIC ?
3562                                             PIN_VREF80 : PIN_IN);
3563                         if (nid != ALC880_PIN_CD_NID)
3564                                 snd_hda_codec_write(codec, nid, 0,
3565                                                     AC_VERB_SET_AMP_GAIN_MUTE,
3566                                                     AMP_OUT_MUTE);
3567                 }
3568         }
3569 }
3570
3571 /* parse the BIOS configuration and set up the alc_spec */
3572 /* return 1 if successful, 0 if the proper config is not found,
3573  * or a negative error code
3574  */
3575 static int alc880_parse_auto_config(struct hda_codec *codec)
3576 {
3577         struct alc_spec *spec = codec->spec;
3578         int err;
3579         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
3580
3581         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
3582                                            alc880_ignore);
3583         if (err < 0)
3584                 return err;
3585         if (!spec->autocfg.line_outs)
3586                 return 0; /* can't find valid BIOS pin config */
3587
3588         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
3589         if (err < 0)
3590                 return err;
3591         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
3592         if (err < 0)
3593                 return err;
3594         err = alc880_auto_create_extra_out(spec,
3595                                            spec->autocfg.speaker_pins[0],
3596                                            "Speaker");
3597         if (err < 0)
3598                 return err;
3599         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
3600                                            "Headphone");
3601         if (err < 0)
3602                 return err;
3603         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
3604         if (err < 0)
3605                 return err;
3606
3607         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3608
3609         if (spec->autocfg.dig_out_pin)
3610                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
3611         if (spec->autocfg.dig_in_pin)
3612                 spec->dig_in_nid = ALC880_DIGIN_NID;
3613
3614         if (spec->kctl_alloc)
3615                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
3616
3617         spec->init_verbs[spec->num_init_verbs++] = alc880_volume_init_verbs;
3618
3619         spec->num_mux_defs = 1;
3620         spec->input_mux = &spec->private_imux;
3621
3622         return 1;
3623 }
3624
3625 /* additional initialization for auto-configuration model */
3626 static void alc880_auto_init(struct hda_codec *codec)
3627 {
3628         struct alc_spec *spec = codec->spec;
3629         alc880_auto_init_multi_out(codec);
3630         alc880_auto_init_extra_out(codec);
3631         alc880_auto_init_analog_input(codec);
3632         if (spec->unsol_event)
3633                 alc_sku_automute(codec);
3634 }
3635
3636 /*
3637  * OK, here we have finally the patch for ALC880
3638  */
3639
3640 static int patch_alc880(struct hda_codec *codec)
3641 {
3642         struct alc_spec *spec;
3643         int board_config;
3644         int err;
3645
3646         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3647         if (spec == NULL)
3648                 return -ENOMEM;
3649
3650         codec->spec = spec;
3651
3652         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
3653                                                   alc880_models,
3654                                                   alc880_cfg_tbl);
3655         if (board_config < 0) {
3656                 printk(KERN_INFO "hda_codec: Unknown model for ALC880, "
3657                        "trying auto-probe from BIOS...\n");
3658                 board_config = ALC880_AUTO;
3659         }
3660
3661         if (board_config == ALC880_AUTO) {
3662                 /* automatic parse from the BIOS config */
3663                 err = alc880_parse_auto_config(codec);
3664                 if (err < 0) {
3665                         alc_free(codec);
3666                         return err;
3667                 } else if (!err) {
3668                         printk(KERN_INFO
3669                                "hda_codec: Cannot set up configuration "
3670                                "from BIOS.  Using 3-stack mode...\n");
3671                         board_config = ALC880_3ST;
3672                 }
3673         }
3674
3675         if (board_config != ALC880_AUTO)
3676                 setup_preset(spec, &alc880_presets[board_config]);
3677
3678         spec->stream_name_analog = "ALC880 Analog";
3679         spec->stream_analog_playback = &alc880_pcm_analog_playback;
3680         spec->stream_analog_capture = &alc880_pcm_analog_capture;
3681         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
3682
3683         spec->stream_name_digital = "ALC880 Digital";
3684         spec->stream_digital_playback = &alc880_pcm_digital_playback;
3685         spec->stream_digital_capture = &alc880_pcm_digital_capture;
3686
3687         if (!spec->adc_nids && spec->input_mux) {
3688                 /* check whether NID 0x07 is valid */
3689                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
3690                 /* get type */
3691                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
3692                 if (wcap != AC_WID_AUD_IN) {
3693                         spec->adc_nids = alc880_adc_nids_alt;
3694                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
3695                         spec->mixers[spec->num_mixers] =
3696                                 alc880_capture_alt_mixer;
3697                         spec->num_mixers++;
3698                 } else {
3699                         spec->adc_nids = alc880_adc_nids;
3700                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
3701                         spec->mixers[spec->num_mixers] = alc880_capture_mixer;
3702                         spec->num_mixers++;
3703                 }
3704         }
3705
3706         spec->vmaster_nid = 0x0c;
3707
3708         codec->patch_ops = alc_patch_ops;
3709         if (board_config == ALC880_AUTO)
3710                 spec->init_hook = alc880_auto_init;
3711 #ifdef CONFIG_SND_HDA_POWER_SAVE
3712         if (!spec->loopback.amplist)
3713                 spec->loopback.amplist = alc880_loopbacks;
3714 #endif
3715
3716         return 0;
3717 }
3718
3719
3720 /*
3721  * ALC260 support
3722  */
3723
3724 static hda_nid_t alc260_dac_nids[1] = {
3725         /* front */
3726         0x02,
3727 };
3728
3729 static hda_nid_t alc260_adc_nids[1] = {
3730         /* ADC0 */
3731         0x04,
3732 };
3733
3734 static hda_nid_t alc260_adc_nids_alt[1] = {
3735         /* ADC1 */
3736         0x05,
3737 };
3738
3739 static hda_nid_t alc260_hp_adc_nids[2] = {
3740         /* ADC1, 0 */
3741         0x05, 0x04
3742 };
3743
3744 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
3745  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
3746  */
3747 static hda_nid_t alc260_dual_adc_nids[2] = {
3748         /* ADC0, ADC1 */
3749         0x04, 0x05
3750 };
3751
3752 #define ALC260_DIGOUT_NID       0x03
3753 #define ALC260_DIGIN_NID        0x06
3754
3755 static struct hda_input_mux alc260_capture_source = {
3756         .num_items = 4,
3757         .items = {
3758                 { "Mic", 0x0 },
3759                 { "Front Mic", 0x1 },
3760                 { "Line", 0x2 },
3761                 { "CD", 0x4 },
3762         },
3763 };
3764
3765 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
3766  * headphone jack and the internal CD lines since these are the only pins at
3767  * which audio can appear.  For flexibility, also allow the option of
3768  * recording the mixer output on the second ADC (ADC0 doesn't have a
3769  * connection to the mixer output).
3770  */
3771 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
3772         {
3773                 .num_items = 3,
3774                 .items = {
3775                         { "Mic/Line", 0x0 },
3776                         { "CD", 0x4 },
3777                         { "Headphone", 0x2 },
3778                 },
3779         },
3780         {
3781                 .num_items = 4,
3782                 .items = {
3783                         { "Mic/Line", 0x0 },
3784                         { "CD", 0x4 },
3785                         { "Headphone", 0x2 },
3786                         { "Mixer", 0x5 },
3787                 },
3788         },
3789
3790 };
3791
3792 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
3793  * the Fujitsu S702x, but jacks are marked differently.
3794  */
3795 static struct hda_input_mux alc260_acer_capture_sources[2] = {
3796         {
3797                 .num_items = 4,
3798                 .items = {
3799                         { "Mic", 0x0 },
3800                         { "Line", 0x2 },
3801                         { "CD", 0x4 },
3802                         { "Headphone", 0x5 },
3803                 },
3804         },
3805         {
3806                 .num_items = 5,
3807                 .items = {
3808                         { "Mic", 0x0 },
3809                         { "Line", 0x2 },
3810                         { "CD", 0x4 },
3811                         { "Headphone", 0x6 },
3812                         { "Mixer", 0x5 },
3813                 },
3814         },
3815 };
3816 /*
3817  * This is just place-holder, so there's something for alc_build_pcms to look
3818  * at when it calculates the maximum number of channels. ALC260 has no mixer
3819  * element which allows changing the channel mode, so the verb list is
3820  * never used.
3821  */
3822 static struct hda_channel_mode alc260_modes[1] = {
3823         { 2, NULL },
3824 };
3825
3826
3827 /* Mixer combinations
3828  *
3829  * basic: base_output + input + pc_beep + capture
3830  * HP: base_output + input + capture_alt
3831  * HP_3013: hp_3013 + input + capture
3832  * fujitsu: fujitsu + capture
3833  * acer: acer + capture
3834  */
3835
3836 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
3837         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3838         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
3839         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
3840         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
3841         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
3842         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
3843         { } /* end */
3844 };
3845
3846 static struct snd_kcontrol_new alc260_input_mixer[] = {
3847         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3848         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3849         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
3850         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
3851         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
3852         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
3853         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
3854         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
3855         { } /* end */
3856 };
3857
3858 static struct snd_kcontrol_new alc260_pc_beep_mixer[] = {
3859         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT),
3860         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT),
3861         { } /* end */
3862 };
3863
3864 /* update HP, line and mono out pins according to the master switch */
3865 static void alc260_hp_master_update(struct hda_codec *codec,
3866                                     hda_nid_t hp, hda_nid_t line,
3867                                     hda_nid_t mono)
3868 {
3869         struct alc_spec *spec = codec->spec;
3870         unsigned int val = spec->master_sw ? PIN_HP : 0;
3871         /* change HP and line-out pins */
3872         snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3873                             val);
3874         snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3875                             val);
3876         /* mono (speaker) depending on the HP jack sense */
3877         val = (val && !spec->jack_present) ? PIN_OUT : 0;
3878         snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3879                             val);
3880 }
3881
3882 static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
3883                                    struct snd_ctl_elem_value *ucontrol)
3884 {
3885         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3886         struct alc_spec *spec = codec->spec;
3887         *ucontrol->value.integer.value = spec->master_sw;
3888         return 0;
3889 }
3890
3891 static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
3892                                    struct snd_ctl_elem_value *ucontrol)
3893 {
3894         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3895         struct alc_spec *spec = codec->spec;
3896         int val = !!*ucontrol->value.integer.value;
3897         hda_nid_t hp, line, mono;
3898
3899         if (val == spec->master_sw)
3900                 return 0;
3901         spec->master_sw = val;
3902         hp = (kcontrol->private_value >> 16) & 0xff;
3903         line = (kcontrol->private_value >> 8) & 0xff;
3904         mono = kcontrol->private_value & 0xff;
3905         alc260_hp_master_update(codec, hp, line, mono);
3906         return 1;
3907 }
3908
3909 static struct snd_kcontrol_new alc260_hp_output_mixer[] = {
3910         {
3911                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3912                 .name = "Master Playback Switch",
3913                 .info = snd_ctl_boolean_mono_info,
3914                 .get = alc260_hp_master_sw_get,
3915                 .put = alc260_hp_master_sw_put,
3916                 .private_value = (0x0f << 16) | (0x10 << 8) | 0x11
3917         },
3918         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3919         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
3920         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
3921         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
3922         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
3923                               HDA_OUTPUT),
3924         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2, HDA_INPUT),
3925         { } /* end */
3926 };
3927
3928 static struct hda_verb alc260_hp_unsol_verbs[] = {
3929         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3930         {},
3931 };
3932
3933 static void alc260_hp_automute(struct hda_codec *codec)
3934 {
3935         struct alc_spec *spec = codec->spec;
3936         unsigned int present;
3937
3938         present = snd_hda_codec_read(codec, 0x10, 0,
3939                                      AC_VERB_GET_PIN_SENSE, 0);
3940         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
3941         alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
3942 }
3943
3944 static void alc260_hp_unsol_event(struct hda_codec *codec, unsigned int res)
3945 {
3946         if ((res >> 26) == ALC880_HP_EVENT)
3947                 alc260_hp_automute(codec);
3948 }
3949
3950 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
3951         {
3952                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3953                 .name = "Master Playback Switch",
3954                 .info = snd_ctl_boolean_mono_info,
3955                 .get = alc260_hp_master_sw_get,
3956                 .put = alc260_hp_master_sw_put,
3957                 .private_value = (0x10 << 16) | (0x15 << 8) | 0x11
3958         },
3959         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
3960         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
3961         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
3962         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
3963         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3964         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
3965         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
3966         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
3967         { } /* end */
3968 };
3969
3970 static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
3971         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3972         {},
3973 };
3974
3975 static void alc260_hp_3013_automute(struct hda_codec *codec)
3976 {
3977         struct alc_spec *spec = codec->spec;
3978         unsigned int present;
3979
3980         present = snd_hda_codec_read(codec, 0x15, 0,
3981                                      AC_VERB_GET_PIN_SENSE, 0);
3982         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
3983         alc260_hp_master_update(codec, 0x10, 0x15, 0x11);
3984 }
3985
3986 static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
3987                                        unsigned int res)
3988 {
3989         if ((res >> 26) == ALC880_HP_EVENT)
3990                 alc260_hp_3013_automute(codec);
3991 }
3992
3993 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12, 
3994  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
3995  */
3996 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
3997         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3998         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
3999         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4000         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4001         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4002         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
4003         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
4004         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
4005         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4006         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4007         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4008         HDA_BIND_MUTE("Speaker Playback Switch", 0x09, 2, HDA_INPUT),
4009         { } /* end */
4010 };
4011
4012 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
4013  * versions of the ALC260 don't act on requests to enable mic bias from NID
4014  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
4015  * datasheet doesn't mention this restriction.  At this stage it's not clear
4016  * whether this behaviour is intentional or is a hardware bug in chip
4017  * revisions available in early 2006.  Therefore for now allow the
4018  * "Headphone Jack Mode" control to span all choices, but if it turns out
4019  * that the lack of mic bias for this NID is intentional we could change the
4020  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4021  *
4022  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
4023  * don't appear to make the mic bias available from the "line" jack, even
4024  * though the NID used for this jack (0x14) can supply it.  The theory is
4025  * that perhaps Acer have included blocking capacitors between the ALC260
4026  * and the output jack.  If this turns out to be the case for all such
4027  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
4028  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
4029  *
4030  * The C20x Tablet series have a mono internal speaker which is controlled
4031  * via the chip's Mono sum widget and pin complex, so include the necessary
4032  * controls for such models.  On models without a "mono speaker" the control
4033  * won't do anything.
4034  */
4035 static struct snd_kcontrol_new alc260_acer_mixer[] = {
4036         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4037         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
4038         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
4039         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4040                               HDA_OUTPUT),
4041         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2,
4042                            HDA_INPUT),
4043         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4044         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4045         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4046         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4047         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4048         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4049         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4050         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4051         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4052         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4053         { } /* end */
4054 };
4055
4056 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
4057  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
4058  */
4059 static struct snd_kcontrol_new alc260_will_mixer[] = {
4060         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4061         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4062         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4063         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4064         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4065         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4066         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4067         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4068         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4069         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4070         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4071         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4072         { } /* end */
4073 };
4074
4075 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
4076  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
4077  */
4078 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
4079         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4080         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4081         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4082         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4083         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4084         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
4085         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
4086         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4087         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4088         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4089         { } /* end */
4090 };
4091
4092 /* capture mixer elements */
4093 static struct snd_kcontrol_new alc260_capture_mixer[] = {
4094         HDA_CODEC_VOLUME("Capture Volume", 0x04, 0x0, HDA_INPUT),
4095         HDA_CODEC_MUTE("Capture Switch", 0x04, 0x0, HDA_INPUT),
4096         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x05, 0x0, HDA_INPUT),
4097         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x05, 0x0, HDA_INPUT),
4098         {
4099                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4100                 /* The multiple "Capture Source" controls confuse alsamixer
4101                  * So call somewhat different..
4102                  */
4103                 /* .name = "Capture Source", */
4104                 .name = "Input Source",
4105                 .count = 2,
4106                 .info = alc_mux_enum_info,
4107                 .get = alc_mux_enum_get,
4108                 .put = alc_mux_enum_put,
4109         },
4110         { } /* end */
4111 };
4112
4113 static struct snd_kcontrol_new alc260_capture_alt_mixer[] = {
4114         HDA_CODEC_VOLUME("Capture Volume", 0x05, 0x0, HDA_INPUT),
4115         HDA_CODEC_MUTE("Capture Switch", 0x05, 0x0, HDA_INPUT),
4116         {
4117                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4118                 /* The multiple "Capture Source" controls confuse alsamixer
4119                  * So call somewhat different..
4120                  */
4121                 /* .name = "Capture Source", */
4122                 .name = "Input Source",
4123                 .count = 1,
4124                 .info = alc_mux_enum_info,
4125                 .get = alc_mux_enum_get,
4126                 .put = alc_mux_enum_put,
4127         },
4128         { } /* end */
4129 };
4130
4131 /*
4132  * initialization verbs
4133  */
4134 static struct hda_verb alc260_init_verbs[] = {
4135         /* Line In pin widget for input */
4136         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4137         /* CD pin widget for input */
4138         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4139         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4140         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4141         /* Mic2 (front panel) pin widget for input and vref at 80% */
4142         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4143         /* LINE-2 is used for line-out in rear */
4144         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4145         /* select line-out */
4146         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
4147         /* LINE-OUT pin */
4148         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4149         /* enable HP */
4150         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4151         /* enable Mono */
4152         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4153         /* mute capture amp left and right */
4154         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4155         /* set connection select to line in (default select for this ADC) */
4156         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4157         /* mute capture amp left and right */
4158         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4159         /* set connection select to line in (default select for this ADC) */
4160         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
4161         /* set vol=0 Line-Out mixer amp left and right */
4162         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4163         /* unmute pin widget amp left and right (no gain on this amp) */
4164         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4165         /* set vol=0 HP mixer amp left and right */
4166         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4167         /* unmute pin widget amp left and right (no gain on this amp) */
4168         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4169         /* set vol=0 Mono mixer amp left and right */
4170         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4171         /* unmute pin widget amp left and right (no gain on this amp) */
4172         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4173         /* unmute LINE-2 out pin */
4174         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4175         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4176          * Line In 2 = 0x03
4177          */
4178         /* mute analog inputs */
4179         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4180         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4181         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4182         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4183         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4184         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4185         /* mute Front out path */
4186         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4187         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4188         /* mute Headphone out path */
4189         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4190         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4191         /* mute Mono out path */
4192         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4193         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4194         { }
4195 };
4196
4197 #if 0 /* should be identical with alc260_init_verbs? */
4198 static struct hda_verb alc260_hp_init_verbs[] = {
4199         /* Headphone and output */
4200         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4201         /* mono output */
4202         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4203         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4204         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4205         /* Mic2 (front panel) pin widget for input and vref at 80% */
4206         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4207         /* Line In pin widget for input */
4208         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4209         /* Line-2 pin widget for output */
4210         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4211         /* CD pin widget for input */
4212         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4213         /* unmute amp left and right */
4214         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4215         /* set connection select to line in (default select for this ADC) */
4216         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4217         /* unmute Line-Out mixer amp left and right (volume = 0) */
4218         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4219         /* mute pin widget amp left and right (no gain on this amp) */
4220         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4221         /* unmute HP mixer amp left and right (volume = 0) */
4222         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4223         /* mute pin widget amp left and right (no gain on this amp) */
4224         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4225         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4226          * Line In 2 = 0x03
4227          */
4228         /* mute analog inputs */
4229         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4230         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4231         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4232         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4233         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4234         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4235         /* Unmute Front out path */
4236         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4237         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4238         /* Unmute Headphone out path */
4239         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4240         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4241         /* Unmute Mono out path */
4242         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4243         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4244         { }
4245 };
4246 #endif
4247
4248 static struct hda_verb alc260_hp_3013_init_verbs[] = {
4249         /* Line out and output */
4250         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4251         /* mono output */
4252         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4253         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4254         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4255         /* Mic2 (front panel) pin widget for input and vref at 80% */
4256         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4257         /* Line In pin widget for input */
4258         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4259         /* Headphone pin widget for output */
4260         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4261         /* CD pin widget for input */
4262         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4263         /* unmute amp left and right */
4264         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4265         /* set connection select to line in (default select for this ADC) */
4266         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4267         /* unmute Line-Out mixer amp left and right (volume = 0) */
4268         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4269         /* mute pin widget amp left and right (no gain on this amp) */
4270         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4271         /* unmute HP mixer amp left and right (volume = 0) */
4272         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4273         /* mute pin widget amp left and right (no gain on this amp) */
4274         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4275         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4276          * Line In 2 = 0x03
4277          */
4278         /* mute analog inputs */
4279         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4280         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4281         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4282         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4283         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4284         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4285         /* Unmute Front out path */
4286         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4287         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4288         /* Unmute Headphone out path */
4289         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4290         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4291         /* Unmute Mono out path */
4292         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4293         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4294         { }
4295 };
4296
4297 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
4298  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
4299  * audio = 0x16, internal speaker = 0x10.
4300  */
4301 static struct hda_verb alc260_fujitsu_init_verbs[] = {
4302         /* Disable all GPIOs */
4303         {0x01, AC_VERB_SET_GPIO_MASK, 0},
4304         /* Internal speaker is connected to headphone pin */
4305         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4306         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
4307         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4308         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
4309         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4310         /* Ensure all other unused pins are disabled and muted. */
4311         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4312         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4313         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4314         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4315         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4316         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4317         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4318         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4319
4320         /* Disable digital (SPDIF) pins */
4321         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4322         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4323
4324         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus 
4325          * when acting as an output.
4326          */
4327         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4328
4329         /* Start with output sum widgets muted and their output gains at min */
4330         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4331         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4332         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4333         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4334         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4335         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4336         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4337         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4338         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4339
4340         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
4341         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4342         /* Unmute Line1 pin widget output buffer since it starts as an output.
4343          * If the pin mode is changed by the user the pin mode control will
4344          * take care of enabling the pin's input/output buffers as needed.
4345          * Therefore there's no need to enable the input buffer at this
4346          * stage.
4347          */
4348         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4349         /* Unmute input buffer of pin widget used for Line-in (no equiv 
4350          * mixer ctrl)
4351          */
4352         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4353
4354         /* Mute capture amp left and right */
4355         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4356         /* Set ADC connection select to match default mixer setting - line 
4357          * in (on mic1 pin)
4358          */
4359         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4360
4361         /* Do the same for the second ADC: mute capture input amp and
4362          * set ADC connection to line in (on mic1 pin)
4363          */
4364         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4365         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4366
4367         /* Mute all inputs to mixer widget (even unconnected ones) */
4368         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4369         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4370         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4371         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4372         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4373         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4374         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4375         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4376
4377         { }
4378 };
4379
4380 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
4381  * similar laptops (adapted from Fujitsu init verbs).
4382  */
4383 static struct hda_verb alc260_acer_init_verbs[] = {
4384         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
4385          * the headphone jack.  Turn this on and rely on the standard mute
4386          * methods whenever the user wants to turn these outputs off.
4387          */
4388         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
4389         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4390         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
4391         /* Internal speaker/Headphone jack is connected to Line-out pin */
4392         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4393         /* Internal microphone/Mic jack is connected to Mic1 pin */
4394         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
4395         /* Line In jack is connected to Line1 pin */
4396         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4397         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
4398         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4399         /* Ensure all other unused pins are disabled and muted. */
4400         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4401         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4402         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4403         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4404         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4405         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4406         /* Disable digital (SPDIF) pins */
4407         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4408         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4409
4410         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum 
4411          * bus when acting as outputs.
4412          */
4413         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
4414         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4415
4416         /* Start with output sum widgets muted and their output gains at min */
4417         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4418         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4419         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4420         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4421         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4422         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4423         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4424         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4425         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4426
4427         /* Unmute Line-out pin widget amp left and right
4428          * (no equiv mixer ctrl)
4429          */
4430         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4431         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
4432         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4433         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
4434          * inputs. If the pin mode is changed by the user the pin mode control
4435          * will take care of enabling the pin's input/output buffers as needed.
4436          * Therefore there's no need to enable the input buffer at this
4437          * stage.
4438          */
4439         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4440         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4441
4442         /* Mute capture amp left and right */
4443         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4444         /* Set ADC connection select to match default mixer setting - mic
4445          * (on mic1 pin)
4446          */
4447         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4448
4449         /* Do similar with the second ADC: mute capture input amp and
4450          * set ADC connection to mic to match ALSA's default state.
4451          */
4452         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4453         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4454
4455         /* Mute all inputs to mixer widget (even unconnected ones) */
4456         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4457         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4458         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4459         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4460         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4461         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4462         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4463         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4464
4465         { }
4466 };
4467
4468 static struct hda_verb alc260_will_verbs[] = {
4469         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4470         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
4471         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
4472         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4473         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
4474         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
4475         {}
4476 };
4477
4478 static struct hda_verb alc260_replacer_672v_verbs[] = {
4479         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4480         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
4481         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
4482
4483         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
4484         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4485         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4486
4487         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4488         {}
4489 };
4490
4491 /* toggle speaker-output according to the hp-jack state */
4492 static void alc260_replacer_672v_automute(struct hda_codec *codec)
4493 {
4494         unsigned int present;
4495
4496         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
4497         present = snd_hda_codec_read(codec, 0x0f, 0,
4498                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
4499         if (present) {
4500                 snd_hda_codec_write_cache(codec, 0x01, 0,
4501                                           AC_VERB_SET_GPIO_DATA, 1);
4502                 snd_hda_codec_write_cache(codec, 0x0f, 0,
4503                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4504                                           PIN_HP);
4505         } else {
4506                 snd_hda_codec_write_cache(codec, 0x01, 0,
4507                                           AC_VERB_SET_GPIO_DATA, 0);
4508                 snd_hda_codec_write_cache(codec, 0x0f, 0,
4509                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4510                                           PIN_OUT);
4511         }
4512 }
4513
4514 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
4515                                        unsigned int res)
4516 {
4517         if ((res >> 26) == ALC880_HP_EVENT)
4518                 alc260_replacer_672v_automute(codec);
4519 }
4520
4521 /* Test configuration for debugging, modelled after the ALC880 test
4522  * configuration.
4523  */
4524 #ifdef CONFIG_SND_DEBUG
4525 static hda_nid_t alc260_test_dac_nids[1] = {
4526         0x02,
4527 };
4528 static hda_nid_t alc260_test_adc_nids[2] = {
4529         0x04, 0x05,
4530 };
4531 /* For testing the ALC260, each input MUX needs its own definition since
4532  * the signal assignments are different.  This assumes that the first ADC 
4533  * is NID 0x04.
4534  */
4535 static struct hda_input_mux alc260_test_capture_sources[2] = {
4536         {
4537                 .num_items = 7,
4538                 .items = {
4539                         { "MIC1 pin", 0x0 },
4540                         { "MIC2 pin", 0x1 },
4541                         { "LINE1 pin", 0x2 },
4542                         { "LINE2 pin", 0x3 },
4543                         { "CD pin", 0x4 },
4544                         { "LINE-OUT pin", 0x5 },
4545                         { "HP-OUT pin", 0x6 },
4546                 },
4547         },
4548         {
4549                 .num_items = 8,
4550                 .items = {
4551                         { "MIC1 pin", 0x0 },
4552                         { "MIC2 pin", 0x1 },
4553                         { "LINE1 pin", 0x2 },
4554                         { "LINE2 pin", 0x3 },
4555                         { "CD pin", 0x4 },
4556                         { "Mixer", 0x5 },
4557                         { "LINE-OUT pin", 0x6 },
4558                         { "HP-OUT pin", 0x7 },
4559                 },
4560         },
4561 };
4562 static struct snd_kcontrol_new alc260_test_mixer[] = {
4563         /* Output driver widgets */
4564         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4565         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4566         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4567         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
4568         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4569         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
4570
4571         /* Modes for retasking pin widgets
4572          * Note: the ALC260 doesn't seem to act on requests to enable mic
4573          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
4574          * mention this restriction.  At this stage it's not clear whether
4575          * this behaviour is intentional or is a hardware bug in chip
4576          * revisions available at least up until early 2006.  Therefore for
4577          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
4578          * choices, but if it turns out that the lack of mic bias for these
4579          * NIDs is intentional we could change their modes from
4580          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4581          */
4582         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
4583         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
4584         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
4585         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
4586         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
4587         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
4588
4589         /* Loopback mixer controls */
4590         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
4591         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
4592         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
4593         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
4594         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
4595         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
4596         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
4597         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
4598         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4599         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4600         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4601         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4602         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
4603         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
4604         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
4605         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
4606
4607         /* Controls for GPIO pins, assuming they are configured as outputs */
4608         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
4609         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
4610         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
4611         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
4612
4613         /* Switches to allow the digital IO pins to be enabled.  The datasheet
4614          * is ambigious as to which NID is which; testing on laptops which
4615          * make this output available should provide clarification. 
4616          */
4617         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
4618         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
4619
4620         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
4621          * this output to turn on an external amplifier.
4622          */
4623         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
4624         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
4625
4626         { } /* end */
4627 };
4628 static struct hda_verb alc260_test_init_verbs[] = {
4629         /* Enable all GPIOs as outputs with an initial value of 0 */
4630         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
4631         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4632         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
4633
4634         /* Enable retasking pins as output, initially without power amp */
4635         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4636         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4637         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4638         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4639         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4640         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4641
4642         /* Disable digital (SPDIF) pins initially, but users can enable
4643          * them via a mixer switch.  In the case of SPDIF-out, this initverb
4644          * payload also sets the generation to 0, output to be in "consumer"
4645          * PCM format, copyright asserted, no pre-emphasis and no validity
4646          * control.
4647          */
4648         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4649         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4650
4651         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the 
4652          * OUT1 sum bus when acting as an output.
4653          */
4654         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
4655         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
4656         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4657         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
4658
4659         /* Start with output sum widgets muted and their output gains at min */
4660         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4661         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4662         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4663         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4664         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4665         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4666         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4667         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4668         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4669
4670         /* Unmute retasking pin widget output buffers since the default
4671          * state appears to be output.  As the pin mode is changed by the
4672          * user the pin mode control will take care of enabling the pin's
4673          * input/output buffers as needed.
4674          */
4675         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4676         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4677         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4678         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4679         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4680         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4681         /* Also unmute the mono-out pin widget */
4682         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4683
4684         /* Mute capture amp left and right */
4685         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4686         /* Set ADC connection select to match default mixer setting (mic1
4687          * pin)
4688          */
4689         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4690
4691         /* Do the same for the second ADC: mute capture input amp and
4692          * set ADC connection to mic1 pin
4693          */
4694         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4695         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4696
4697         /* Mute all inputs to mixer widget (even unconnected ones) */
4698         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4699         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4700         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4701         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4702         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4703         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4704         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4705         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4706
4707         { }
4708 };
4709 #endif
4710
4711 #define alc260_pcm_analog_playback      alc880_pcm_analog_alt_playback
4712 #define alc260_pcm_analog_capture       alc880_pcm_analog_capture
4713
4714 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
4715 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
4716
4717 /*
4718  * for BIOS auto-configuration
4719  */
4720
4721 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
4722                                         const char *pfx)
4723 {
4724         hda_nid_t nid_vol;
4725         unsigned long vol_val, sw_val;
4726         char name[32];
4727         int err;
4728
4729         if (nid >= 0x0f && nid < 0x11) {
4730                 nid_vol = nid - 0x7;
4731                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
4732                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
4733         } else if (nid == 0x11) {
4734                 nid_vol = nid - 0x7;
4735                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
4736                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
4737         } else if (nid >= 0x12 && nid <= 0x15) {
4738                 nid_vol = 0x08;
4739                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
4740                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
4741         } else
4742                 return 0; /* N/A */
4743         
4744         snprintf(name, sizeof(name), "%s Playback Volume", pfx);
4745         err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val);
4746         if (err < 0)
4747                 return err;
4748         snprintf(name, sizeof(name), "%s Playback Switch", pfx);
4749         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val);
4750         if (err < 0)
4751                 return err;
4752         return 1;
4753 }
4754
4755 /* add playback controls from the parsed DAC table */
4756 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
4757                                              const struct auto_pin_cfg *cfg)
4758 {
4759         hda_nid_t nid;
4760         int err;
4761
4762         spec->multiout.num_dacs = 1;
4763         spec->multiout.dac_nids = spec->private_dac_nids;
4764         spec->multiout.dac_nids[0] = 0x02;
4765
4766         nid = cfg->line_out_pins[0];
4767         if (nid) {
4768                 err = alc260_add_playback_controls(spec, nid, "Front");
4769                 if (err < 0)
4770                         return err;
4771         }
4772
4773         nid = cfg->speaker_pins[0];
4774         if (nid) {
4775                 err = alc260_add_playback_controls(spec, nid, "Speaker");
4776                 if (err < 0)
4777                         return err;
4778         }
4779
4780         nid = cfg->hp_pins[0];
4781         if (nid) {
4782                 err = alc260_add_playback_controls(spec, nid, "Headphone");
4783                 if (err < 0)
4784                         return err;
4785         }
4786         return 0;
4787 }
4788
4789 /* create playback/capture controls for input pins */
4790 static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec,
4791                                                 const struct auto_pin_cfg *cfg)
4792 {
4793         struct hda_input_mux *imux = &spec->private_imux;
4794         int i, err, idx;
4795
4796         for (i = 0; i < AUTO_PIN_LAST; i++) {
4797                 if (cfg->input_pins[i] >= 0x12) {
4798                         idx = cfg->input_pins[i] - 0x12;
4799                         err = new_analog_input(spec, cfg->input_pins[i],
4800                                                auto_pin_cfg_labels[i], idx,
4801                                                0x07);
4802                         if (err < 0)
4803                                 return err;
4804                         imux->items[imux->num_items].label =
4805                                 auto_pin_cfg_labels[i];
4806                         imux->items[imux->num_items].index = idx;
4807                         imux->num_items++;
4808                 }
4809                 if (cfg->input_pins[i] >= 0x0f && cfg->input_pins[i] <= 0x10){
4810                         idx = cfg->input_pins[i] - 0x09;
4811                         err = new_analog_input(spec, cfg->input_pins[i],
4812                                                auto_pin_cfg_labels[i], idx,
4813                                                0x07);
4814                         if (err < 0)
4815                                 return err;
4816                         imux->items[imux->num_items].label =
4817                                 auto_pin_cfg_labels[i];
4818                         imux->items[imux->num_items].index = idx;
4819                         imux->num_items++;
4820                 }
4821         }
4822         return 0;
4823 }
4824
4825 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
4826                                               hda_nid_t nid, int pin_type,
4827                                               int sel_idx)
4828 {
4829         alc_set_pin_output(codec, nid, pin_type);
4830         /* need the manual connection? */
4831         if (nid >= 0x12) {
4832                 int idx = nid - 0x12;
4833                 snd_hda_codec_write(codec, idx + 0x0b, 0,
4834                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
4835         }
4836 }
4837
4838 static void alc260_auto_init_multi_out(struct hda_codec *codec)
4839 {
4840         struct alc_spec *spec = codec->spec;
4841         hda_nid_t nid;
4842
4843         alc_subsystem_id(codec, 0x10, 0x15, 0x0f);
4844         nid = spec->autocfg.line_out_pins[0];
4845         if (nid) {
4846                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
4847                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
4848         }
4849         
4850         nid = spec->autocfg.speaker_pins[0];
4851         if (nid)
4852                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
4853
4854         nid = spec->autocfg.hp_pins[0];
4855         if (nid)
4856                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
4857 }
4858
4859 #define ALC260_PIN_CD_NID               0x16
4860 static void alc260_auto_init_analog_input(struct hda_codec *codec)
4861 {
4862         struct alc_spec *spec = codec->spec;
4863         int i;
4864
4865         for (i = 0; i < AUTO_PIN_LAST; i++) {
4866                 hda_nid_t nid = spec->autocfg.input_pins[i];
4867                 if (nid >= 0x12) {
4868                         snd_hda_codec_write(codec, nid, 0,
4869                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
4870                                             i <= AUTO_PIN_FRONT_MIC ?
4871                                             PIN_VREF80 : PIN_IN);
4872                         if (nid != ALC260_PIN_CD_NID)
4873                                 snd_hda_codec_write(codec, nid, 0,
4874                                                     AC_VERB_SET_AMP_GAIN_MUTE,
4875                                                     AMP_OUT_MUTE);
4876                 }
4877         }
4878 }
4879
4880 /*
4881  * generic initialization of ADC, input mixers and output mixers
4882  */
4883 static struct hda_verb alc260_volume_init_verbs[] = {
4884         /*
4885          * Unmute ADC0-1 and set the default input to mic-in
4886          */
4887         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4888         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4889         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4890         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4891         
4892         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4893          * mixer widget
4894          * Note: PASD motherboards uses the Line In 2 as the input for
4895          * front panel mic (mic 2)
4896          */
4897         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
4898         /* mute analog inputs */
4899         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4900         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4901         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4902         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4903         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4904
4905         /*
4906          * Set up output mixers (0x08 - 0x0a)
4907          */
4908         /* set vol=0 to output mixers */
4909         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4910         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4911         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4912         /* set up input amps for analog loopback */
4913         /* Amp Indices: DAC = 0, mixer = 1 */
4914         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4915         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4916         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4917         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4918         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4919         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4920         
4921         { }
4922 };
4923
4924 static int alc260_parse_auto_config(struct hda_codec *codec)
4925 {
4926         struct alc_spec *spec = codec->spec;
4927         unsigned int wcap;
4928         int err;
4929         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
4930
4931         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
4932                                            alc260_ignore);
4933         if (err < 0)
4934                 return err;
4935         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
4936         if (err < 0)
4937                 return err;
4938         if (!spec->kctl_alloc)
4939                 return 0; /* can't find valid BIOS pin config */
4940         err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg);
4941         if (err < 0)
4942                 return err;
4943
4944         spec->multiout.max_channels = 2;
4945
4946         if (spec->autocfg.dig_out_pin)
4947                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
4948         if (spec->kctl_alloc)
4949                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
4950
4951         spec->init_verbs[spec->num_init_verbs++] = alc260_volume_init_verbs;
4952
4953         spec->num_mux_defs = 1;
4954         spec->input_mux = &spec->private_imux;
4955
4956         /* check whether NID 0x04 is valid */
4957         wcap = get_wcaps(codec, 0x04);
4958         wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */
4959         if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
4960                 spec->adc_nids = alc260_adc_nids_alt;
4961                 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
4962                 spec->mixers[spec->num_mixers] = alc260_capture_alt_mixer;
4963         } else {
4964                 spec->adc_nids = alc260_adc_nids;
4965                 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
4966                 spec->mixers[spec->num_mixers] = alc260_capture_mixer;
4967         }
4968         spec->num_mixers++;
4969
4970         return 1;
4971 }
4972
4973 /* additional initialization for auto-configuration model */
4974 static void alc260_auto_init(struct hda_codec *codec)
4975 {
4976         struct alc_spec *spec = codec->spec;
4977         alc260_auto_init_multi_out(codec);
4978         alc260_auto_init_analog_input(codec);
4979         if (spec->unsol_event)
4980                 alc_sku_automute(codec);
4981 }
4982
4983 #ifdef CONFIG_SND_HDA_POWER_SAVE
4984 static struct hda_amp_list alc260_loopbacks[] = {
4985         { 0x07, HDA_INPUT, 0 },
4986         { 0x07, HDA_INPUT, 1 },
4987         { 0x07, HDA_INPUT, 2 },
4988         { 0x07, HDA_INPUT, 3 },
4989         { 0x07, HDA_INPUT, 4 },
4990         { } /* end */
4991 };
4992 #endif
4993
4994 /*
4995  * ALC260 configurations
4996  */
4997 static const char *alc260_models[ALC260_MODEL_LAST] = {
4998         [ALC260_BASIC]          = "basic",
4999         [ALC260_HP]             = "hp",
5000         [ALC260_HP_3013]        = "hp-3013",
5001         [ALC260_FUJITSU_S702X]  = "fujitsu",
5002         [ALC260_ACER]           = "acer",
5003         [ALC260_WILL]           = "will",
5004         [ALC260_REPLACER_672V]  = "replacer",
5005 #ifdef CONFIG_SND_DEBUG
5006         [ALC260_TEST]           = "test",
5007 #endif
5008         [ALC260_AUTO]           = "auto",
5009 };
5010
5011 static struct snd_pci_quirk alc260_cfg_tbl[] = {
5012         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
5013         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
5014         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
5015         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013),
5016         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
5017         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP),
5018         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_3013),
5019         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
5020         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
5021         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
5022         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
5023         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
5024         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
5025         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
5026         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
5027         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
5028         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
5029         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
5030         {}
5031 };
5032
5033 static struct alc_config_preset alc260_presets[] = {
5034         [ALC260_BASIC] = {
5035                 .mixers = { alc260_base_output_mixer,
5036                             alc260_input_mixer,
5037                             alc260_pc_beep_mixer,
5038                             alc260_capture_mixer },
5039                 .init_verbs = { alc260_init_verbs },
5040                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5041                 .dac_nids = alc260_dac_nids,
5042                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5043                 .adc_nids = alc260_adc_nids,
5044                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5045                 .channel_mode = alc260_modes,
5046                 .input_mux = &alc260_capture_source,
5047         },
5048         [ALC260_HP] = {
5049                 .mixers = { alc260_hp_output_mixer,
5050                             alc260_input_mixer,
5051                             alc260_capture_alt_mixer },
5052                 .init_verbs = { alc260_init_verbs,
5053                                 alc260_hp_unsol_verbs },
5054                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5055                 .dac_nids = alc260_dac_nids,
5056                 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
5057                 .adc_nids = alc260_hp_adc_nids,
5058                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5059                 .channel_mode = alc260_modes,
5060                 .input_mux = &alc260_capture_source,
5061                 .unsol_event = alc260_hp_unsol_event,
5062                 .init_hook = alc260_hp_automute,
5063         },
5064         [ALC260_HP_3013] = {
5065                 .mixers = { alc260_hp_3013_mixer,
5066                             alc260_input_mixer,
5067                             alc260_capture_alt_mixer },
5068                 .init_verbs = { alc260_hp_3013_init_verbs,
5069                                 alc260_hp_3013_unsol_verbs },
5070                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5071                 .dac_nids = alc260_dac_nids,
5072                 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
5073                 .adc_nids = alc260_hp_adc_nids,
5074                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5075                 .channel_mode = alc260_modes,
5076                 .input_mux = &alc260_capture_source,
5077                 .unsol_event = alc260_hp_3013_unsol_event,
5078                 .init_hook = alc260_hp_3013_automute,
5079         },
5080         [ALC260_FUJITSU_S702X] = {
5081                 .mixers = { alc260_fujitsu_mixer,
5082                             alc260_capture_mixer },
5083                 .init_verbs = { alc260_fujitsu_init_verbs },
5084                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5085                 .dac_nids = alc260_dac_nids,
5086                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5087                 .adc_nids = alc260_dual_adc_nids,
5088                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5089                 .channel_mode = alc260_modes,
5090                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
5091                 .input_mux = alc260_fujitsu_capture_sources,
5092         },
5093         [ALC260_ACER] = {
5094                 .mixers = { alc260_acer_mixer,
5095                             alc260_capture_mixer },
5096                 .init_verbs = { alc260_acer_init_verbs },
5097                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5098                 .dac_nids = alc260_dac_nids,
5099                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5100                 .adc_nids = alc260_dual_adc_nids,
5101                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5102                 .channel_mode = alc260_modes,
5103                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
5104                 .input_mux = alc260_acer_capture_sources,
5105         },
5106         [ALC260_WILL] = {
5107                 .mixers = { alc260_will_mixer,
5108                             alc260_capture_mixer },
5109                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
5110                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5111                 .dac_nids = alc260_dac_nids,
5112                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5113                 .adc_nids = alc260_adc_nids,
5114                 .dig_out_nid = ALC260_DIGOUT_NID,
5115                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5116                 .channel_mode = alc260_modes,
5117                 .input_mux = &alc260_capture_source,
5118         },
5119         [ALC260_REPLACER_672V] = {
5120                 .mixers = { alc260_replacer_672v_mixer,
5121                             alc260_capture_mixer },
5122                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
5123                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5124                 .dac_nids = alc260_dac_nids,
5125                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5126                 .adc_nids = alc260_adc_nids,
5127                 .dig_out_nid = ALC260_DIGOUT_NID,
5128                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5129                 .channel_mode = alc260_modes,
5130                 .input_mux = &alc260_capture_source,
5131                 .unsol_event = alc260_replacer_672v_unsol_event,
5132                 .init_hook = alc260_replacer_672v_automute,
5133         },
5134 #ifdef CONFIG_SND_DEBUG
5135         [ALC260_TEST] = {
5136                 .mixers = { alc260_test_mixer,
5137                             alc260_capture_mixer },
5138                 .init_verbs = { alc260_test_init_verbs },
5139                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
5140                 .dac_nids = alc260_test_dac_nids,
5141                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
5142                 .adc_nids = alc260_test_adc_nids,
5143                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5144                 .channel_mode = alc260_modes,
5145                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
5146                 .input_mux = alc260_test_capture_sources,
5147         },
5148 #endif
5149 };
5150
5151 static int patch_alc260(struct hda_codec *codec)
5152 {
5153         struct alc_spec *spec;
5154         int err, board_config;
5155
5156         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5157         if (spec == NULL)
5158                 return -ENOMEM;
5159
5160         codec->spec = spec;
5161
5162         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
5163                                                   alc260_models,
5164                                                   alc260_cfg_tbl);
5165         if (board_config < 0) {
5166                 snd_printd(KERN_INFO "hda_codec: Unknown model for ALC260, "
5167                            "trying auto-probe from BIOS...\n");
5168                 board_config = ALC260_AUTO;
5169         }
5170
5171         if (board_config == ALC260_AUTO) {
5172                 /* automatic parse from the BIOS config */
5173                 err = alc260_parse_auto_config(codec);
5174                 if (err < 0) {
5175                         alc_free(codec);
5176                         return err;
5177                 } else if (!err) {
5178                         printk(KERN_INFO
5179                                "hda_codec: Cannot set up configuration "
5180                                "from BIOS.  Using base mode...\n");
5181                         board_config = ALC260_BASIC;
5182                 }
5183         }
5184
5185         if (board_config != ALC260_AUTO)
5186                 setup_preset(spec, &alc260_presets[board_config]);
5187
5188         spec->stream_name_analog = "ALC260 Analog";
5189         spec->stream_analog_playback = &alc260_pcm_analog_playback;
5190         spec->stream_analog_capture = &alc260_pcm_analog_capture;
5191
5192         spec->stream_name_digital = "ALC260 Digital";
5193         spec->stream_digital_playback = &alc260_pcm_digital_playback;
5194         spec->stream_digital_capture = &alc260_pcm_digital_capture;
5195
5196         spec->vmaster_nid = 0x08;
5197
5198         codec->patch_ops = alc_patch_ops;
5199         if (board_config == ALC260_AUTO)
5200                 spec->init_hook = alc260_auto_init;
5201 #ifdef CONFIG_SND_HDA_POWER_SAVE
5202         if (!spec->loopback.amplist)
5203                 spec->loopback.amplist = alc260_loopbacks;
5204 #endif
5205
5206         return 0;
5207 }
5208
5209
5210 /*
5211  * ALC882 support
5212  *
5213  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5214  * configuration.  Each pin widget can choose any input DACs and a mixer.
5215  * Each ADC is connected from a mixer of all inputs.  This makes possible
5216  * 6-channel independent captures.
5217  *
5218  * In addition, an independent DAC for the multi-playback (not used in this
5219  * driver yet).
5220  */
5221 #define ALC882_DIGOUT_NID       0x06
5222 #define ALC882_DIGIN_NID        0x0a
5223
5224 static struct hda_channel_mode alc882_ch_modes[1] = {
5225         { 8, NULL }
5226 };
5227
5228 static hda_nid_t alc882_dac_nids[4] = {
5229         /* front, rear, clfe, rear_surr */
5230         0x02, 0x03, 0x04, 0x05
5231 };
5232
5233 /* identical with ALC880 */
5234 #define alc882_adc_nids         alc880_adc_nids
5235 #define alc882_adc_nids_alt     alc880_adc_nids_alt
5236
5237 static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
5238 static hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 };
5239
5240 /* input MUX */
5241 /* FIXME: should be a matrix-type input source selection */
5242
5243 static struct hda_input_mux alc882_capture_source = {
5244         .num_items = 4,
5245         .items = {
5246                 { "Mic", 0x0 },
5247                 { "Front Mic", 0x1 },
5248                 { "Line", 0x2 },
5249                 { "CD", 0x4 },
5250         },
5251 };
5252 #define alc882_mux_enum_info alc_mux_enum_info
5253 #define alc882_mux_enum_get alc_mux_enum_get
5254
5255 static int alc882_mux_enum_put(struct snd_kcontrol *kcontrol,
5256                                struct snd_ctl_elem_value *ucontrol)
5257 {
5258         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5259         struct alc_spec *spec = codec->spec;
5260         const struct hda_input_mux *imux = spec->input_mux;
5261         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
5262         hda_nid_t nid = spec->capsrc_nids ?
5263                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
5264         unsigned int *cur_val = &spec->cur_mux[adc_idx];
5265         unsigned int i, idx;
5266
5267         idx = ucontrol->value.enumerated.item[0];
5268         if (idx >= imux->num_items)
5269                 idx = imux->num_items - 1;
5270         if (*cur_val == idx)
5271                 return 0;
5272         for (i = 0; i < imux->num_items; i++) {
5273                 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
5274                 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
5275                                          imux->items[i].index,
5276                                          HDA_AMP_MUTE, v);
5277         }
5278         *cur_val = idx;
5279         return 1;
5280 }
5281
5282 /*
5283  * 2ch mode
5284  */
5285 static struct hda_verb alc882_3ST_ch2_init[] = {
5286         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
5287         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5288         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5289         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5290         { } /* end */
5291 };
5292
5293 /*
5294  * 6ch mode
5295  */
5296 static struct hda_verb alc882_3ST_ch6_init[] = {
5297         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5298         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5299         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
5300         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5301         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5302         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5303         { } /* end */
5304 };
5305
5306 static struct hda_channel_mode alc882_3ST_6ch_modes[2] = {
5307         { 2, alc882_3ST_ch2_init },
5308         { 6, alc882_3ST_ch6_init },
5309 };
5310
5311 /*
5312  * 6ch mode
5313  */
5314 static struct hda_verb alc882_sixstack_ch6_init[] = {
5315         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
5316         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5317         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5318         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5319         { } /* end */
5320 };
5321
5322 /*
5323  * 8ch mode
5324  */
5325 static struct hda_verb alc882_sixstack_ch8_init[] = {
5326         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5327         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5328         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5329         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5330         { } /* end */
5331 };
5332
5333 static struct hda_channel_mode alc882_sixstack_modes[2] = {
5334         { 6, alc882_sixstack_ch6_init },
5335         { 8, alc882_sixstack_ch8_init },
5336 };
5337
5338 /*
5339  * macbook pro ALC885 can switch LineIn to LineOut without loosing Mic
5340  */
5341
5342 /*
5343  * 2ch mode
5344  */
5345 static struct hda_verb alc885_mbp_ch2_init[] = {
5346         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5347         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5348         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5349         { } /* end */
5350 };
5351
5352 /*
5353  * 6ch mode
5354  */
5355 static struct hda_verb alc885_mbp_ch6_init[] = {
5356         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5357         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5358         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5359         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5360         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5361         { } /* end */
5362 };
5363
5364 static struct hda_channel_mode alc885_mbp_6ch_modes[2] = {
5365         { 2, alc885_mbp_ch2_init },
5366         { 6, alc885_mbp_ch6_init },
5367 };
5368
5369
5370 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
5371  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
5372  */
5373 static struct snd_kcontrol_new alc882_base_mixer[] = {
5374         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5375         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5376         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
5377         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
5378         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
5379         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
5380         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
5381         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
5382         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
5383         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
5384         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5385         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5386         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5387         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5388         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5389         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5390         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5391         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5392         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5393         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5394         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5395         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5396         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5397         { } /* end */
5398 };
5399
5400 static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
5401         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
5402         HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
5403         HDA_CODEC_MUTE  ("Speaker Playback Switch", 0x14, 0x00, HDA_OUTPUT),
5404         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
5405         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5406         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5407         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
5408         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
5409         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
5410         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
5411         { } /* end */
5412 };
5413 static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
5414         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5415         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5416         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5417         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5418         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5419         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5420         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5421         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5422         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5423         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5424         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5425         { } /* end */
5426 };
5427
5428 static struct snd_kcontrol_new alc882_targa_mixer[] = {
5429         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5430         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5431         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5432         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5433         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5434         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5435         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5436         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5437         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5438         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5439         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5440         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5441         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5442         { } /* end */
5443 };
5444
5445 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
5446  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
5447  */
5448 static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
5449         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5450         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
5451         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5452         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
5453         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5454         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5455         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5456         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5457         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
5458         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
5459         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5460         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5461         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5462         { } /* end */
5463 };
5464
5465 static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
5466         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5467         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5468         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5469         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5470         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5471         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5472         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5473         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5474         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5475         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5476         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5477         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5478         { } /* end */
5479 };
5480
5481 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
5482         {
5483                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5484                 .name = "Channel Mode",
5485                 .info = alc_ch_mode_info,
5486                 .get = alc_ch_mode_get,
5487                 .put = alc_ch_mode_put,
5488         },
5489         { } /* end */
5490 };
5491
5492 static struct hda_verb alc882_init_verbs[] = {
5493         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5494         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5495         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5496         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5497         /* Rear mixer */
5498         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5499         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5500         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5501         /* CLFE mixer */
5502         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5503         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5504         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5505         /* Side mixer */
5506         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5507         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5508         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5509
5510         /* Front Pin: output 0 (0x0c) */
5511         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5512         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5513         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5514         /* Rear Pin: output 1 (0x0d) */
5515         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5516         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5517         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5518         /* CLFE Pin: output 2 (0x0e) */
5519         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5520         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5521         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
5522         /* Side Pin: output 3 (0x0f) */
5523         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5524         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5525         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
5526         /* Mic (rear) pin: input vref at 80% */
5527         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5528         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5529         /* Front Mic pin: input vref at 80% */
5530         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5531         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5532         /* Line In pin: input */
5533         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5534         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5535         /* Line-2 In: Headphone output (output 0 - 0x0c) */
5536         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5537         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5538         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
5539         /* CD pin widget for input */
5540         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5541
5542         /* FIXME: use matrix-type input source selection */
5543         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5544         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5545         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5546         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5547         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5548         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5549         /* Input mixer2 */
5550         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5551         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5552         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5553         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5554         /* Input mixer3 */
5555         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5556         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5557         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5558         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5559         /* ADC1: mute amp left and right */
5560         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5561         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5562         /* ADC2: mute amp left and right */
5563         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5564         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5565         /* ADC3: mute amp left and right */
5566         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5567         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5568
5569         { }
5570 };
5571
5572 static struct hda_verb alc882_eapd_verbs[] = {
5573         /* change to EAPD mode */
5574         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
5575         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
5576         { }
5577 };
5578
5579 /* Mac Pro test */
5580 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
5581         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5582         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5583         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
5584         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
5585         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
5586         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT),
5587         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT),
5588         { } /* end */
5589 };
5590
5591 static struct hda_verb alc882_macpro_init_verbs[] = {
5592         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5593         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5594         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5595         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5596         /* Front Pin: output 0 (0x0c) */
5597         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5598         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5599         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
5600         /* Front Mic pin: input vref at 80% */
5601         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5602         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5603         /* Speaker:  output */
5604         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5605         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5606         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
5607         /* Headphone output (output 0 - 0x0c) */
5608         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5609         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5610         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
5611
5612         /* FIXME: use matrix-type input source selection */
5613         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5614         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5615         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5616         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5617         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5618         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5619         /* Input mixer2 */
5620         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5621         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5622         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5623         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5624         /* Input mixer3 */
5625         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5626         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5627         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5628         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5629         /* ADC1: mute amp left and right */
5630         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5631         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5632         /* ADC2: mute amp left and right */
5633         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5634         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5635         /* ADC3: mute amp left and right */
5636         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5637         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5638
5639         { }
5640 };
5641
5642 /* Macbook Pro rev3 */
5643 static struct hda_verb alc885_mbp3_init_verbs[] = {
5644         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5645         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5646         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5647         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5648         /* Rear mixer */
5649         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5650         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5651         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5652         /* Front Pin: output 0 (0x0c) */
5653         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5654         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5655         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5656         /* HP Pin: output 0 (0x0d) */
5657         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
5658         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5659         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
5660         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5661         /* Mic (rear) pin: input vref at 80% */
5662         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5663         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5664         /* Front Mic pin: input vref at 80% */
5665         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5666         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5667         /* Line In pin: use output 1 when in LineOut mode */
5668         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5669         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5670         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
5671
5672         /* FIXME: use matrix-type input source selection */
5673         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5674         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5675         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5676         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5677         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5678         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5679         /* Input mixer2 */
5680         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5681         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5682         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5683         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5684         /* Input mixer3 */
5685         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5686         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5687         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5688         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5689         /* ADC1: mute amp left and right */
5690         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5691         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5692         /* ADC2: mute amp left and right */
5693         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5694         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5695         /* ADC3: mute amp left and right */
5696         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5697         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5698
5699         { }
5700 };
5701
5702 /* iMac 24 mixer. */
5703 static struct snd_kcontrol_new alc885_imac24_mixer[] = {
5704         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
5705         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
5706         { } /* end */
5707 };
5708
5709 /* iMac 24 init verbs. */
5710 static struct hda_verb alc885_imac24_init_verbs[] = {
5711         /* Internal speakers: output 0 (0x0c) */
5712         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5713         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5714         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
5715         /* Internal speakers: output 0 (0x0c) */
5716         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5717         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5718         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
5719         /* Headphone: output 0 (0x0c) */
5720         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5721         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5722         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5723         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5724         /* Front Mic: input vref at 80% */
5725         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5726         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5727         { }
5728 };
5729
5730 /* Toggle speaker-output according to the hp-jack state */
5731 static void alc885_imac24_automute(struct hda_codec *codec)
5732 {
5733         unsigned int present;
5734
5735         present = snd_hda_codec_read(codec, 0x14, 0,
5736                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5737         snd_hda_codec_amp_stereo(codec, 0x18, HDA_OUTPUT, 0,
5738                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5739         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
5740                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5741 }
5742
5743 /* Processes unsolicited events. */
5744 static void alc885_imac24_unsol_event(struct hda_codec *codec,
5745                                       unsigned int res)
5746 {
5747         /* Headphone insertion or removal. */
5748         if ((res >> 26) == ALC880_HP_EVENT)
5749                 alc885_imac24_automute(codec);
5750 }
5751
5752 static void alc885_mbp3_automute(struct hda_codec *codec)
5753 {
5754         unsigned int present;
5755
5756         present = snd_hda_codec_read(codec, 0x15, 0,
5757                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5758         snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
5759                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5760         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
5761                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
5762
5763 }
5764 static void alc885_mbp3_unsol_event(struct hda_codec *codec,
5765                                     unsigned int res)
5766 {
5767         /* Headphone insertion or removal. */
5768         if ((res >> 26) == ALC880_HP_EVENT)
5769                 alc885_mbp3_automute(codec);
5770 }
5771
5772
5773 static struct hda_verb alc882_targa_verbs[] = {
5774         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5775         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5776
5777         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5778         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5779         
5780         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
5781         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
5782         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5783
5784         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5785         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5786         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
5787         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
5788         { } /* end */
5789 };
5790
5791 /* toggle speaker-output according to the hp-jack state */
5792 static void alc882_targa_automute(struct hda_codec *codec)
5793 {
5794         unsigned int present;
5795  
5796         present = snd_hda_codec_read(codec, 0x14, 0,
5797                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5798         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
5799                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5800         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
5801                                   present ? 1 : 3);
5802 }
5803
5804 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
5805 {
5806         /* Looks like the unsol event is incompatible with the standard
5807          * definition.  4bit tag is placed at 26 bit!
5808          */
5809         if (((res >> 26) == ALC880_HP_EVENT)) {
5810                 alc882_targa_automute(codec);
5811         }
5812 }
5813
5814 static struct hda_verb alc882_asus_a7j_verbs[] = {
5815         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5816         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5817
5818         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5819         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5820         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5821         
5822         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5823         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5824         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5825
5826         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
5827         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
5828         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5829         { } /* end */
5830 };
5831
5832 static struct hda_verb alc882_asus_a7m_verbs[] = {
5833         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5834         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5835
5836         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5837         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5838         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5839         
5840         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5841         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5842         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5843
5844         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
5845         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
5846         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5847         { } /* end */
5848 };
5849
5850 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5851 {
5852         unsigned int gpiostate, gpiomask, gpiodir;
5853
5854         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5855                                        AC_VERB_GET_GPIO_DATA, 0);
5856
5857         if (!muted)
5858                 gpiostate |= (1 << pin);
5859         else
5860                 gpiostate &= ~(1 << pin);
5861
5862         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5863                                       AC_VERB_GET_GPIO_MASK, 0);
5864         gpiomask |= (1 << pin);
5865
5866         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5867                                      AC_VERB_GET_GPIO_DIRECTION, 0);
5868         gpiodir |= (1 << pin);
5869
5870
5871         snd_hda_codec_write(codec, codec->afg, 0,
5872                             AC_VERB_SET_GPIO_MASK, gpiomask);
5873         snd_hda_codec_write(codec, codec->afg, 0,
5874                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5875
5876         msleep(1);
5877
5878         snd_hda_codec_write(codec, codec->afg, 0,
5879                             AC_VERB_SET_GPIO_DATA, gpiostate);
5880 }
5881
5882 /* set up GPIO at initialization */
5883 static void alc885_macpro_init_hook(struct hda_codec *codec)
5884 {
5885         alc882_gpio_mute(codec, 0, 0);
5886         alc882_gpio_mute(codec, 1, 0);
5887 }
5888
5889 /* set up GPIO and update auto-muting at initialization */
5890 static void alc885_imac24_init_hook(struct hda_codec *codec)
5891 {
5892         alc885_macpro_init_hook(codec);
5893         alc885_imac24_automute(codec);
5894 }
5895
5896 /*
5897  * generic initialization of ADC, input mixers and output mixers
5898  */
5899 static struct hda_verb alc882_auto_init_verbs[] = {
5900         /*
5901          * Unmute ADC0-2 and set the default input to mic-in
5902          */
5903         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5904         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5905         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5906         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5907         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5908         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5909
5910         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5911          * mixer widget
5912          * Note: PASD motherboards uses the Line In 2 as the input for
5913          * front panel mic (mic 2)
5914          */
5915         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
5916         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5917         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5918         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5919         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5920         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5921
5922         /*
5923          * Set up output mixers (0x0c - 0x0f)
5924          */
5925         /* set vol=0 to output mixers */
5926         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5927         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5928         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5929         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5930         /* set up input amps for analog loopback */
5931         /* Amp Indices: DAC = 0, mixer = 1 */
5932         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5933         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5934         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5935         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5936         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5937         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5938         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5939         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5940         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5941         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5942
5943         /* FIXME: use matrix-type input source selection */
5944         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5945         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5946         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5947         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
5948         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
5949         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
5950         /* Input mixer2 */
5951         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5952         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
5953         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
5954         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
5955         /* Input mixer3 */
5956         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5957         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
5958         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
5959         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
5960
5961         { }
5962 };
5963
5964 /* capture mixer elements */
5965 static struct snd_kcontrol_new alc882_capture_alt_mixer[] = {
5966         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
5967         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
5968         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
5969         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
5970         {
5971                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5972                 /* The multiple "Capture Source" controls confuse alsamixer
5973                  * So call somewhat different..
5974                  */
5975                 /* .name = "Capture Source", */
5976                 .name = "Input Source",
5977                 .count = 2,
5978                 .info = alc882_mux_enum_info,
5979                 .get = alc882_mux_enum_get,
5980                 .put = alc882_mux_enum_put,
5981         },
5982         { } /* end */
5983 };
5984
5985 static struct snd_kcontrol_new alc882_capture_mixer[] = {
5986         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
5987         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
5988         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
5989         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
5990         HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
5991         HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
5992         {
5993                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5994                 /* The multiple "Capture Source" controls confuse alsamixer
5995                  * So call somewhat different..
5996                  */
5997                 /* .name = "Capture Source", */
5998                 .name = "Input Source",
5999                 .count = 3,
6000                 .info = alc882_mux_enum_info,
6001                 .get = alc882_mux_enum_get,
6002                 .put = alc882_mux_enum_put,
6003         },
6004         { } /* end */
6005 };
6006
6007 #ifdef CONFIG_SND_HDA_POWER_SAVE
6008 #define alc882_loopbacks        alc880_loopbacks
6009 #endif
6010
6011 /* pcm configuration: identiacal with ALC880 */
6012 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
6013 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
6014 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
6015 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
6016
6017 /*
6018  * configuration and preset
6019  */
6020 static const char *alc882_models[ALC882_MODEL_LAST] = {
6021         [ALC882_3ST_DIG]        = "3stack-dig",
6022         [ALC882_6ST_DIG]        = "6stack-dig",
6023         [ALC882_ARIMA]          = "arima",
6024         [ALC882_W2JC]           = "w2jc",
6025         [ALC882_TARGA]          = "targa",
6026         [ALC882_ASUS_A7J]       = "asus-a7j",
6027         [ALC882_ASUS_A7M]       = "asus-a7m",
6028         [ALC885_MACPRO]         = "macpro",
6029         [ALC885_MBP3]           = "mbp3",
6030         [ALC885_IMAC24]         = "imac24",
6031         [ALC882_AUTO]           = "auto",
6032 };
6033
6034 static struct snd_pci_quirk alc882_cfg_tbl[] = {
6035         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
6036         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
6037         SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
6038         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
6039         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
6040         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
6041         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
6042         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
6043         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),
6044         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
6045         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
6046         SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA),
6047         {}
6048 };
6049
6050 static struct alc_config_preset alc882_presets[] = {
6051         [ALC882_3ST_DIG] = {
6052                 .mixers = { alc882_base_mixer },
6053                 .init_verbs = { alc882_init_verbs },
6054                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6055                 .dac_nids = alc882_dac_nids,
6056                 .dig_out_nid = ALC882_DIGOUT_NID,
6057                 .dig_in_nid = ALC882_DIGIN_NID,
6058                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6059                 .channel_mode = alc882_ch_modes,
6060                 .need_dac_fix = 1,
6061                 .input_mux = &alc882_capture_source,
6062         },
6063         [ALC882_6ST_DIG] = {
6064                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6065                 .init_verbs = { alc882_init_verbs },
6066                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6067                 .dac_nids = alc882_dac_nids,
6068                 .dig_out_nid = ALC882_DIGOUT_NID,
6069                 .dig_in_nid = ALC882_DIGIN_NID,
6070                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6071                 .channel_mode = alc882_sixstack_modes,
6072                 .input_mux = &alc882_capture_source,
6073         },
6074         [ALC882_ARIMA] = {
6075                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6076                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs },
6077                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6078                 .dac_nids = alc882_dac_nids,
6079                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6080                 .channel_mode = alc882_sixstack_modes,
6081                 .input_mux = &alc882_capture_source,
6082         },
6083         [ALC882_W2JC] = {
6084                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
6085                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6086                                 alc880_gpio1_init_verbs },
6087                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6088                 .dac_nids = alc882_dac_nids,
6089                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6090                 .channel_mode = alc880_threestack_modes,
6091                 .need_dac_fix = 1,
6092                 .input_mux = &alc882_capture_source,
6093                 .dig_out_nid = ALC882_DIGOUT_NID,
6094         },
6095         [ALC885_MBP3] = {
6096                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
6097                 .init_verbs = { alc885_mbp3_init_verbs,
6098                                 alc880_gpio1_init_verbs },
6099                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6100                 .dac_nids = alc882_dac_nids,
6101                 .channel_mode = alc885_mbp_6ch_modes,
6102                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_6ch_modes),
6103                 .input_mux = &alc882_capture_source,
6104                 .dig_out_nid = ALC882_DIGOUT_NID,
6105                 .dig_in_nid = ALC882_DIGIN_NID,
6106                 .unsol_event = alc885_mbp3_unsol_event,
6107                 .init_hook = alc885_mbp3_automute,
6108         },
6109         [ALC885_MACPRO] = {
6110                 .mixers = { alc882_macpro_mixer },
6111                 .init_verbs = { alc882_macpro_init_verbs },
6112                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6113                 .dac_nids = alc882_dac_nids,
6114                 .dig_out_nid = ALC882_DIGOUT_NID,
6115                 .dig_in_nid = ALC882_DIGIN_NID,
6116                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6117                 .channel_mode = alc882_ch_modes,
6118                 .input_mux = &alc882_capture_source,
6119                 .init_hook = alc885_macpro_init_hook,
6120         },
6121         [ALC885_IMAC24] = {
6122                 .mixers = { alc885_imac24_mixer },
6123                 .init_verbs = { alc885_imac24_init_verbs },
6124                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6125                 .dac_nids = alc882_dac_nids,
6126                 .dig_out_nid = ALC882_DIGOUT_NID,
6127                 .dig_in_nid = ALC882_DIGIN_NID,
6128                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6129                 .channel_mode = alc882_ch_modes,
6130                 .input_mux = &alc882_capture_source,
6131                 .unsol_event = alc885_imac24_unsol_event,
6132                 .init_hook = alc885_imac24_init_hook,
6133         },
6134         [ALC882_TARGA] = {
6135                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer,
6136                             alc882_capture_mixer },
6137                 .init_verbs = { alc882_init_verbs, alc882_targa_verbs},
6138                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6139                 .dac_nids = alc882_dac_nids,
6140                 .dig_out_nid = ALC882_DIGOUT_NID,
6141                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6142                 .adc_nids = alc882_adc_nids,
6143                 .capsrc_nids = alc882_capsrc_nids,
6144                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6145                 .channel_mode = alc882_3ST_6ch_modes,
6146                 .need_dac_fix = 1,
6147                 .input_mux = &alc882_capture_source,
6148                 .unsol_event = alc882_targa_unsol_event,
6149                 .init_hook = alc882_targa_automute,
6150         },
6151         [ALC882_ASUS_A7J] = {
6152                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer,
6153                             alc882_capture_mixer },
6154                 .init_verbs = { alc882_init_verbs, alc882_asus_a7j_verbs},
6155                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6156                 .dac_nids = alc882_dac_nids,
6157                 .dig_out_nid = ALC882_DIGOUT_NID,
6158                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6159                 .adc_nids = alc882_adc_nids,
6160                 .capsrc_nids = alc882_capsrc_nids,
6161                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6162                 .channel_mode = alc882_3ST_6ch_modes,
6163                 .need_dac_fix = 1,
6164                 .input_mux = &alc882_capture_source,
6165         },      
6166         [ALC882_ASUS_A7M] = {
6167                 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
6168                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6169                                 alc880_gpio1_init_verbs,
6170                                 alc882_asus_a7m_verbs },
6171                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6172                 .dac_nids = alc882_dac_nids,
6173                 .dig_out_nid = ALC882_DIGOUT_NID,
6174                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6175                 .channel_mode = alc880_threestack_modes,
6176                 .need_dac_fix = 1,
6177                 .input_mux = &alc882_capture_source,
6178         },      
6179 };
6180
6181
6182 /*
6183  * Pin config fixes
6184  */
6185 enum { 
6186         PINFIX_ABIT_AW9D_MAX
6187 };
6188
6189 static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
6190         { 0x15, 0x01080104 }, /* side */
6191         { 0x16, 0x01011012 }, /* rear */
6192         { 0x17, 0x01016011 }, /* clfe */
6193         { }
6194 };
6195
6196 static const struct alc_pincfg *alc882_pin_fixes[] = {
6197         [PINFIX_ABIT_AW9D_MAX] = alc882_abit_aw9d_pinfix,
6198 };
6199
6200 static struct snd_pci_quirk alc882_pinfix_tbl[] = {
6201         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
6202         {}
6203 };
6204
6205 /*
6206  * BIOS auto configuration
6207  */
6208 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
6209                                               hda_nid_t nid, int pin_type,
6210                                               int dac_idx)
6211 {
6212         /* set as output */
6213         struct alc_spec *spec = codec->spec;
6214         int idx;
6215
6216         alc_set_pin_output(codec, nid, pin_type);
6217         if (spec->multiout.dac_nids[dac_idx] == 0x25)
6218                 idx = 4;
6219         else
6220                 idx = spec->multiout.dac_nids[dac_idx] - 2;
6221         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
6222
6223 }
6224
6225 static void alc882_auto_init_multi_out(struct hda_codec *codec)
6226 {
6227         struct alc_spec *spec = codec->spec;
6228         int i;
6229
6230         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
6231         for (i = 0; i <= HDA_SIDE; i++) {
6232                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
6233                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
6234                 if (nid)
6235                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
6236                                                           i);
6237         }
6238 }
6239
6240 static void alc882_auto_init_hp_out(struct hda_codec *codec)
6241 {
6242         struct alc_spec *spec = codec->spec;
6243         hda_nid_t pin;
6244
6245         pin = spec->autocfg.hp_pins[0];
6246         if (pin) /* connect to front */
6247                 /* use dac 0 */
6248                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
6249         pin = spec->autocfg.speaker_pins[0];
6250         if (pin)
6251                 alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
6252 }
6253
6254 #define alc882_is_input_pin(nid)        alc880_is_input_pin(nid)
6255 #define ALC882_PIN_CD_NID               ALC880_PIN_CD_NID
6256
6257 static void alc882_auto_init_analog_input(struct hda_codec *codec)
6258 {
6259         struct alc_spec *spec = codec->spec;
6260         int i;
6261
6262         for (i = 0; i < AUTO_PIN_LAST; i++) {
6263                 hda_nid_t nid = spec->autocfg.input_pins[i];
6264                 unsigned int vref;
6265                 if (!nid)
6266                         continue;
6267                 vref = PIN_IN;
6268                 if (1 /*i <= AUTO_PIN_FRONT_MIC*/) {
6269                         if (snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP) &
6270                             AC_PINCAP_VREF_80)
6271                                 vref = PIN_VREF80;
6272                 }
6273                 snd_hda_codec_write(codec, nid, 0,
6274                                     AC_VERB_SET_PIN_WIDGET_CONTROL, vref);
6275                 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
6276                         snd_hda_codec_write(codec, nid, 0,
6277                                             AC_VERB_SET_AMP_GAIN_MUTE,
6278                                             AMP_OUT_MUTE);
6279         }
6280 }
6281
6282 /* add mic boosts if needed */
6283 static int alc_auto_add_mic_boost(struct hda_codec *codec)
6284 {
6285         struct alc_spec *spec = codec->spec;
6286         int err;
6287         hda_nid_t nid;
6288
6289         nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
6290         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6291                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6292                                   "Mic Boost",
6293                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6294                 if (err < 0)
6295                         return err;
6296         }
6297         nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
6298         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6299                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6300                                   "Front Mic Boost",
6301                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6302                 if (err < 0)
6303                         return err;
6304         }
6305         return 0;
6306 }
6307
6308 /* almost identical with ALC880 parser... */
6309 static int alc882_parse_auto_config(struct hda_codec *codec)
6310 {
6311         struct alc_spec *spec = codec->spec;
6312         int err = alc880_parse_auto_config(codec);
6313
6314         if (err < 0)
6315                 return err;
6316         else if (!err)
6317                 return 0; /* no config found */
6318
6319         err = alc_auto_add_mic_boost(codec);
6320         if (err < 0)
6321                 return err;
6322
6323         /* hack - override the init verbs */
6324         spec->init_verbs[0] = alc882_auto_init_verbs;
6325
6326         return 1; /* config found */
6327 }
6328
6329 /* additional initialization for auto-configuration model */
6330 static void alc882_auto_init(struct hda_codec *codec)
6331 {
6332         struct alc_spec *spec = codec->spec;
6333         alc882_auto_init_multi_out(codec);
6334         alc882_auto_init_hp_out(codec);
6335         alc882_auto_init_analog_input(codec);
6336         if (spec->unsol_event)
6337                 alc_sku_automute(codec);
6338 }
6339
6340 static int patch_alc883(struct hda_codec *codec); /* called in patch_alc882() */
6341
6342 static int patch_alc882(struct hda_codec *codec)
6343 {
6344         struct alc_spec *spec;
6345         int err, board_config;
6346
6347         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6348         if (spec == NULL)
6349                 return -ENOMEM;
6350
6351         codec->spec = spec;
6352
6353         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
6354                                                   alc882_models,
6355                                                   alc882_cfg_tbl);
6356
6357         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
6358                 /* Pick up systems that don't supply PCI SSID */
6359                 switch (codec->subsystem_id) {
6360                 case 0x106b0c00: /* Mac Pro */
6361                         board_config = ALC885_MACPRO;
6362                         break;
6363                 case 0x106b1000: /* iMac 24 */
6364                         board_config = ALC885_IMAC24;
6365                         break;
6366                 case 0x106b00a1: /* Macbook */
6367                 case 0x106b2c00: /* Macbook Pro rev3 */
6368                         board_config = ALC885_MBP3;
6369                         break;
6370                 default:
6371                         /* ALC889A is handled better as ALC888-compatible */
6372                         if (codec->revision_id == 0x100103) {
6373                                 alc_free(codec);
6374                                 return patch_alc883(codec);
6375                         }
6376                         printk(KERN_INFO "hda_codec: Unknown model for ALC882, "
6377                                          "trying auto-probe from BIOS...\n");
6378                         board_config = ALC882_AUTO;
6379                 }
6380         }
6381
6382         alc_fix_pincfg(codec, alc882_pinfix_tbl, alc882_pin_fixes);
6383
6384         if (board_config == ALC882_AUTO) {
6385                 /* automatic parse from the BIOS config */
6386                 err = alc882_parse_auto_config(codec);
6387                 if (err < 0) {
6388                         alc_free(codec);
6389                         return err;
6390                 } else if (!err) {
6391                         printk(KERN_INFO
6392                                "hda_codec: Cannot set up configuration "
6393                                "from BIOS.  Using base mode...\n");
6394                         board_config = ALC882_3ST_DIG;
6395                 }
6396         }
6397
6398         if (board_config != ALC882_AUTO)
6399                 setup_preset(spec, &alc882_presets[board_config]);
6400
6401         spec->stream_name_analog = "ALC882 Analog";
6402         spec->stream_analog_playback = &alc882_pcm_analog_playback;
6403         spec->stream_analog_capture = &alc882_pcm_analog_capture;
6404         /* FIXME: setup DAC5 */
6405         /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
6406         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
6407
6408         spec->stream_name_digital = "ALC882 Digital";
6409         spec->stream_digital_playback = &alc882_pcm_digital_playback;
6410         spec->stream_digital_capture = &alc882_pcm_digital_capture;
6411
6412         if (!spec->adc_nids && spec->input_mux) {
6413                 /* check whether NID 0x07 is valid */
6414                 unsigned int wcap = get_wcaps(codec, 0x07);
6415                 /* get type */
6416                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
6417                 if (wcap != AC_WID_AUD_IN) {
6418                         spec->adc_nids = alc882_adc_nids_alt;
6419                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
6420                         spec->capsrc_nids = alc882_capsrc_nids_alt;
6421                         spec->mixers[spec->num_mixers] =
6422                                 alc882_capture_alt_mixer;
6423                         spec->num_mixers++;
6424                 } else {
6425                         spec->adc_nids = alc882_adc_nids;
6426                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
6427                         spec->capsrc_nids = alc882_capsrc_nids;
6428                         spec->mixers[spec->num_mixers] = alc882_capture_mixer;
6429                         spec->num_mixers++;
6430                 }
6431         }
6432
6433         spec->vmaster_nid = 0x0c;
6434
6435         codec->patch_ops = alc_patch_ops;
6436         if (board_config == ALC882_AUTO)
6437                 spec->init_hook = alc882_auto_init;
6438 #ifdef CONFIG_SND_HDA_POWER_SAVE
6439         if (!spec->loopback.amplist)
6440                 spec->loopback.amplist = alc882_loopbacks;
6441 #endif
6442
6443         return 0;
6444 }
6445
6446 /*
6447  * ALC883 support
6448  *
6449  * ALC883 is almost identical with ALC880 but has cleaner and more flexible
6450  * configuration.  Each pin widget can choose any input DACs and a mixer.
6451  * Each ADC is connected from a mixer of all inputs.  This makes possible
6452  * 6-channel independent captures.
6453  *
6454  * In addition, an independent DAC for the multi-playback (not used in this
6455  * driver yet).
6456  */
6457 #define ALC883_DIGOUT_NID       0x06
6458 #define ALC883_DIGIN_NID        0x0a
6459
6460 static hda_nid_t alc883_dac_nids[4] = {
6461         /* front, rear, clfe, rear_surr */
6462         0x02, 0x03, 0x04, 0x05
6463 };
6464
6465 static hda_nid_t alc883_adc_nids[2] = {
6466         /* ADC1-2 */
6467         0x08, 0x09,
6468 };
6469
6470 static hda_nid_t alc883_capsrc_nids[2] = { 0x23, 0x22 };
6471
6472 /* input MUX */
6473 /* FIXME: should be a matrix-type input source selection */
6474
6475 static struct hda_input_mux alc883_capture_source = {
6476         .num_items = 4,
6477         .items = {
6478                 { "Mic", 0x0 },
6479                 { "Front Mic", 0x1 },
6480                 { "Line", 0x2 },
6481                 { "CD", 0x4 },
6482         },
6483 };
6484
6485 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
6486         .num_items = 2,
6487         .items = {
6488                 { "Mic", 0x1 },
6489                 { "Line", 0x2 },
6490         },
6491 };
6492
6493 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
6494         .num_items = 4,
6495         .items = {
6496                 { "Mic", 0x0 },
6497                 { "iMic", 0x1 },
6498                 { "Line", 0x2 },
6499                 { "CD", 0x4 },
6500         },
6501 };
6502
6503 static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
6504         .num_items = 2,
6505         .items = {
6506                 { "Mic", 0x0 },
6507                 { "Int Mic", 0x1 },
6508         },
6509 };
6510
6511 #define alc883_mux_enum_info alc_mux_enum_info
6512 #define alc883_mux_enum_get alc_mux_enum_get
6513 /* ALC883 has the ALC882-type input selection */
6514 #define alc883_mux_enum_put alc882_mux_enum_put
6515
6516 /*
6517  * 2ch mode
6518  */
6519 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
6520         { 2, NULL }
6521 };
6522
6523 /*
6524  * 2ch mode
6525  */
6526 static struct hda_verb alc883_3ST_ch2_init[] = {
6527         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6528         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6529         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6530         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6531         { } /* end */
6532 };
6533
6534 /*
6535  * 4ch mode
6536  */
6537 static struct hda_verb alc883_3ST_ch4_init[] = {
6538         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6539         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6540         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6541         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6542         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6543         { } /* end */
6544 };
6545
6546 /*
6547  * 6ch mode
6548  */
6549 static struct hda_verb alc883_3ST_ch6_init[] = {
6550         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6551         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6552         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6553         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6554         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6555         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6556         { } /* end */
6557 };
6558
6559 static struct hda_channel_mode alc883_3ST_6ch_modes[3] = {
6560         { 2, alc883_3ST_ch2_init },
6561         { 4, alc883_3ST_ch4_init },
6562         { 6, alc883_3ST_ch6_init },
6563 };
6564
6565 /*
6566  * 6ch mode
6567  */
6568 static struct hda_verb alc883_sixstack_ch6_init[] = {
6569         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6570         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6571         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6572         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6573         { } /* end */
6574 };
6575
6576 /*
6577  * 8ch mode
6578  */
6579 static struct hda_verb alc883_sixstack_ch8_init[] = {
6580         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6581         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6582         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6583         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6584         { } /* end */
6585 };
6586
6587 static struct hda_channel_mode alc883_sixstack_modes[2] = {
6588         { 6, alc883_sixstack_ch6_init },
6589         { 8, alc883_sixstack_ch8_init },
6590 };
6591
6592 static struct hda_verb alc883_medion_eapd_verbs[] = {
6593         /* eanable EAPD on medion laptop */
6594         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
6595         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
6596         { }
6597 };
6598
6599 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
6600  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
6601  */
6602
6603 static struct snd_kcontrol_new alc883_base_mixer[] = {
6604         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6605         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6606         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6607         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6608         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6609         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6610         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6611         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6612         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6613         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6614         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6615         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6616         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6617         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6618         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6619         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6620         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6621         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6622         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6623         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6624         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6625         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6626         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6627         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6628         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6629         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6630         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6631         {
6632                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6633                 /* .name = "Capture Source", */
6634                 .name = "Input Source",
6635                 .count = 2,
6636                 .info = alc883_mux_enum_info,
6637                 .get = alc883_mux_enum_get,
6638                 .put = alc883_mux_enum_put,
6639         },
6640         { } /* end */
6641 };
6642
6643 static struct snd_kcontrol_new alc883_mitac_mixer[] = {
6644         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6645         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6646         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6647         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6648         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6649         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6650         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6651         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6652         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6653         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6654         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6655         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6656         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6657         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6658         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6659         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6660         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6661         {
6662                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6663                 /* .name = "Capture Source", */
6664                 .name = "Input Source",
6665                 .count = 2,
6666                 .info = alc883_mux_enum_info,
6667                 .get = alc883_mux_enum_get,
6668                 .put = alc883_mux_enum_put,
6669         },
6670         { } /* end */
6671 };
6672
6673 static struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
6674         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6675         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
6676         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6677         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
6678         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6679         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6680         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6681         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6682         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
6683         HDA_CODEC_MUTE("Int Mic 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_2ch_fujitsu_pi2515_mixer[] = {
6701         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6702         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
6703         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6704         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
6705         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6706         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6707         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6708         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6709         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
6710         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6711         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6712         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6713         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6714         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6715         {
6716                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6717                 /* .name = "Capture Source", */
6718                 .name = "Input Source",
6719                 .count = 2,
6720                 .info = alc883_mux_enum_info,
6721                 .get = alc883_mux_enum_get,
6722                 .put = alc883_mux_enum_put,
6723         },
6724         { } /* end */
6725 };
6726
6727 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
6728         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6729         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6730         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6731         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6732         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6733         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6734         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6735         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6736         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6737         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6738         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6739         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6740         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6741         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6742         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6743         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6744         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6745         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6746         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6747         {
6748                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6749                 /* .name = "Capture Source", */
6750                 .name = "Input Source",
6751                 .count = 2,
6752                 .info = alc883_mux_enum_info,
6753                 .get = alc883_mux_enum_get,
6754                 .put = alc883_mux_enum_put,
6755         },
6756         { } /* end */
6757 };
6758
6759 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
6760         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6761         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6762         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6763         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6764         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6765         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6766         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6767         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6768         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6769         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6770         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6771         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6772         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6773         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6774         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6775         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6776         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6777         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6778         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6779         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6780         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6781         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6782         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6783         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6784         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6785         {
6786                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6787                 /* .name = "Capture Source", */
6788                 .name = "Input Source",
6789                 .count = 2,
6790                 .info = alc883_mux_enum_info,
6791                 .get = alc883_mux_enum_get,
6792                 .put = alc883_mux_enum_put,
6793         },
6794         { } /* end */
6795 };
6796
6797 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
6798         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6799         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6800         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6801         HDA_CODEC_MUTE("Surround Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6802         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6803         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6804         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x16, 1, 0x0, HDA_OUTPUT),
6805         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
6806         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6807         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6808         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6809         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6810         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6811         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6812         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6813         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6814         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6815         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6816         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6817         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6818         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6819         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6820         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6821
6822         {
6823                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6824                 /* .name = "Capture Source", */
6825                 .name = "Input Source",
6826                 .count = 1,
6827                 .info = alc883_mux_enum_info,
6828                 .get = alc883_mux_enum_get,
6829                 .put = alc883_mux_enum_put,
6830         },
6831         { } /* end */
6832 };
6833
6834 static struct snd_kcontrol_new alc883_tagra_mixer[] = {
6835         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6836         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6837         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6838         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6839         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6840         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6841         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6842         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6843         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6844         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6845         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6846         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6847         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6848         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6849         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6850         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6851         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6852         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6853         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6854         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6855         {
6856                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6857                 /* .name = "Capture Source", */
6858                 .name = "Input Source",
6859                 .count = 2,
6860                 .info = alc883_mux_enum_info,
6861                 .get = alc883_mux_enum_get,
6862                 .put = alc883_mux_enum_put,
6863         },
6864         { } /* end */
6865 };
6866
6867 static struct snd_kcontrol_new alc883_tagra_2ch_mixer[] = {
6868         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6869         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6870         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6871         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6872         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6873         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6874         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6875         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6876         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6877         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
6878         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6879         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6880         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6881         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6882         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6883         {
6884                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6885                 /* .name = "Capture Source", */
6886                 .name = "Input Source",
6887                 .count = 2,
6888                 .info = alc883_mux_enum_info,
6889                 .get = alc883_mux_enum_get,
6890                 .put = alc883_mux_enum_put,
6891         },
6892         { } /* end */
6893 };
6894
6895 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
6896         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6897         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6898         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6899         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
6900         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6901         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6902         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6903         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6904         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6905         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6906         {
6907                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6908                 /* .name = "Capture Source", */
6909                 .name = "Input Source",
6910                 .count = 1,
6911                 .info = alc883_mux_enum_info,
6912                 .get = alc883_mux_enum_get,
6913                 .put = alc883_mux_enum_put,
6914         },
6915         { } /* end */
6916 };
6917
6918 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
6919         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6920         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
6921         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6922         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6923         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6924         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6925         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6926         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6927         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6928         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6929         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6930         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6931         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6932         {
6933                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6934                 /* .name = "Capture Source", */
6935                 .name = "Input Source",
6936                 .count = 2,
6937                 .info = alc883_mux_enum_info,
6938                 .get = alc883_mux_enum_get,
6939                 .put = alc883_mux_enum_put,
6940         },
6941         { } /* end */
6942 };
6943
6944 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
6945         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6946         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6947         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6948         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6949         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6950         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6951         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6952         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6953         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6954         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6955         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6956         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6957         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6958         {
6959                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6960                 /* .name = "Capture Source", */
6961                 .name = "Input Source",
6962                 .count = 2,
6963                 .info = alc883_mux_enum_info,
6964                 .get = alc883_mux_enum_get,
6965                 .put = alc883_mux_enum_put,
6966         },
6967         { } /* end */
6968 };      
6969
6970 static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
6971         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6972         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6973         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6974         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6975         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6976         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6977         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6978         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6979         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6980         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6981         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6982         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6983         {
6984                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6985                 /* .name = "Capture Source", */
6986                 .name = "Input Source",
6987                 .count = 2,
6988                 .info = alc883_mux_enum_info,
6989                 .get = alc883_mux_enum_get,
6990                 .put = alc883_mux_enum_put,
6991         },
6992         { } /* end */
6993 };
6994
6995 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
6996         {
6997                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6998                 .name = "Channel Mode",
6999                 .info = alc_ch_mode_info,
7000                 .get = alc_ch_mode_get,
7001                 .put = alc_ch_mode_put,
7002         },
7003         { } /* end */
7004 };
7005
7006 static struct hda_verb alc883_init_verbs[] = {
7007         /* ADC1: mute amp left and right */
7008         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7009         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7010         /* ADC2: mute amp left and right */
7011         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7012         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7013         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7014         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7015         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7016         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7017         /* Rear mixer */
7018         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7019         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7020         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7021         /* CLFE mixer */
7022         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7023         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7024         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7025         /* Side mixer */
7026         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7027         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7028         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7029
7030         /* mute analog input loopbacks */
7031         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7032         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7033         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7034         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7035         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7036
7037         /* Front Pin: output 0 (0x0c) */
7038         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7039         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7040         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7041         /* Rear Pin: output 1 (0x0d) */
7042         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7043         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7044         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7045         /* CLFE Pin: output 2 (0x0e) */
7046         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7047         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7048         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
7049         /* Side Pin: output 3 (0x0f) */
7050         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7051         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7052         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
7053         /* Mic (rear) pin: input vref at 80% */
7054         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7055         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7056         /* Front Mic pin: input vref at 80% */
7057         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7058         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7059         /* Line In pin: input */
7060         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7061         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7062         /* Line-2 In: Headphone output (output 0 - 0x0c) */
7063         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7064         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7065         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7066         /* CD pin widget for input */
7067         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7068
7069         /* FIXME: use matrix-type input source selection */
7070         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7071         /* Input mixer2 */
7072         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7073         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7074         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7075         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7076         /* Input mixer3 */
7077         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7078         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7079         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7080         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7081         { }
7082 };
7083
7084 /* toggle speaker-output according to the hp-jack state */
7085 static void alc883_mitac_hp_automute(struct hda_codec *codec)
7086 {
7087         unsigned int present;
7088
7089         present = snd_hda_codec_read(codec, 0x15, 0,
7090                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7091         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7092                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7093         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
7094                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7095 }
7096
7097 /* auto-toggle front mic */
7098 /*
7099 static void alc883_mitac_mic_automute(struct hda_codec *codec)
7100 {
7101         unsigned int present;
7102         unsigned char bits;
7103
7104         present = snd_hda_codec_read(codec, 0x18, 0,
7105                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7106         bits = present ? HDA_AMP_MUTE : 0;
7107         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
7108 }
7109 */
7110
7111 static void alc883_mitac_automute(struct hda_codec *codec)
7112 {
7113         alc883_mitac_hp_automute(codec);
7114         /* alc883_mitac_mic_automute(codec); */
7115 }
7116
7117 static void alc883_mitac_unsol_event(struct hda_codec *codec,
7118                                            unsigned int res)
7119 {
7120         switch (res >> 26) {
7121         case ALC880_HP_EVENT:
7122                 alc883_mitac_hp_automute(codec);
7123                 break;
7124         case ALC880_MIC_EVENT:
7125                 /* alc883_mitac_mic_automute(codec); */
7126                 break;
7127         }
7128 }
7129
7130 static struct hda_verb alc883_mitac_verbs[] = {
7131         /* HP */
7132         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7133         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7134         /* Subwoofer */
7135         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
7136         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7137
7138         /* enable unsolicited event */
7139         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7140         /* {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN}, */
7141
7142         { } /* end */
7143 };
7144
7145 static struct hda_verb alc883_clevo_m720_verbs[] = {
7146         /* HP */
7147         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7148         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7149         /* Int speaker */
7150         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
7151         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7152
7153         /* enable unsolicited event */
7154         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7155         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
7156
7157         { } /* end */
7158 };
7159
7160 static struct hda_verb alc883_2ch_fujitsu_pi2515_verbs[] = {
7161         /* HP */
7162         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7163         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7164         /* Subwoofer */
7165         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7166         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7167
7168         /* enable unsolicited event */
7169         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7170
7171         { } /* end */
7172 };
7173
7174 static struct hda_verb alc883_tagra_verbs[] = {
7175         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7176         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7177
7178         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7179         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7180         
7181         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7182         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7183         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7184
7185         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7186         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
7187         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
7188         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
7189
7190         { } /* end */
7191 };
7192
7193 static struct hda_verb alc883_lenovo_101e_verbs[] = {
7194         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7195         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
7196         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
7197         { } /* end */
7198 };
7199
7200 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
7201         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7202         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7203         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7204         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7205         { } /* end */
7206 };
7207
7208 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
7209         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7210         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7211         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7212         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
7213         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
7214         { } /* end */
7215 };
7216
7217 static struct hda_verb alc883_haier_w66_verbs[] = {
7218         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7219         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7220
7221         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7222
7223         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7224         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7225         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7226         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7227         { } /* end */
7228 };
7229
7230 static struct hda_verb alc888_3st_hp_verbs[] = {
7231         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
7232         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
7233         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
7234         { }
7235 };
7236
7237 static struct hda_verb alc888_6st_dell_verbs[] = {
7238         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7239         { }
7240 };
7241
7242 static struct hda_verb alc888_3st_hp_2ch_init[] = {
7243         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7244         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7245         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7246         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7247         { }
7248 };
7249
7250 static struct hda_verb alc888_3st_hp_6ch_init[] = {
7251         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7252         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7253         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7254         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7255         { }
7256 };
7257
7258 static struct hda_channel_mode alc888_3st_hp_modes[2] = {
7259         { 2, alc888_3st_hp_2ch_init },
7260         { 6, alc888_3st_hp_6ch_init },
7261 };
7262
7263 /* toggle front-jack and RCA according to the hp-jack state */
7264 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
7265 {
7266         unsigned int present;
7267  
7268         present = snd_hda_codec_read(codec, 0x1b, 0,
7269                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7270         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7271                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7272         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7273                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7274 }
7275
7276 /* toggle RCA according to the front-jack state */
7277 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
7278 {
7279         unsigned int present;
7280  
7281         present = snd_hda_codec_read(codec, 0x14, 0,
7282                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7283         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7284                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7285 }
7286
7287 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
7288                                              unsigned int res)
7289 {
7290         if ((res >> 26) == ALC880_HP_EVENT)
7291                 alc888_lenovo_ms7195_front_automute(codec);
7292         if ((res >> 26) == ALC880_FRONT_EVENT)
7293                 alc888_lenovo_ms7195_rca_automute(codec);
7294 }
7295
7296 static struct hda_verb alc883_medion_md2_verbs[] = {
7297         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7298         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7299
7300         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7301
7302         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7303         { } /* end */
7304 };
7305
7306 /* toggle speaker-output according to the hp-jack state */
7307 static void alc883_medion_md2_automute(struct hda_codec *codec)
7308 {
7309         unsigned int present;
7310  
7311         present = snd_hda_codec_read(codec, 0x14, 0,
7312                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7313         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7314                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7315 }
7316
7317 static void alc883_medion_md2_unsol_event(struct hda_codec *codec,
7318                                           unsigned int res)
7319 {
7320         if ((res >> 26) == ALC880_HP_EVENT)
7321                 alc883_medion_md2_automute(codec);
7322 }
7323
7324 /* toggle speaker-output according to the hp-jack state */
7325 static void alc883_tagra_automute(struct hda_codec *codec)
7326 {
7327         unsigned int present;
7328         unsigned char bits;
7329
7330         present = snd_hda_codec_read(codec, 0x14, 0,
7331                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7332         bits = present ? HDA_AMP_MUTE : 0;
7333         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
7334                                  HDA_AMP_MUTE, bits);
7335         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
7336                                   present ? 1 : 3);
7337 }
7338
7339 static void alc883_tagra_unsol_event(struct hda_codec *codec, unsigned int res)
7340 {
7341         if ((res >> 26) == ALC880_HP_EVENT)
7342                 alc883_tagra_automute(codec);
7343 }
7344
7345 /* toggle speaker-output according to the hp-jack state */
7346 static void alc883_clevo_m720_hp_automute(struct hda_codec *codec)
7347 {
7348         unsigned int present;
7349         unsigned char bits;
7350
7351         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
7352                 & AC_PINSENSE_PRESENCE;
7353         bits = present ? HDA_AMP_MUTE : 0;
7354         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7355                                  HDA_AMP_MUTE, bits);
7356 }
7357
7358 static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
7359 {
7360         unsigned int present;
7361
7362         present = snd_hda_codec_read(codec, 0x18, 0,
7363                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7364         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
7365                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7366 }
7367
7368 static void alc883_clevo_m720_automute(struct hda_codec *codec)
7369 {
7370         alc883_clevo_m720_hp_automute(codec);
7371         alc883_clevo_m720_mic_automute(codec);
7372 }
7373
7374 static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
7375                                            unsigned int res)
7376 {
7377         switch (res >> 26) {
7378         case ALC880_HP_EVENT:
7379                 alc883_clevo_m720_hp_automute(codec);
7380                 break;
7381         case ALC880_MIC_EVENT:
7382                 alc883_clevo_m720_mic_automute(codec);
7383                 break;
7384         }
7385 }
7386
7387 /* toggle speaker-output according to the hp-jack state */
7388 static void alc883_2ch_fujitsu_pi2515_automute(struct hda_codec *codec)
7389 {
7390         unsigned int present;
7391         unsigned char bits;
7392
7393         present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
7394                 & AC_PINSENSE_PRESENCE;
7395         bits = present ? HDA_AMP_MUTE : 0;
7396         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7397                                  HDA_AMP_MUTE, bits);
7398 }
7399
7400 static void alc883_2ch_fujitsu_pi2515_unsol_event(struct hda_codec *codec,
7401                                                   unsigned int res)
7402 {
7403         if ((res >> 26) == ALC880_HP_EVENT)
7404                 alc883_2ch_fujitsu_pi2515_automute(codec);
7405 }
7406
7407 static void alc883_haier_w66_automute(struct hda_codec *codec)
7408 {
7409         unsigned int present;
7410         unsigned char bits;
7411
7412         present = snd_hda_codec_read(codec, 0x1b, 0,
7413                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7414         bits = present ? 0x80 : 0;
7415         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7416                                  0x80, bits);
7417 }
7418
7419 static void alc883_haier_w66_unsol_event(struct hda_codec *codec,
7420                                          unsigned int res)
7421 {
7422         if ((res >> 26) == ALC880_HP_EVENT)
7423                 alc883_haier_w66_automute(codec);
7424 }
7425
7426 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
7427 {
7428         unsigned int present;
7429         unsigned char bits;
7430
7431         present = snd_hda_codec_read(codec, 0x14, 0,
7432                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7433         bits = present ? HDA_AMP_MUTE : 0;
7434         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7435                                  HDA_AMP_MUTE, bits);
7436 }
7437
7438 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
7439 {
7440         unsigned int present;
7441         unsigned char bits;
7442
7443         present = snd_hda_codec_read(codec, 0x1b, 0,
7444                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7445         bits = present ? HDA_AMP_MUTE : 0;
7446         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7447                                  HDA_AMP_MUTE, bits);
7448         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7449                                  HDA_AMP_MUTE, bits);
7450 }
7451
7452 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
7453                                            unsigned int res)
7454 {
7455         if ((res >> 26) == ALC880_HP_EVENT)
7456                 alc883_lenovo_101e_all_automute(codec);
7457         if ((res >> 26) == ALC880_FRONT_EVENT)
7458                 alc883_lenovo_101e_ispeaker_automute(codec);
7459 }
7460
7461 /* toggle speaker-output according to the hp-jack state */
7462 static void alc883_acer_aspire_automute(struct hda_codec *codec)
7463 {
7464         unsigned int present;
7465  
7466         present = snd_hda_codec_read(codec, 0x14, 0,
7467                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7468         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7469                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7470         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
7471                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7472 }
7473
7474 static void alc883_acer_aspire_unsol_event(struct hda_codec *codec,
7475                                            unsigned int res)
7476 {
7477         if ((res >> 26) == ALC880_HP_EVENT)
7478                 alc883_acer_aspire_automute(codec);
7479 }
7480
7481 static struct hda_verb alc883_acer_eapd_verbs[] = {
7482         /* HP Pin: output 0 (0x0c) */
7483         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7484         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7485         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7486         /* Front Pin: output 0 (0x0c) */
7487         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7488         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7489         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7490         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
7491         /* eanable EAPD on medion laptop */
7492         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7493         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
7494         /* enable unsolicited event */
7495         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7496         { }
7497 };
7498
7499 static void alc888_6st_dell_front_automute(struct hda_codec *codec)
7500 {
7501         unsigned int present;
7502  
7503         present = snd_hda_codec_read(codec, 0x1b, 0,
7504                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7505         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7506                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7507         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7508                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7509         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
7510                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7511         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
7512                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7513 }
7514
7515 static void alc888_6st_dell_unsol_event(struct hda_codec *codec,
7516                                              unsigned int res)
7517 {
7518         switch (res >> 26) {
7519         case ALC880_HP_EVENT:
7520                 printk("hp_event\n");
7521                 alc888_6st_dell_front_automute(codec);
7522                 break;
7523         }
7524 }
7525
7526 /*
7527  * generic initialization of ADC, input mixers and output mixers
7528  */
7529 static struct hda_verb alc883_auto_init_verbs[] = {
7530         /*
7531          * Unmute ADC0-2 and set the default input to mic-in
7532          */
7533         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7534         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7535         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7536         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7537
7538         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
7539          * mixer widget
7540          * Note: PASD motherboards uses the Line In 2 as the input for
7541          * front panel mic (mic 2)
7542          */
7543         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
7544         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7545         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7546         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7547         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7548         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7549
7550         /*
7551          * Set up output mixers (0x0c - 0x0f)
7552          */
7553         /* set vol=0 to output mixers */
7554         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7555         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7556         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7557         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7558         /* set up input amps for analog loopback */
7559         /* Amp Indices: DAC = 0, mixer = 1 */
7560         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7561         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7562         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7563         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7564         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7565         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7566         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7567         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7568         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7569         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7570
7571         /* FIXME: use matrix-type input source selection */
7572         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7573         /* Input mixer1 */
7574         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7575         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7576         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7577         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
7578         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7579         /* Input mixer2 */
7580         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7581         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7582         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7583         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
7584         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7585
7586         { }
7587 };
7588
7589 /* capture mixer elements */
7590 static struct snd_kcontrol_new alc883_capture_mixer[] = {
7591         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7592         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7593         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7594         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7595         {
7596                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7597                 /* The multiple "Capture Source" controls confuse alsamixer
7598                  * So call somewhat different..
7599                  */
7600                 /* .name = "Capture Source", */
7601                 .name = "Input Source",
7602                 .count = 2,
7603                 .info = alc882_mux_enum_info,
7604                 .get = alc882_mux_enum_get,
7605                 .put = alc882_mux_enum_put,
7606         },
7607         { } /* end */
7608 };
7609
7610 #ifdef CONFIG_SND_HDA_POWER_SAVE
7611 #define alc883_loopbacks        alc880_loopbacks
7612 #endif
7613
7614 /* pcm configuration: identiacal with ALC880 */
7615 #define alc883_pcm_analog_playback      alc880_pcm_analog_playback
7616 #define alc883_pcm_analog_capture       alc880_pcm_analog_capture
7617 #define alc883_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
7618 #define alc883_pcm_digital_playback     alc880_pcm_digital_playback
7619 #define alc883_pcm_digital_capture      alc880_pcm_digital_capture
7620
7621 /*
7622  * configuration and preset
7623  */
7624 static const char *alc883_models[ALC883_MODEL_LAST] = {
7625         [ALC883_3ST_2ch_DIG]    = "3stack-dig",
7626         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
7627         [ALC883_3ST_6ch]        = "3stack-6ch",
7628         [ALC883_6ST_DIG]        = "6stack-dig",
7629         [ALC883_TARGA_DIG]      = "targa-dig",
7630         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
7631         [ALC883_ACER]           = "acer",
7632         [ALC883_ACER_ASPIRE]    = "acer-aspire",
7633         [ALC883_MEDION]         = "medion",
7634         [ALC883_MEDION_MD2]     = "medion-md2",
7635         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
7636         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
7637         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
7638         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
7639         [ALC883_HAIER_W66]      = "haier-w66",
7640         [ALC888_3ST_HP]         = "3stack-hp",
7641         [ALC888_6ST_DELL]       = "6stack-dell",
7642         [ALC883_MITAC]          = "mitac",
7643         [ALC883_CLEVO_M720]     = "clevo-m720",
7644         [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
7645         [ALC883_AUTO]           = "auto",
7646 };
7647
7648 static struct snd_pci_quirk alc883_cfg_tbl[] = {
7649         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG),
7650         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
7651         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
7652         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
7653         SND_PCI_QUIRK(0x1025, 0, "Acer laptop", ALC883_ACER), /* default Acer */
7654         SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
7655         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
7656         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
7657         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
7658         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
7659         SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
7660         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
7661         SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
7662         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
7663         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
7664         SND_PCI_QUIRK(0x1458, 0xa002, "MSI", ALC883_6ST_DIG),
7665         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
7666         SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
7667         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
7668         SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC883_TARGA_2ch_DIG),
7669         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
7670         SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
7671         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
7672         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
7673         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
7674         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
7675         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
7676         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
7677         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
7678         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
7679         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
7680         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
7681         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
7682         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
7683         SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG),
7684         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
7685         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
7686         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
7687         SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
7688         SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
7689         SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
7690         SND_PCI_QUIRK(0x1558, 0, "Clevo laptop", ALC883_LAPTOP_EAPD),
7691         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
7692         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
7693         SND_PCI_QUIRK(0x1734, 0x1108, "Fujitsu AMILO Pi2515", ALC883_FUJITSU_PI2515),
7694         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
7695         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
7696         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
7697         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
7698         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
7699         SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
7700         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
7701         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
7702         {}
7703 };
7704
7705 static struct alc_config_preset alc883_presets[] = {
7706         [ALC883_3ST_2ch_DIG] = {
7707                 .mixers = { alc883_3ST_2ch_mixer },
7708                 .init_verbs = { alc883_init_verbs },
7709                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7710                 .dac_nids = alc883_dac_nids,
7711                 .dig_out_nid = ALC883_DIGOUT_NID,
7712                 .dig_in_nid = ALC883_DIGIN_NID,
7713                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7714                 .channel_mode = alc883_3ST_2ch_modes,
7715                 .input_mux = &alc883_capture_source,
7716         },
7717         [ALC883_3ST_6ch_DIG] = {
7718                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
7719                 .init_verbs = { alc883_init_verbs },
7720                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7721                 .dac_nids = alc883_dac_nids,
7722                 .dig_out_nid = ALC883_DIGOUT_NID,
7723                 .dig_in_nid = ALC883_DIGIN_NID,
7724                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7725                 .channel_mode = alc883_3ST_6ch_modes,
7726                 .need_dac_fix = 1,
7727                 .input_mux = &alc883_capture_source,
7728         },
7729         [ALC883_3ST_6ch] = {
7730                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
7731                 .init_verbs = { alc883_init_verbs },
7732                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7733                 .dac_nids = alc883_dac_nids,
7734                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7735                 .channel_mode = alc883_3ST_6ch_modes,
7736                 .need_dac_fix = 1,
7737                 .input_mux = &alc883_capture_source,
7738         },
7739         [ALC883_6ST_DIG] = {
7740                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
7741                 .init_verbs = { alc883_init_verbs },
7742                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7743                 .dac_nids = alc883_dac_nids,
7744                 .dig_out_nid = ALC883_DIGOUT_NID,
7745                 .dig_in_nid = ALC883_DIGIN_NID,
7746                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7747                 .channel_mode = alc883_sixstack_modes,
7748                 .input_mux = &alc883_capture_source,
7749         },
7750         [ALC883_TARGA_DIG] = {
7751                 .mixers = { alc883_tagra_mixer, alc883_chmode_mixer },
7752                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
7753                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7754                 .dac_nids = alc883_dac_nids,
7755                 .dig_out_nid = ALC883_DIGOUT_NID,
7756                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7757                 .channel_mode = alc883_3ST_6ch_modes,
7758                 .need_dac_fix = 1,
7759                 .input_mux = &alc883_capture_source,
7760                 .unsol_event = alc883_tagra_unsol_event,
7761                 .init_hook = alc883_tagra_automute,
7762         },
7763         [ALC883_TARGA_2ch_DIG] = {
7764                 .mixers = { alc883_tagra_2ch_mixer},
7765                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
7766                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7767                 .dac_nids = alc883_dac_nids,
7768                 .dig_out_nid = ALC883_DIGOUT_NID,
7769                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7770                 .channel_mode = alc883_3ST_2ch_modes,
7771                 .input_mux = &alc883_capture_source,
7772                 .unsol_event = alc883_tagra_unsol_event,
7773                 .init_hook = alc883_tagra_automute,
7774         },
7775         [ALC883_ACER] = {
7776                 .mixers = { alc883_base_mixer },
7777                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
7778                  * and the headphone jack.  Turn this on and rely on the
7779                  * standard mute methods whenever the user wants to turn
7780                  * these outputs off.
7781                  */
7782                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
7783                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7784                 .dac_nids = alc883_dac_nids,
7785                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7786                 .channel_mode = alc883_3ST_2ch_modes,
7787                 .input_mux = &alc883_capture_source,
7788         },
7789         [ALC883_ACER_ASPIRE] = {
7790                 .mixers = { alc883_acer_aspire_mixer },
7791                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
7792                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7793                 .dac_nids = alc883_dac_nids,
7794                 .dig_out_nid = ALC883_DIGOUT_NID,
7795                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7796                 .channel_mode = alc883_3ST_2ch_modes,
7797                 .input_mux = &alc883_capture_source,
7798                 .unsol_event = alc883_acer_aspire_unsol_event,
7799                 .init_hook = alc883_acer_aspire_automute,
7800         },
7801         [ALC883_MEDION] = {
7802                 .mixers = { alc883_fivestack_mixer,
7803                             alc883_chmode_mixer },
7804                 .init_verbs = { alc883_init_verbs,
7805                                 alc883_medion_eapd_verbs },
7806                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7807                 .dac_nids = alc883_dac_nids,
7808                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7809                 .channel_mode = alc883_sixstack_modes,
7810                 .input_mux = &alc883_capture_source,
7811         },
7812         [ALC883_MEDION_MD2] = {
7813                 .mixers = { alc883_medion_md2_mixer},
7814                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
7815                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7816                 .dac_nids = alc883_dac_nids,
7817                 .dig_out_nid = ALC883_DIGOUT_NID,
7818                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7819                 .channel_mode = alc883_3ST_2ch_modes,
7820                 .input_mux = &alc883_capture_source,
7821                 .unsol_event = alc883_medion_md2_unsol_event,
7822                 .init_hook = alc883_medion_md2_automute,
7823         },      
7824         [ALC883_LAPTOP_EAPD] = {
7825                 .mixers = { alc883_base_mixer },
7826                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
7827                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7828                 .dac_nids = alc883_dac_nids,
7829                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7830                 .channel_mode = alc883_3ST_2ch_modes,
7831                 .input_mux = &alc883_capture_source,
7832         },
7833         [ALC883_CLEVO_M720] = {
7834                 .mixers = { alc883_clevo_m720_mixer },
7835                 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
7836                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7837                 .dac_nids = alc883_dac_nids,
7838                 .dig_out_nid = ALC883_DIGOUT_NID,
7839                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7840                 .channel_mode = alc883_3ST_2ch_modes,
7841                 .input_mux = &alc883_capture_source,
7842                 .unsol_event = alc883_clevo_m720_unsol_event,
7843                 .init_hook = alc883_clevo_m720_automute,
7844         },
7845         [ALC883_LENOVO_101E_2ch] = {
7846                 .mixers = { alc883_lenovo_101e_2ch_mixer},
7847                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
7848                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7849                 .dac_nids = alc883_dac_nids,
7850                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7851                 .channel_mode = alc883_3ST_2ch_modes,
7852                 .input_mux = &alc883_lenovo_101e_capture_source,
7853                 .unsol_event = alc883_lenovo_101e_unsol_event,
7854                 .init_hook = alc883_lenovo_101e_all_automute,
7855         },
7856         [ALC883_LENOVO_NB0763] = {
7857                 .mixers = { alc883_lenovo_nb0763_mixer },
7858                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
7859                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7860                 .dac_nids = alc883_dac_nids,
7861                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7862                 .channel_mode = alc883_3ST_2ch_modes,
7863                 .need_dac_fix = 1,
7864                 .input_mux = &alc883_lenovo_nb0763_capture_source,
7865                 .unsol_event = alc883_medion_md2_unsol_event,
7866                 .init_hook = alc883_medion_md2_automute,
7867         },
7868         [ALC888_LENOVO_MS7195_DIG] = {
7869                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
7870                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
7871                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7872                 .dac_nids = alc883_dac_nids,
7873                 .dig_out_nid = ALC883_DIGOUT_NID,
7874                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7875                 .channel_mode = alc883_3ST_6ch_modes,
7876                 .need_dac_fix = 1,
7877                 .input_mux = &alc883_capture_source,
7878                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
7879                 .init_hook = alc888_lenovo_ms7195_front_automute,
7880         },
7881         [ALC883_HAIER_W66] = {
7882                 .mixers = { alc883_tagra_2ch_mixer},
7883                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
7884                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7885                 .dac_nids = alc883_dac_nids,
7886                 .dig_out_nid = ALC883_DIGOUT_NID,
7887                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7888                 .channel_mode = alc883_3ST_2ch_modes,
7889                 .input_mux = &alc883_capture_source,
7890                 .unsol_event = alc883_haier_w66_unsol_event,
7891                 .init_hook = alc883_haier_w66_automute,
7892         },
7893         [ALC888_3ST_HP] = {
7894                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
7895                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
7896                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7897                 .dac_nids = alc883_dac_nids,
7898                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
7899                 .channel_mode = alc888_3st_hp_modes,
7900                 .need_dac_fix = 1,
7901                 .input_mux = &alc883_capture_source,
7902         },
7903         [ALC888_6ST_DELL] = {
7904                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
7905                 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
7906                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7907                 .dac_nids = alc883_dac_nids,
7908                 .dig_out_nid = ALC883_DIGOUT_NID,
7909                 .dig_in_nid = ALC883_DIGIN_NID,
7910                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7911                 .channel_mode = alc883_sixstack_modes,
7912                 .input_mux = &alc883_capture_source,
7913                 .unsol_event = alc888_6st_dell_unsol_event,
7914                 .init_hook = alc888_6st_dell_front_automute,
7915         },
7916         [ALC883_MITAC] = {
7917                 .mixers = { alc883_mitac_mixer },
7918                 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
7919                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7920                 .dac_nids = alc883_dac_nids,
7921                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7922                 .channel_mode = alc883_3ST_2ch_modes,
7923                 .input_mux = &alc883_capture_source,
7924                 .unsol_event = alc883_mitac_unsol_event,
7925                 .init_hook = alc883_mitac_automute,
7926         },
7927         [ALC883_FUJITSU_PI2515] = {
7928                 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
7929                 .init_verbs = { alc883_init_verbs,
7930                                 alc883_2ch_fujitsu_pi2515_verbs},
7931                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7932                 .dac_nids = alc883_dac_nids,
7933                 .dig_out_nid = ALC883_DIGOUT_NID,
7934                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7935                 .channel_mode = alc883_3ST_2ch_modes,
7936                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
7937                 .unsol_event = alc883_2ch_fujitsu_pi2515_unsol_event,
7938                 .init_hook = alc883_2ch_fujitsu_pi2515_automute,
7939         },
7940 };
7941
7942
7943 /*
7944  * BIOS auto configuration
7945  */
7946 static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
7947                                               hda_nid_t nid, int pin_type,
7948                                               int dac_idx)
7949 {
7950         /* set as output */
7951         struct alc_spec *spec = codec->spec;
7952         int idx;
7953
7954         alc_set_pin_output(codec, nid, pin_type);
7955         if (spec->multiout.dac_nids[dac_idx] == 0x25)
7956                 idx = 4;
7957         else
7958                 idx = spec->multiout.dac_nids[dac_idx] - 2;
7959         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
7960
7961 }
7962
7963 static void alc883_auto_init_multi_out(struct hda_codec *codec)
7964 {
7965         struct alc_spec *spec = codec->spec;
7966         int i;
7967
7968         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
7969         for (i = 0; i <= HDA_SIDE; i++) {
7970                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
7971                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
7972                 if (nid)
7973                         alc883_auto_set_output_and_unmute(codec, nid, pin_type,
7974                                                           i);
7975         }
7976 }
7977
7978 static void alc883_auto_init_hp_out(struct hda_codec *codec)
7979 {
7980         struct alc_spec *spec = codec->spec;
7981         hda_nid_t pin;
7982
7983         pin = spec->autocfg.hp_pins[0];
7984         if (pin) /* connect to front */
7985                 /* use dac 0 */
7986                 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
7987         pin = spec->autocfg.speaker_pins[0];
7988         if (pin)
7989                 alc883_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
7990 }
7991
7992 #define alc883_is_input_pin(nid)        alc880_is_input_pin(nid)
7993 #define ALC883_PIN_CD_NID               ALC880_PIN_CD_NID
7994
7995 static void alc883_auto_init_analog_input(struct hda_codec *codec)
7996 {
7997         struct alc_spec *spec = codec->spec;
7998         int i;
7999
8000         for (i = 0; i < AUTO_PIN_LAST; i++) {
8001                 hda_nid_t nid = spec->autocfg.input_pins[i];
8002                 if (alc883_is_input_pin(nid)) {
8003                         snd_hda_codec_write(codec, nid, 0,
8004                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
8005                                             (i <= AUTO_PIN_FRONT_MIC ?
8006                                              PIN_VREF80 : PIN_IN));
8007                         if (nid != ALC883_PIN_CD_NID)
8008                                 snd_hda_codec_write(codec, nid, 0,
8009                                                     AC_VERB_SET_AMP_GAIN_MUTE,
8010                                                     AMP_OUT_MUTE);
8011                 }
8012         }
8013 }
8014
8015 /* almost identical with ALC880 parser... */
8016 static int alc883_parse_auto_config(struct hda_codec *codec)
8017 {
8018         struct alc_spec *spec = codec->spec;
8019         int err = alc880_parse_auto_config(codec);
8020
8021         if (err < 0)
8022                 return err;
8023         else if (!err)
8024                 return 0; /* no config found */
8025
8026         err = alc_auto_add_mic_boost(codec);
8027         if (err < 0)
8028                 return err;
8029
8030         /* hack - override the init verbs */
8031         spec->init_verbs[0] = alc883_auto_init_verbs;
8032         spec->mixers[spec->num_mixers] = alc883_capture_mixer;
8033         spec->num_mixers++;
8034
8035         return 1; /* config found */
8036 }
8037
8038 /* additional initialization for auto-configuration model */
8039 static void alc883_auto_init(struct hda_codec *codec)
8040 {
8041         struct alc_spec *spec = codec->spec;
8042         alc883_auto_init_multi_out(codec);
8043         alc883_auto_init_hp_out(codec);
8044         alc883_auto_init_analog_input(codec);
8045         if (spec->unsol_event)
8046                 alc_sku_automute(codec);
8047 }
8048
8049 static int patch_alc883(struct hda_codec *codec)
8050 {
8051         struct alc_spec *spec;
8052         int err, board_config;
8053
8054         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
8055         if (spec == NULL)
8056                 return -ENOMEM;
8057
8058         codec->spec = spec;
8059
8060         board_config = snd_hda_check_board_config(codec, ALC883_MODEL_LAST,
8061                                                   alc883_models,
8062                                                   alc883_cfg_tbl);
8063         if (board_config < 0) {
8064                 printk(KERN_INFO "hda_codec: Unknown model for ALC883, "
8065                        "trying auto-probe from BIOS...\n");
8066                 board_config = ALC883_AUTO;
8067         }
8068
8069         if (board_config == ALC883_AUTO) {
8070                 /* automatic parse from the BIOS config */
8071                 err = alc883_parse_auto_config(codec);
8072                 if (err < 0) {
8073                         alc_free(codec);
8074                         return err;
8075                 } else if (!err) {
8076                         printk(KERN_INFO
8077                                "hda_codec: Cannot set up configuration "
8078                                "from BIOS.  Using base mode...\n");
8079                         board_config = ALC883_3ST_2ch_DIG;
8080                 }
8081         }
8082
8083         if (board_config != ALC883_AUTO)
8084                 setup_preset(spec, &alc883_presets[board_config]);
8085
8086         spec->stream_name_analog = "ALC883 Analog";
8087         spec->stream_analog_playback = &alc883_pcm_analog_playback;
8088         spec->stream_analog_capture = &alc883_pcm_analog_capture;
8089         spec->stream_analog_alt_capture = &alc883_pcm_analog_alt_capture;
8090
8091         spec->stream_name_digital = "ALC883 Digital";
8092         spec->stream_digital_playback = &alc883_pcm_digital_playback;
8093         spec->stream_digital_capture = &alc883_pcm_digital_capture;
8094
8095         spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
8096         spec->adc_nids = alc883_adc_nids;
8097         spec->capsrc_nids = alc883_capsrc_nids;
8098
8099         spec->vmaster_nid = 0x0c;
8100
8101         codec->patch_ops = alc_patch_ops;
8102         if (board_config == ALC883_AUTO)
8103                 spec->init_hook = alc883_auto_init;
8104 #ifdef CONFIG_SND_HDA_POWER_SAVE
8105         if (!spec->loopback.amplist)
8106                 spec->loopback.amplist = alc883_loopbacks;
8107 #endif
8108
8109         return 0;
8110 }
8111
8112 /*
8113  * ALC262 support
8114  */
8115
8116 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
8117 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
8118
8119 #define alc262_dac_nids         alc260_dac_nids
8120 #define alc262_adc_nids         alc882_adc_nids
8121 #define alc262_adc_nids_alt     alc882_adc_nids_alt
8122 #define alc262_capsrc_nids      alc882_capsrc_nids
8123 #define alc262_capsrc_nids_alt  alc882_capsrc_nids_alt
8124
8125 #define alc262_modes            alc260_modes
8126 #define alc262_capture_source   alc882_capture_source
8127
8128 static struct snd_kcontrol_new alc262_base_mixer[] = {
8129         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8130         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8131         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8132         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8133         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8134         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8135         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8136         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8137         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8138         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8139         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8140         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8141         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8142            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
8143         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
8144         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8145         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
8146         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
8147         { } /* end */
8148 };
8149
8150 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
8151         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8152         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8153         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8154         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8155         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8156         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8157         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8158         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8159         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8160         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8161         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8162         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8163         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8164            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
8165         /*HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),*/
8166         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8167         { } /* end */
8168 };
8169
8170 /* update HP, line and mono-out pins according to the master switch */
8171 static void alc262_hp_master_update(struct hda_codec *codec)
8172 {
8173         struct alc_spec *spec = codec->spec;
8174         int val = spec->master_sw;
8175
8176         /* HP & line-out */
8177         snd_hda_codec_write_cache(codec, 0x1b, 0,
8178                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
8179                                   val ? PIN_HP : 0);
8180         snd_hda_codec_write_cache(codec, 0x15, 0,
8181                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
8182                                   val ? PIN_HP : 0);
8183         /* mono (speaker) depending on the HP jack sense */
8184         val = val && !spec->jack_present;
8185         snd_hda_codec_write_cache(codec, 0x16, 0,
8186                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
8187                                   val ? PIN_OUT : 0);
8188 }
8189
8190 static void alc262_hp_bpc_automute(struct hda_codec *codec)
8191 {
8192         struct alc_spec *spec = codec->spec;
8193         unsigned int presence;
8194         presence = snd_hda_codec_read(codec, 0x1b, 0,
8195                                       AC_VERB_GET_PIN_SENSE, 0);
8196         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
8197         alc262_hp_master_update(codec);
8198 }
8199
8200 static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res)
8201 {
8202         if ((res >> 26) != ALC880_HP_EVENT)
8203                 return;
8204         alc262_hp_bpc_automute(codec);
8205 }
8206
8207 static void alc262_hp_wildwest_automute(struct hda_codec *codec)
8208 {
8209         struct alc_spec *spec = codec->spec;
8210         unsigned int presence;
8211         presence = snd_hda_codec_read(codec, 0x15, 0,
8212                                       AC_VERB_GET_PIN_SENSE, 0);
8213         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
8214         alc262_hp_master_update(codec);
8215 }
8216
8217 static void alc262_hp_wildwest_unsol_event(struct hda_codec *codec,
8218                                            unsigned int res)
8219 {
8220         if ((res >> 26) != ALC880_HP_EVENT)
8221                 return;
8222         alc262_hp_wildwest_automute(codec);
8223 }
8224
8225 static int alc262_hp_master_sw_get(struct snd_kcontrol *kcontrol,
8226                                    struct snd_ctl_elem_value *ucontrol)
8227 {
8228         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8229         struct alc_spec *spec = codec->spec;
8230         *ucontrol->value.integer.value = spec->master_sw;
8231         return 0;
8232 }
8233
8234 static int alc262_hp_master_sw_put(struct snd_kcontrol *kcontrol,
8235                                    struct snd_ctl_elem_value *ucontrol)
8236 {
8237         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8238         struct alc_spec *spec = codec->spec;
8239         int val = !!*ucontrol->value.integer.value;
8240
8241         if (val == spec->master_sw)
8242                 return 0;
8243         spec->master_sw = val;
8244         alc262_hp_master_update(codec);
8245         return 1;
8246 }
8247
8248 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
8249         {
8250                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8251                 .name = "Master Playback Switch",
8252                 .info = snd_ctl_boolean_mono_info,
8253                 .get = alc262_hp_master_sw_get,
8254                 .put = alc262_hp_master_sw_put,
8255         },
8256         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8257         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8258         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8259         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
8260                               HDA_OUTPUT),
8261         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
8262                             HDA_OUTPUT),
8263         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8264         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8265         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8266         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8267         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8268         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8269         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8270         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8271         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8272         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8273         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8274         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
8275         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
8276         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
8277         { } /* end */
8278 };
8279
8280 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
8281         {
8282                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8283                 .name = "Master Playback Switch",
8284                 .info = snd_ctl_boolean_mono_info,
8285                 .get = alc262_hp_master_sw_get,
8286                 .put = alc262_hp_master_sw_put,
8287         },
8288         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8289         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8290         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8291         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8292         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
8293                               HDA_OUTPUT),
8294         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
8295                             HDA_OUTPUT),
8296         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
8297         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
8298         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
8299         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
8300         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
8301         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8302         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8303         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8304         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
8305         { } /* end */
8306 };
8307
8308 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
8309         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8310         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8311         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
8312         { } /* end */
8313 };
8314
8315 /* mute/unmute internal speaker according to the hp jack and mute state */
8316 static void alc262_hp_t5735_automute(struct hda_codec *codec, int force)
8317 {
8318         struct alc_spec *spec = codec->spec;
8319
8320         if (force || !spec->sense_updated) {
8321                 unsigned int present;
8322                 present = snd_hda_codec_read(codec, 0x15, 0,
8323                                              AC_VERB_GET_PIN_SENSE, 0);
8324                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
8325                 spec->sense_updated = 1;
8326         }
8327         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0, HDA_AMP_MUTE,
8328                                  spec->jack_present ? HDA_AMP_MUTE : 0);
8329 }
8330
8331 static void alc262_hp_t5735_unsol_event(struct hda_codec *codec,
8332                                         unsigned int res)
8333 {
8334         if ((res >> 26) != ALC880_HP_EVENT)
8335                 return;
8336         alc262_hp_t5735_automute(codec, 1);
8337 }
8338
8339 static void alc262_hp_t5735_init_hook(struct hda_codec *codec)
8340 {
8341         alc262_hp_t5735_automute(codec, 1);
8342 }
8343
8344 static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
8345         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8346         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8347         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8348         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8349         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8350         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8351         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8352         { } /* end */
8353 };
8354
8355 static struct hda_verb alc262_hp_t5735_verbs[] = {
8356         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8357         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8358
8359         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8360         { }
8361 };
8362
8363 static struct snd_kcontrol_new alc262_hp_rp5700_mixer[] = {
8364         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8365         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8366         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
8367         HDA_CODEC_MUTE("Speaker Playback Switch", 0x16, 0x0, HDA_OUTPUT),
8368         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
8369         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
8370         { } /* end */
8371 };
8372
8373 static struct hda_verb alc262_hp_rp5700_verbs[] = {
8374         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8375         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8376         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8377         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8378         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8379         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8380         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8381         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8382         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
8383         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
8384         {}
8385 };
8386
8387 static struct hda_input_mux alc262_hp_rp5700_capture_source = {
8388         .num_items = 1,
8389         .items = {
8390                 { "Line", 0x1 },
8391         },
8392 };
8393
8394 /* bind hp and internal speaker mute (with plug check) */
8395 static int alc262_sony_master_sw_put(struct snd_kcontrol *kcontrol,
8396                                      struct snd_ctl_elem_value *ucontrol)
8397 {
8398         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8399         long *valp = ucontrol->value.integer.value;
8400         int change;
8401
8402         /* change hp mute */
8403         change = snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
8404                                           HDA_AMP_MUTE,
8405                                           valp[0] ? 0 : HDA_AMP_MUTE);
8406         change |= snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
8407                                            HDA_AMP_MUTE,
8408                                            valp[1] ? 0 : HDA_AMP_MUTE);
8409         if (change) {
8410                 /* change speaker according to HP jack state */
8411                 struct alc_spec *spec = codec->spec;
8412                 unsigned int mute;
8413                 if (spec->jack_present)
8414                         mute = HDA_AMP_MUTE;
8415                 else
8416                         mute = snd_hda_codec_amp_read(codec, 0x15, 0,
8417                                                       HDA_OUTPUT, 0);
8418                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8419                                          HDA_AMP_MUTE, mute);
8420         }
8421         return change;
8422 }
8423
8424 static struct snd_kcontrol_new alc262_sony_mixer[] = {
8425         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8426         {
8427                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8428                 .name = "Master Playback Switch",
8429                 .info = snd_hda_mixer_amp_switch_info,
8430                 .get = snd_hda_mixer_amp_switch_get,
8431                 .put = alc262_sony_master_sw_put,
8432                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
8433         },
8434         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8435         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8436         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8437         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8438         { } /* end */
8439 };
8440
8441 static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
8442         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8443         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8444         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8445         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8446         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8447         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8448         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8449         { } /* end */
8450 };
8451
8452 #define alc262_capture_mixer            alc882_capture_mixer
8453 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
8454
8455 /*
8456  * generic initialization of ADC, input mixers and output mixers
8457  */
8458 static struct hda_verb alc262_init_verbs[] = {
8459         /*
8460          * Unmute ADC0-2 and set the default input to mic-in
8461          */
8462         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
8463         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8464         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8465         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8466         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8467         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8468
8469         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8470          * mixer widget
8471          * Note: PASD motherboards uses the Line In 2 as the input for
8472          * front panel mic (mic 2)
8473          */
8474         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8475         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8476         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8477         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8478         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8479         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8480
8481         /*
8482          * Set up output mixers (0x0c - 0x0e)
8483          */
8484         /* set vol=0 to output mixers */
8485         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8486         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8487         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8488         /* set up input amps for analog loopback */
8489         /* Amp Indices: DAC = 0, mixer = 1 */
8490         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8491         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8492         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8493         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8494         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8495         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8496
8497         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
8498         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8499         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
8500         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8501         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8502         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8503
8504         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8505         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8506         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8507         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8508         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8509         
8510         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8511         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
8512         
8513         /* FIXME: use matrix-type input source selection */
8514         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8515         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
8516         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8517         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8518         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8519         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8520         /* Input mixer2 */
8521         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8522         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8523         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8524         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8525         /* Input mixer3 */
8526         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8527         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8528         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8529         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8530
8531         { }
8532 };
8533
8534 static struct hda_verb alc262_hippo_unsol_verbs[] = {
8535         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8536         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8537         {}
8538 };
8539
8540 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
8541         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8542         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8543         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8544
8545         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8546         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8547         {}
8548 };
8549
8550 static struct hda_verb alc262_sony_unsol_verbs[] = {
8551         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8552         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8553         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
8554
8555         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8556         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8557 };
8558
8559 /* mute/unmute internal speaker according to the hp jack and mute state */
8560 static void alc262_hippo_automute(struct hda_codec *codec)
8561 {
8562         struct alc_spec *spec = codec->spec;
8563         unsigned int mute;
8564         unsigned int present;
8565
8566         /* need to execute and sync at first */
8567         snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
8568         present = snd_hda_codec_read(codec, 0x15, 0,
8569                                      AC_VERB_GET_PIN_SENSE, 0);
8570         spec->jack_present = (present & 0x80000000) != 0;
8571         if (spec->jack_present) {
8572                 /* mute internal speaker */
8573                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8574                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8575         } else {
8576                 /* unmute internal speaker if necessary */
8577                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
8578                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8579                                          HDA_AMP_MUTE, mute);
8580         }
8581 }
8582
8583 /* unsolicited event for HP jack sensing */
8584 static void alc262_hippo_unsol_event(struct hda_codec *codec,
8585                                        unsigned int res)
8586 {
8587         if ((res >> 26) != ALC880_HP_EVENT)
8588                 return;
8589         alc262_hippo_automute(codec);
8590 }
8591
8592 static void alc262_hippo1_automute(struct hda_codec *codec)
8593 {
8594         unsigned int mute;
8595         unsigned int present;
8596
8597         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
8598         present = snd_hda_codec_read(codec, 0x1b, 0,
8599                                      AC_VERB_GET_PIN_SENSE, 0);
8600         present = (present & 0x80000000) != 0;
8601         if (present) {
8602                 /* mute internal speaker */
8603                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8604                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8605         } else {
8606                 /* unmute internal speaker if necessary */
8607                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
8608                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8609                                          HDA_AMP_MUTE, mute);
8610         }
8611 }
8612
8613 /* unsolicited event for HP jack sensing */
8614 static void alc262_hippo1_unsol_event(struct hda_codec *codec,
8615                                        unsigned int res)
8616 {
8617         if ((res >> 26) != ALC880_HP_EVENT)
8618                 return;
8619         alc262_hippo1_automute(codec);
8620 }
8621
8622 /*
8623  * fujitsu model
8624  *  0x14 = headphone/spdif-out, 0x15 = internal speaker,
8625  *  0x1b = port replicator headphone out
8626  */
8627
8628 #define ALC_HP_EVENT    0x37
8629
8630 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
8631         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
8632         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8633         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
8634         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8635         {}
8636 };
8637
8638 static struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
8639         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
8640         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8641         {}
8642 };
8643
8644 static struct hda_input_mux alc262_fujitsu_capture_source = {
8645         .num_items = 3,
8646         .items = {
8647                 { "Mic", 0x0 },
8648                 { "Int Mic", 0x1 },
8649                 { "CD", 0x4 },
8650         },
8651 };
8652
8653 static struct hda_input_mux alc262_HP_capture_source = {
8654         .num_items = 5,
8655         .items = {
8656                 { "Mic", 0x0 },
8657                 { "Front Mic", 0x1 },
8658                 { "Line", 0x2 },
8659                 { "CD", 0x4 },
8660                 { "AUX IN", 0x6 },
8661         },
8662 };
8663
8664 static struct hda_input_mux alc262_HP_D7000_capture_source = {
8665         .num_items = 4,
8666         .items = {
8667                 { "Mic", 0x0 },
8668                 { "Front Mic", 0x2 },
8669                 { "Line", 0x1 },
8670                 { "CD", 0x4 },
8671         },
8672 };
8673
8674 /* mute/unmute internal speaker according to the hp jack and mute state */
8675 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
8676 {
8677         struct alc_spec *spec = codec->spec;
8678         unsigned int mute;
8679
8680         if (force || !spec->sense_updated) {
8681                 unsigned int present_int_hp, present_dock_hp;
8682                 /* need to execute and sync at first */
8683                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
8684                 present_int_hp = snd_hda_codec_read(codec, 0x14, 0,
8685                                         AC_VERB_GET_PIN_SENSE, 0);
8686                 snd_hda_codec_read(codec, 0x1B, 0, AC_VERB_SET_PIN_SENSE, 0);
8687                 present_dock_hp = snd_hda_codec_read(codec, 0x1b, 0,
8688                                         AC_VERB_GET_PIN_SENSE, 0);
8689                 spec->jack_present = (present_int_hp & 0x80000000) != 0;
8690                 spec->jack_present |= (present_dock_hp & 0x80000000) != 0;
8691                 spec->sense_updated = 1;
8692         }
8693         if (spec->jack_present) {
8694                 /* mute internal speaker */
8695                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8696                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8697         } else {
8698                 /* unmute internal speaker if necessary */
8699                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
8700                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8701                                          HDA_AMP_MUTE, mute);
8702         }
8703 }
8704
8705 /* unsolicited event for HP jack sensing */
8706 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
8707                                        unsigned int res)
8708 {
8709         if ((res >> 26) != ALC_HP_EVENT)
8710                 return;
8711         alc262_fujitsu_automute(codec, 1);
8712 }
8713
8714 /* bind volumes of both NID 0x0c and 0x0d */
8715 static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
8716         .ops = &snd_hda_bind_vol,
8717         .values = {
8718                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
8719                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
8720                 0
8721         },
8722 };
8723
8724 /* mute/unmute internal speaker according to the hp jack and mute state */
8725 static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
8726 {
8727         struct alc_spec *spec = codec->spec;
8728         unsigned int mute;
8729
8730         if (force || !spec->sense_updated) {
8731                 unsigned int present_int_hp;
8732                 /* need to execute and sync at first */
8733                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
8734                 present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
8735                                         AC_VERB_GET_PIN_SENSE, 0);
8736                 spec->jack_present = (present_int_hp & 0x80000000) != 0;
8737                 spec->sense_updated = 1;
8738         }
8739         if (spec->jack_present) {
8740                 /* mute internal speaker */
8741                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8742                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8743                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8744                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8745         } else {
8746                 /* unmute internal speaker if necessary */
8747                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
8748                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8749                                          HDA_AMP_MUTE, mute);
8750                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8751                                          HDA_AMP_MUTE, mute);
8752         }
8753 }
8754
8755 /* unsolicited event for HP jack sensing */
8756 static void alc262_lenovo_3000_unsol_event(struct hda_codec *codec,
8757                                        unsigned int res)
8758 {
8759         if ((res >> 26) != ALC_HP_EVENT)
8760                 return;
8761         alc262_lenovo_3000_automute(codec, 1);
8762 }
8763
8764 /* bind hp and internal speaker mute (with plug check) */
8765 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
8766                                          struct snd_ctl_elem_value *ucontrol)
8767 {
8768         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8769         long *valp = ucontrol->value.integer.value;
8770         int change;
8771
8772         change = snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8773                                                  HDA_AMP_MUTE,
8774                                                  valp ? 0 : HDA_AMP_MUTE);
8775         change |= snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
8776                                                  HDA_AMP_MUTE,
8777                                                  valp ? 0 : HDA_AMP_MUTE);
8778
8779         if (change)
8780                 alc262_fujitsu_automute(codec, 0);
8781         return change;
8782 }
8783
8784 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
8785         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
8786         {
8787                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8788                 .name = "Master Playback Switch",
8789                 .info = snd_hda_mixer_amp_switch_info,
8790                 .get = snd_hda_mixer_amp_switch_get,
8791                 .put = alc262_fujitsu_master_sw_put,
8792                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
8793         },
8794         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8795         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8796         HDA_CODEC_VOLUME("PC Speaker Volume", 0x0b, 0x05, HDA_INPUT),
8797         HDA_CODEC_MUTE("PC Speaker Switch", 0x0b, 0x05, HDA_INPUT),
8798         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8799         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8800         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8801         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
8802         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8803         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8804         { } /* end */
8805 };
8806
8807 /* bind hp and internal speaker mute (with plug check) */
8808 static int alc262_lenovo_3000_master_sw_put(struct snd_kcontrol *kcontrol,
8809                                          struct snd_ctl_elem_value *ucontrol)
8810 {
8811         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8812         long *valp = ucontrol->value.integer.value;
8813         int change;
8814
8815         change = snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
8816                                                  HDA_AMP_MUTE,
8817                                                  valp ? 0 : HDA_AMP_MUTE);
8818
8819         if (change)
8820                 alc262_lenovo_3000_automute(codec, 0);
8821         return change;
8822 }
8823
8824 static struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
8825         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
8826         {
8827                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8828                 .name = "Master Playback Switch",
8829                 .info = snd_hda_mixer_amp_switch_info,
8830                 .get = snd_hda_mixer_amp_switch_get,
8831                 .put = alc262_lenovo_3000_master_sw_put,
8832                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
8833         },
8834         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8835         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8836         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8837         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8838         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8839         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
8840         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8841         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8842         { } /* end */
8843 };
8844
8845 /* additional init verbs for Benq laptops */
8846 static struct hda_verb alc262_EAPD_verbs[] = {
8847         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
8848         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
8849         {}
8850 };
8851
8852 static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
8853         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8854         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8855
8856         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
8857         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
8858         {}
8859 };
8860
8861 /* Samsung Q1 Ultra Vista model setup */
8862 static struct snd_kcontrol_new alc262_ultra_mixer[] = {
8863         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8864         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
8865         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8866         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8867         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
8868         HDA_CODEC_VOLUME("Headphone Mic Boost", 0x15, 0, HDA_INPUT),
8869         { } /* end */
8870 };
8871
8872 static struct hda_verb alc262_ultra_verbs[] = {
8873         /* output mixer */
8874         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8875         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8876         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8877         /* speaker */
8878         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8879         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8880         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8881         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8882         /* HP */
8883         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8884         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8885         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8886         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8887         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8888         /* internal mic */
8889         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8890         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8891         /* ADC, choose mic */
8892         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8893         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8894         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8895         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8896         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8897         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8898         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
8899         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
8900         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
8901         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(8)},
8902         {}
8903 };
8904
8905 /* mute/unmute internal speaker according to the hp jack and mute state */
8906 static void alc262_ultra_automute(struct hda_codec *codec)
8907 {
8908         struct alc_spec *spec = codec->spec;
8909         unsigned int mute;
8910
8911         mute = 0;
8912         /* auto-mute only when HP is used as HP */
8913         if (!spec->cur_mux[0]) {
8914                 unsigned int present;
8915                 /* need to execute and sync at first */
8916                 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
8917                 present = snd_hda_codec_read(codec, 0x15, 0,
8918                                              AC_VERB_GET_PIN_SENSE, 0);
8919                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
8920                 if (spec->jack_present)
8921                         mute = HDA_AMP_MUTE;
8922         }
8923         /* mute/unmute internal speaker */
8924         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8925                                  HDA_AMP_MUTE, mute);
8926         /* mute/unmute HP */
8927         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8928                                  HDA_AMP_MUTE, mute ? 0 : HDA_AMP_MUTE);
8929 }
8930
8931 /* unsolicited event for HP jack sensing */
8932 static void alc262_ultra_unsol_event(struct hda_codec *codec,
8933                                        unsigned int res)
8934 {
8935         if ((res >> 26) != ALC880_HP_EVENT)
8936                 return;
8937         alc262_ultra_automute(codec);
8938 }
8939
8940 static struct hda_input_mux alc262_ultra_capture_source = {
8941         .num_items = 2,
8942         .items = {
8943                 { "Mic", 0x1 },
8944                 { "Headphone", 0x7 },
8945         },
8946 };
8947
8948 static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
8949                                      struct snd_ctl_elem_value *ucontrol)
8950 {
8951         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8952         struct alc_spec *spec = codec->spec;
8953         int ret;
8954
8955         ret = alc882_mux_enum_put(kcontrol, ucontrol);
8956         if (!ret)
8957                 return 0;
8958         /* reprogram the HP pin as mic or HP according to the input source */
8959         snd_hda_codec_write_cache(codec, 0x15, 0,
8960                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
8961                                   spec->cur_mux[0] ? PIN_VREF80 : PIN_HP);
8962         alc262_ultra_automute(codec); /* mute/unmute HP */
8963         return ret;
8964 }
8965
8966 static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
8967         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
8968         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
8969         {
8970                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8971                 .name = "Capture Source",
8972                 .info = alc882_mux_enum_info,
8973                 .get = alc882_mux_enum_get,
8974                 .put = alc262_ultra_mux_enum_put,
8975         },
8976         { } /* end */
8977 };
8978
8979 /* add playback controls from the parsed DAC table */
8980 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
8981                                              const struct auto_pin_cfg *cfg)
8982 {
8983         hda_nid_t nid;
8984         int err;
8985
8986         spec->multiout.num_dacs = 1;    /* only use one dac */
8987         spec->multiout.dac_nids = spec->private_dac_nids;
8988         spec->multiout.dac_nids[0] = 2;
8989
8990         nid = cfg->line_out_pins[0];
8991         if (nid) {
8992                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
8993                                   "Front Playback Volume",
8994                                   HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT));
8995                 if (err < 0)
8996                         return err;
8997                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
8998                                   "Front Playback Switch",
8999                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
9000                 if (err < 0)
9001                         return err;
9002         }
9003
9004         nid = cfg->speaker_pins[0];
9005         if (nid) {
9006                 if (nid == 0x16) {
9007                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
9008                                           "Speaker Playback Volume",
9009                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
9010                                                               HDA_OUTPUT));
9011                         if (err < 0)
9012                                 return err;
9013                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9014                                           "Speaker Playback Switch",
9015                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
9016                                                               HDA_OUTPUT));
9017                         if (err < 0)
9018                                 return err;
9019                 } else {
9020                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9021                                           "Speaker Playback Switch",
9022                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
9023                                                               HDA_OUTPUT));
9024                         if (err < 0)
9025                                 return err;
9026                 }
9027         }
9028         nid = cfg->hp_pins[0];
9029         if (nid) {
9030                 /* spec->multiout.hp_nid = 2; */
9031                 if (nid == 0x16) {
9032                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
9033                                           "Headphone Playback Volume",
9034                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
9035                                                               HDA_OUTPUT));
9036                         if (err < 0)
9037                                 return err;
9038                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9039                                           "Headphone Playback Switch",
9040                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
9041                                                               HDA_OUTPUT));
9042                         if (err < 0)
9043                                 return err;
9044                 } else {
9045                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9046                                           "Headphone Playback Switch",
9047                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
9048                                                               HDA_OUTPUT));
9049                         if (err < 0)
9050                                 return err;
9051                 }
9052         }
9053         return 0;
9054 }
9055
9056 /* identical with ALC880 */
9057 #define alc262_auto_create_analog_input_ctls \
9058         alc880_auto_create_analog_input_ctls
9059
9060 /*
9061  * generic initialization of ADC, input mixers and output mixers
9062  */
9063 static struct hda_verb alc262_volume_init_verbs[] = {
9064         /*
9065          * Unmute ADC0-2 and set the default input to mic-in
9066          */
9067         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9068         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9069         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9070         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9071         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9072         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9073
9074         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9075          * mixer widget
9076          * Note: PASD motherboards uses the Line In 2 as the input for
9077          * front panel mic (mic 2)
9078          */
9079         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9080         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9081         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9082         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9083         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9084         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9085
9086         /*
9087          * Set up output mixers (0x0c - 0x0f)
9088          */
9089         /* set vol=0 to output mixers */
9090         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9091         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9092         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9093         
9094         /* set up input amps for analog loopback */
9095         /* Amp Indices: DAC = 0, mixer = 1 */
9096         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9097         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9098         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9099         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9100         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9101         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9102
9103         /* FIXME: use matrix-type input source selection */
9104         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9105         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9106         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9107         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9108         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9109         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9110         /* Input mixer2 */
9111         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9112         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9113         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9114         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9115         /* Input mixer3 */
9116         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9117         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9118         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9119         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9120
9121         { }
9122 };
9123
9124 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
9125         /*
9126          * Unmute ADC0-2 and set the default input to mic-in
9127          */
9128         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9129         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9130         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9131         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9132         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9133         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9134
9135         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9136          * mixer widget
9137          * Note: PASD motherboards uses the Line In 2 as the input for
9138          * front panel mic (mic 2)
9139          */
9140         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9141         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9142         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9143         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9144         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9145         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9146         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
9147         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
9148         
9149         /*
9150          * Set up output mixers (0x0c - 0x0e)
9151          */
9152         /* set vol=0 to output mixers */
9153         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9154         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9155         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9156
9157         /* set up input amps for analog loopback */
9158         /* Amp Indices: DAC = 0, mixer = 1 */
9159         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9160         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9161         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9162         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9163         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9164         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9165
9166         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9167         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9168         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9169
9170         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9171         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9172
9173         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9174         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9175
9176         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9177         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9178         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9179         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9180         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9181
9182         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
9183         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9184         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9185         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
9186         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9187         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9188
9189
9190         /* FIXME: use matrix-type input source selection */
9191         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9192         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9193         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9194         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9195         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9196         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9197         /* Input mixer2 */
9198         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9199         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9200         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9201         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9202         /* Input mixer3 */
9203         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9204         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9205         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9206         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9207
9208         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9209
9210         { }
9211 };
9212
9213 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
9214         /*
9215          * Unmute ADC0-2 and set the default input to mic-in
9216          */
9217         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9218         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9219         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9220         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9221         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9222         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9223
9224         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9225          * mixer widget
9226          * Note: PASD motherboards uses the Line In 2 as the input for front
9227          * panel mic (mic 2)
9228          */
9229         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9230         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9231         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9232         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9233         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9234         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9235         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
9236         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
9237         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
9238         /*
9239          * Set up output mixers (0x0c - 0x0e)
9240          */
9241         /* set vol=0 to output mixers */
9242         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9243         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9244         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9245
9246         /* set up input amps for analog loopback */
9247         /* Amp Indices: DAC = 0, mixer = 1 */
9248         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9249         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9250         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9251         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9252         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9253         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9254
9255
9256         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
9257         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
9258         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
9259         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
9260         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
9261         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
9262         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
9263
9264         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9265         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9266
9267         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9268         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
9269
9270         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
9271         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9272         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9273         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
9274         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9275         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9276
9277         /* FIXME: use matrix-type input source selection */
9278         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9279         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9280         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
9281         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
9282         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
9283         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
9284         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
9285         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
9286         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
9287         /* Input mixer2 */
9288         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9289         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9290         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9291         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9292         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9293         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
9294         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
9295         /* Input mixer3 */
9296         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9297         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9298         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9299         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9300         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9301         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
9302         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
9303
9304         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9305
9306         { }
9307 };
9308
9309 #ifdef CONFIG_SND_HDA_POWER_SAVE
9310 #define alc262_loopbacks        alc880_loopbacks
9311 #endif
9312
9313 /* pcm configuration: identiacal with ALC880 */
9314 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
9315 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
9316 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
9317 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
9318
9319 /*
9320  * BIOS auto configuration
9321  */
9322 static int alc262_parse_auto_config(struct hda_codec *codec)
9323 {
9324         struct alc_spec *spec = codec->spec;
9325         int err;
9326         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
9327
9328         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
9329                                            alc262_ignore);
9330         if (err < 0)
9331                 return err;
9332         if (!spec->autocfg.line_outs)
9333                 return 0; /* can't find valid BIOS pin config */
9334         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
9335         if (err < 0)
9336                 return err;
9337         err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg);
9338         if (err < 0)
9339                 return err;
9340
9341         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
9342
9343         if (spec->autocfg.dig_out_pin)
9344                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
9345         if (spec->autocfg.dig_in_pin)
9346                 spec->dig_in_nid = ALC262_DIGIN_NID;
9347
9348         if (spec->kctl_alloc)
9349                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
9350
9351         spec->init_verbs[spec->num_init_verbs++] = alc262_volume_init_verbs;
9352         spec->num_mux_defs = 1;
9353         spec->input_mux = &spec->private_imux;
9354
9355         err = alc_auto_add_mic_boost(codec);
9356         if (err < 0)
9357                 return err;
9358
9359         return 1;
9360 }
9361
9362 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
9363 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
9364 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
9365
9366
9367 /* init callback for auto-configuration model -- overriding the default init */
9368 static void alc262_auto_init(struct hda_codec *codec)
9369 {
9370         struct alc_spec *spec = codec->spec;
9371         alc262_auto_init_multi_out(codec);
9372         alc262_auto_init_hp_out(codec);
9373         alc262_auto_init_analog_input(codec);
9374         if (spec->unsol_event)
9375                 alc_sku_automute(codec);
9376 }
9377
9378 /*
9379  * configuration and preset
9380  */
9381 static const char *alc262_models[ALC262_MODEL_LAST] = {
9382         [ALC262_BASIC]          = "basic",
9383         [ALC262_HIPPO]          = "hippo",
9384         [ALC262_HIPPO_1]        = "hippo_1",
9385         [ALC262_FUJITSU]        = "fujitsu",
9386         [ALC262_HP_BPC]         = "hp-bpc",
9387         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
9388         [ALC262_HP_TC_T5735]    = "hp-tc-t5735",
9389         [ALC262_HP_RP5700]      = "hp-rp5700",
9390         [ALC262_BENQ_ED8]       = "benq",
9391         [ALC262_BENQ_T31]       = "benq-t31",
9392         [ALC262_SONY_ASSAMD]    = "sony-assamd",
9393         [ALC262_ULTRA]          = "ultra",
9394         [ALC262_LENOVO_3000]    = "lenovo-3000",
9395         [ALC262_AUTO]           = "auto",
9396 };
9397
9398 static struct snd_pci_quirk alc262_cfg_tbl[] = {
9399         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
9400         SND_PCI_QUIRK(0x103c, 0x12fe, "HP xw9400", ALC262_HP_BPC),
9401         SND_PCI_QUIRK(0x103c, 0x12ff, "HP xw4550", ALC262_HP_BPC),
9402         SND_PCI_QUIRK(0x103c, 0x1306, "HP xw8600", ALC262_HP_BPC),
9403         SND_PCI_QUIRK(0x103c, 0x1307, "HP xw6600", ALC262_HP_BPC),
9404         SND_PCI_QUIRK(0x103c, 0x1308, "HP xw4600", ALC262_HP_BPC),
9405         SND_PCI_QUIRK(0x103c, 0x1309, "HP xw4*00", ALC262_HP_BPC),
9406         SND_PCI_QUIRK(0x103c, 0x130a, "HP xw6*00", ALC262_HP_BPC),
9407         SND_PCI_QUIRK(0x103c, 0x130b, "HP xw8*00", ALC262_HP_BPC),
9408         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
9409         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
9410         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
9411         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
9412         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
9413         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
9414         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
9415         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
9416         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
9417         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
9418         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
9419         SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
9420                       ALC262_HP_TC_T5735),
9421         SND_PCI_QUIRK(0x103c, 0x2817, "HP RP5700", ALC262_HP_RP5700),
9422         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
9423         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
9424         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
9425         SND_PCI_QUIRK(0x104d, 0x900e, "Sony ASSAMD", ALC262_SONY_ASSAMD),
9426         SND_PCI_QUIRK(0x104d, 0x9015, "Sony 0x9015", ALC262_SONY_ASSAMD),
9427         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
9428         SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
9429         SND_PCI_QUIRK(0x144d, 0xc032, "Samsung Q1 Ultra", ALC262_ULTRA),
9430         SND_PCI_QUIRK(0x144d, 0xc039, "Samsung Q1U EL", ALC262_ULTRA),
9431         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
9432         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
9433         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
9434         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
9435         {}
9436 };
9437
9438 static struct alc_config_preset alc262_presets[] = {
9439         [ALC262_BASIC] = {
9440                 .mixers = { alc262_base_mixer },
9441                 .init_verbs = { alc262_init_verbs },
9442                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9443                 .dac_nids = alc262_dac_nids,
9444                 .hp_nid = 0x03,
9445                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9446                 .channel_mode = alc262_modes,
9447                 .input_mux = &alc262_capture_source,
9448         },
9449         [ALC262_HIPPO] = {
9450                 .mixers = { alc262_base_mixer },
9451                 .init_verbs = { alc262_init_verbs, alc262_hippo_unsol_verbs},
9452                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9453                 .dac_nids = alc262_dac_nids,
9454                 .hp_nid = 0x03,
9455                 .dig_out_nid = ALC262_DIGOUT_NID,
9456                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9457                 .channel_mode = alc262_modes,
9458                 .input_mux = &alc262_capture_source,
9459                 .unsol_event = alc262_hippo_unsol_event,
9460                 .init_hook = alc262_hippo_automute,
9461         },
9462         [ALC262_HIPPO_1] = {
9463                 .mixers = { alc262_hippo1_mixer },
9464                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
9465                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9466                 .dac_nids = alc262_dac_nids,
9467                 .hp_nid = 0x02,
9468                 .dig_out_nid = ALC262_DIGOUT_NID,
9469                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9470                 .channel_mode = alc262_modes,
9471                 .input_mux = &alc262_capture_source,
9472                 .unsol_event = alc262_hippo1_unsol_event,
9473                 .init_hook = alc262_hippo1_automute,
9474         },
9475         [ALC262_FUJITSU] = {
9476                 .mixers = { alc262_fujitsu_mixer },
9477                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
9478                                 alc262_fujitsu_unsol_verbs },
9479                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9480                 .dac_nids = alc262_dac_nids,
9481                 .hp_nid = 0x03,
9482                 .dig_out_nid = ALC262_DIGOUT_NID,
9483                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9484                 .channel_mode = alc262_modes,
9485                 .input_mux = &alc262_fujitsu_capture_source,
9486                 .unsol_event = alc262_fujitsu_unsol_event,
9487         },
9488         [ALC262_HP_BPC] = {
9489                 .mixers = { alc262_HP_BPC_mixer },
9490                 .init_verbs = { alc262_HP_BPC_init_verbs },
9491                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9492                 .dac_nids = alc262_dac_nids,
9493                 .hp_nid = 0x03,
9494                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9495                 .channel_mode = alc262_modes,
9496                 .input_mux = &alc262_HP_capture_source,
9497                 .unsol_event = alc262_hp_bpc_unsol_event,
9498                 .init_hook = alc262_hp_bpc_automute,
9499         },
9500         [ALC262_HP_BPC_D7000_WF] = {
9501                 .mixers = { alc262_HP_BPC_WildWest_mixer },
9502                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
9503                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9504                 .dac_nids = alc262_dac_nids,
9505                 .hp_nid = 0x03,
9506                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9507                 .channel_mode = alc262_modes,
9508                 .input_mux = &alc262_HP_D7000_capture_source,
9509                 .unsol_event = alc262_hp_wildwest_unsol_event,
9510                 .init_hook = alc262_hp_wildwest_automute,
9511         },
9512         [ALC262_HP_BPC_D7000_WL] = {
9513                 .mixers = { alc262_HP_BPC_WildWest_mixer,
9514                             alc262_HP_BPC_WildWest_option_mixer },
9515                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
9516                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9517                 .dac_nids = alc262_dac_nids,
9518                 .hp_nid = 0x03,
9519                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9520                 .channel_mode = alc262_modes,
9521                 .input_mux = &alc262_HP_D7000_capture_source,
9522                 .unsol_event = alc262_hp_wildwest_unsol_event,
9523                 .init_hook = alc262_hp_wildwest_automute,
9524         },
9525         [ALC262_HP_TC_T5735] = {
9526                 .mixers = { alc262_hp_t5735_mixer },
9527                 .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
9528                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9529                 .dac_nids = alc262_dac_nids,
9530                 .hp_nid = 0x03,
9531                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9532                 .channel_mode = alc262_modes,
9533                 .input_mux = &alc262_capture_source,
9534                 .unsol_event = alc262_hp_t5735_unsol_event,
9535                 .init_hook = alc262_hp_t5735_init_hook,
9536         },
9537         [ALC262_HP_RP5700] = {
9538                 .mixers = { alc262_hp_rp5700_mixer },
9539                 .init_verbs = { alc262_init_verbs, alc262_hp_rp5700_verbs },
9540                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9541                 .dac_nids = alc262_dac_nids,
9542                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9543                 .channel_mode = alc262_modes,
9544                 .input_mux = &alc262_hp_rp5700_capture_source,
9545         },
9546         [ALC262_BENQ_ED8] = {
9547                 .mixers = { alc262_base_mixer },
9548                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
9549                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9550                 .dac_nids = alc262_dac_nids,
9551                 .hp_nid = 0x03,
9552                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9553                 .channel_mode = alc262_modes,
9554                 .input_mux = &alc262_capture_source,
9555         },
9556         [ALC262_SONY_ASSAMD] = {
9557                 .mixers = { alc262_sony_mixer },
9558                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
9559                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9560                 .dac_nids = alc262_dac_nids,
9561                 .hp_nid = 0x02,
9562                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9563                 .channel_mode = alc262_modes,
9564                 .input_mux = &alc262_capture_source,
9565                 .unsol_event = alc262_hippo_unsol_event,
9566                 .init_hook = alc262_hippo_automute,
9567         },
9568         [ALC262_BENQ_T31] = {
9569                 .mixers = { alc262_benq_t31_mixer },
9570                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs, alc262_hippo_unsol_verbs },
9571                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9572                 .dac_nids = alc262_dac_nids,
9573                 .hp_nid = 0x03,
9574                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9575                 .channel_mode = alc262_modes,
9576                 .input_mux = &alc262_capture_source,
9577                 .unsol_event = alc262_hippo_unsol_event,
9578                 .init_hook = alc262_hippo_automute,
9579         },      
9580         [ALC262_ULTRA] = {
9581                 .mixers = { alc262_ultra_mixer, alc262_ultra_capture_mixer },
9582                 .init_verbs = { alc262_ultra_verbs },
9583                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9584                 .dac_nids = alc262_dac_nids,
9585                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9586                 .channel_mode = alc262_modes,
9587                 .input_mux = &alc262_ultra_capture_source,
9588                 .adc_nids = alc262_adc_nids, /* ADC0 */
9589                 .capsrc_nids = alc262_capsrc_nids,
9590                 .num_adc_nids = 1, /* single ADC */
9591                 .unsol_event = alc262_ultra_unsol_event,
9592                 .init_hook = alc262_ultra_automute,
9593         },
9594         [ALC262_LENOVO_3000] = {
9595                 .mixers = { alc262_lenovo_3000_mixer },
9596                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
9597                                 alc262_lenovo_3000_unsol_verbs },
9598                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9599                 .dac_nids = alc262_dac_nids,
9600                 .hp_nid = 0x03,
9601                 .dig_out_nid = ALC262_DIGOUT_NID,
9602                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9603                 .channel_mode = alc262_modes,
9604                 .input_mux = &alc262_fujitsu_capture_source,
9605                 .unsol_event = alc262_lenovo_3000_unsol_event,
9606         },
9607 };
9608
9609 static int patch_alc262(struct hda_codec *codec)
9610 {
9611         struct alc_spec *spec;
9612         int board_config;
9613         int err;
9614
9615         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
9616         if (spec == NULL)
9617                 return -ENOMEM;
9618
9619         codec->spec = spec;
9620 #if 0
9621         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
9622          * under-run
9623          */
9624         {
9625         int tmp;
9626         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
9627         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
9628         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
9629         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
9630         }
9631 #endif
9632
9633         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
9634                                                   alc262_models,
9635                                                   alc262_cfg_tbl);
9636
9637         if (board_config < 0) {
9638                 printk(KERN_INFO "hda_codec: Unknown model for ALC262, "
9639                        "trying auto-probe from BIOS...\n");
9640                 board_config = ALC262_AUTO;
9641         }
9642
9643         if (board_config == ALC262_AUTO) {
9644                 /* automatic parse from the BIOS config */
9645                 err = alc262_parse_auto_config(codec);
9646                 if (err < 0) {
9647                         alc_free(codec);
9648                         return err;
9649                 } else if (!err) {
9650                         printk(KERN_INFO
9651                                "hda_codec: Cannot set up configuration "
9652                                "from BIOS.  Using base mode...\n");
9653                         board_config = ALC262_BASIC;
9654                 }
9655         }
9656
9657         if (board_config != ALC262_AUTO)
9658                 setup_preset(spec, &alc262_presets[board_config]);
9659
9660         spec->stream_name_analog = "ALC262 Analog";
9661         spec->stream_analog_playback = &alc262_pcm_analog_playback;
9662         spec->stream_analog_capture = &alc262_pcm_analog_capture;
9663                 
9664         spec->stream_name_digital = "ALC262 Digital";
9665         spec->stream_digital_playback = &alc262_pcm_digital_playback;
9666         spec->stream_digital_capture = &alc262_pcm_digital_capture;
9667
9668         if (!spec->adc_nids && spec->input_mux) {
9669                 /* check whether NID 0x07 is valid */
9670                 unsigned int wcap = get_wcaps(codec, 0x07);
9671
9672                 /* get type */
9673                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
9674                 if (wcap != AC_WID_AUD_IN) {
9675                         spec->adc_nids = alc262_adc_nids_alt;
9676                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
9677                         spec->capsrc_nids = alc262_capsrc_nids_alt;
9678                         spec->mixers[spec->num_mixers] =
9679                                 alc262_capture_alt_mixer;
9680                         spec->num_mixers++;
9681                 } else {
9682                         spec->adc_nids = alc262_adc_nids;
9683                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
9684                         spec->capsrc_nids = alc262_capsrc_nids;
9685                         spec->mixers[spec->num_mixers] = alc262_capture_mixer;
9686                         spec->num_mixers++;
9687                 }
9688         }
9689
9690         spec->vmaster_nid = 0x0c;
9691
9692         codec->patch_ops = alc_patch_ops;
9693         if (board_config == ALC262_AUTO)
9694                 spec->init_hook = alc262_auto_init;
9695 #ifdef CONFIG_SND_HDA_POWER_SAVE
9696         if (!spec->loopback.amplist)
9697                 spec->loopback.amplist = alc262_loopbacks;
9698 #endif
9699                 
9700         return 0;
9701 }
9702
9703 /*
9704  *  ALC268 channel source setting (2 channel)
9705  */
9706 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
9707 #define alc268_modes            alc260_modes
9708         
9709 static hda_nid_t alc268_dac_nids[2] = {
9710         /* front, hp */
9711         0x02, 0x03
9712 };
9713
9714 static hda_nid_t alc268_adc_nids[2] = {
9715         /* ADC0-1 */
9716         0x08, 0x07
9717 };
9718
9719 static hda_nid_t alc268_adc_nids_alt[1] = {
9720         /* ADC0 */
9721         0x08
9722 };
9723
9724 static hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
9725
9726 static struct snd_kcontrol_new alc268_base_mixer[] = {
9727         /* output mixer control */
9728         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
9729         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9730         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
9731         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9732         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9733         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9734         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
9735         { }
9736 };
9737
9738 /* bind Beep switches of both NID 0x0f and 0x10 */
9739 static struct hda_bind_ctls alc268_bind_beep_sw = {
9740         .ops = &snd_hda_bind_sw,
9741         .values = {
9742                 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
9743                 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
9744                 0
9745         },
9746 };
9747
9748 static struct snd_kcontrol_new alc268_beep_mixer[] = {
9749         HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
9750         HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
9751         { }
9752 };
9753
9754 static struct hda_verb alc268_eapd_verbs[] = {
9755         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
9756         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
9757         { }
9758 };
9759
9760 /* Toshiba specific */
9761 #define alc268_toshiba_automute alc262_hippo_automute
9762
9763 static struct hda_verb alc268_toshiba_verbs[] = {
9764         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9765         { } /* end */
9766 };
9767
9768 /* Acer specific */
9769 /* bind volumes of both NID 0x02 and 0x03 */
9770 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
9771         .ops = &snd_hda_bind_vol,
9772         .values = {
9773                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
9774                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
9775                 0
9776         },
9777 };
9778
9779 /* mute/unmute internal speaker according to the hp jack and mute state */
9780 static void alc268_acer_automute(struct hda_codec *codec, int force)
9781 {
9782         struct alc_spec *spec = codec->spec;
9783         unsigned int mute;
9784
9785         if (force || !spec->sense_updated) {
9786                 unsigned int present;
9787                 present = snd_hda_codec_read(codec, 0x14, 0,
9788                                          AC_VERB_GET_PIN_SENSE, 0);
9789                 spec->jack_present = (present & 0x80000000) != 0;
9790                 spec->sense_updated = 1;
9791         }
9792         if (spec->jack_present)
9793                 mute = HDA_AMP_MUTE; /* mute internal speaker */
9794         else /* unmute internal speaker if necessary */
9795                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
9796         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9797                                  HDA_AMP_MUTE, mute);
9798 }
9799
9800
9801 /* bind hp and internal speaker mute (with plug check) */
9802 static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
9803                                      struct snd_ctl_elem_value *ucontrol)
9804 {
9805         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9806         long *valp = ucontrol->value.integer.value;
9807         int change;
9808
9809         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
9810                                           HDA_AMP_MUTE,
9811                                           valp[0] ? 0 : HDA_AMP_MUTE);
9812         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
9813                                            HDA_AMP_MUTE,
9814                                            valp[1] ? 0 : HDA_AMP_MUTE);
9815         if (change)
9816                 alc268_acer_automute(codec, 0);
9817         return change;
9818 }
9819
9820 static struct snd_kcontrol_new alc268_acer_mixer[] = {
9821         /* output mixer control */
9822         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
9823         {
9824                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9825                 .name = "Master Playback Switch",
9826                 .info = snd_hda_mixer_amp_switch_info,
9827                 .get = snd_hda_mixer_amp_switch_get,
9828                 .put = alc268_acer_master_sw_put,
9829                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
9830         },
9831         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9832         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
9833         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
9834         { }
9835 };
9836
9837 static struct hda_verb alc268_acer_verbs[] = {
9838         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
9839         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9840         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9841         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9842         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
9843         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
9844
9845         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9846         { }
9847 };
9848
9849 /* unsolicited event for HP jack sensing */
9850 static void alc268_toshiba_unsol_event(struct hda_codec *codec,
9851                                        unsigned int res)
9852 {
9853         if ((res >> 26) != ALC880_HP_EVENT)
9854                 return;
9855         alc268_toshiba_automute(codec);
9856 }
9857
9858 static void alc268_acer_unsol_event(struct hda_codec *codec,
9859                                        unsigned int res)
9860 {
9861         if ((res >> 26) != ALC880_HP_EVENT)
9862                 return;
9863         alc268_acer_automute(codec, 1);
9864 }
9865
9866 static void alc268_acer_init_hook(struct hda_codec *codec)
9867 {
9868         alc268_acer_automute(codec, 1);
9869 }
9870
9871 static struct snd_kcontrol_new alc268_dell_mixer[] = {
9872         /* output mixer control */
9873         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
9874         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9875         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
9876         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9877         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9878         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
9879         { }
9880 };
9881
9882 static struct hda_verb alc268_dell_verbs[] = {
9883         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9884         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9885         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9886         { }
9887 };
9888
9889 /* mute/unmute internal speaker according to the hp jack and mute state */
9890 static void alc268_dell_automute(struct hda_codec *codec)
9891 {
9892         unsigned int present;
9893         unsigned int mute;
9894
9895         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0);
9896         if (present & 0x80000000)
9897                 mute = HDA_AMP_MUTE;
9898         else
9899                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
9900         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9901                                  HDA_AMP_MUTE, mute);
9902 }
9903
9904 static void alc268_dell_unsol_event(struct hda_codec *codec,
9905                                     unsigned int res)
9906 {
9907         if ((res >> 26) != ALC880_HP_EVENT)
9908                 return;
9909         alc268_dell_automute(codec);
9910 }
9911
9912 #define alc268_dell_init_hook   alc268_dell_automute
9913
9914 static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
9915         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
9916         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9917         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
9918         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9919         HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
9920         HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
9921         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
9922         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
9923         { }
9924 };
9925
9926 static struct hda_verb alc267_quanta_il1_verbs[] = {
9927         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9928         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
9929         { }
9930 };
9931
9932 static void alc267_quanta_il1_hp_automute(struct hda_codec *codec)
9933 {
9934         unsigned int present;
9935
9936         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
9937                 & AC_PINSENSE_PRESENCE;
9938         snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
9939                             present ? 0 : PIN_OUT);
9940 }
9941
9942 static void alc267_quanta_il1_mic_automute(struct hda_codec *codec)
9943 {
9944         unsigned int present;
9945
9946         present = snd_hda_codec_read(codec, 0x18, 0,
9947                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9948         snd_hda_codec_write(codec, 0x23, 0,
9949                             AC_VERB_SET_CONNECT_SEL,
9950                             present ? 0x00 : 0x01);
9951 }
9952
9953 static void alc267_quanta_il1_automute(struct hda_codec *codec)
9954 {
9955         alc267_quanta_il1_hp_automute(codec);
9956         alc267_quanta_il1_mic_automute(codec);
9957 }
9958
9959 static void alc267_quanta_il1_unsol_event(struct hda_codec *codec,
9960                                            unsigned int res)
9961 {
9962         switch (res >> 26) {
9963         case ALC880_HP_EVENT:
9964                 alc267_quanta_il1_hp_automute(codec);
9965                 break;
9966         case ALC880_MIC_EVENT:
9967                 alc267_quanta_il1_mic_automute(codec);
9968                 break;
9969         }
9970 }
9971
9972 /*
9973  * generic initialization of ADC, input mixers and output mixers
9974  */
9975 static struct hda_verb alc268_base_init_verbs[] = {
9976         /* Unmute DAC0-1 and set vol = 0 */
9977         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9978         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9979         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9980         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9981         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9982         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9983
9984         /*
9985          * Set up output mixers (0x0c - 0x0e)
9986          */
9987         /* set vol=0 to output mixers */
9988         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9989         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9990         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9991         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
9992
9993         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9994         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9995
9996         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9997         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9998         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9999         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10000         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10001         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10002         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10003         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10004
10005         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10006         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10007         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10008         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10009         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10010         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10011         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10012
10013         /* set PCBEEP vol = 0, mute connections */
10014         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10015         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10016         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10017
10018         /* Unmute Selector 23h,24h and set the default input to mic-in */
10019         
10020         {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
10021         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10022         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
10023         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10024
10025         { }
10026 };
10027
10028 /*
10029  * generic initialization of ADC, input mixers and output mixers
10030  */
10031 static struct hda_verb alc268_volume_init_verbs[] = {
10032         /* set output DAC */
10033         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10034         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10035         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10036         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10037
10038         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10039         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10040         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10041         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10042         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10043
10044         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10045         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10046         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10047         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10048         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10049
10050         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10051         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10052         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10053         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10054
10055         /* set PCBEEP vol = 0, mute connections */
10056         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10057         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10058         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10059
10060         { }
10061 };
10062
10063 #define alc268_mux_enum_info alc_mux_enum_info
10064 #define alc268_mux_enum_get alc_mux_enum_get
10065 #define alc268_mux_enum_put alc_mux_enum_put
10066
10067 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
10068         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
10069         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
10070         {
10071                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10072                 /* The multiple "Capture Source" controls confuse alsamixer
10073                  * So call somewhat different..
10074                  */
10075                 /* .name = "Capture Source", */
10076                 .name = "Input Source",
10077                 .count = 1,
10078                 .info = alc268_mux_enum_info,
10079                 .get = alc268_mux_enum_get,
10080                 .put = alc268_mux_enum_put,
10081         },
10082         { } /* end */
10083 };
10084
10085 static struct snd_kcontrol_new alc268_capture_mixer[] = {
10086         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
10087         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
10088         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
10089         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
10090         {
10091                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10092                 /* The multiple "Capture Source" controls confuse alsamixer
10093                  * So call somewhat different..
10094                  */
10095                 /* .name = "Capture Source", */
10096                 .name = "Input Source",
10097                 .count = 2,
10098                 .info = alc268_mux_enum_info,
10099                 .get = alc268_mux_enum_get,
10100                 .put = alc268_mux_enum_put,
10101         },
10102         { } /* end */
10103 };
10104
10105 static struct hda_input_mux alc268_capture_source = {
10106         .num_items = 4,
10107         .items = {
10108                 { "Mic", 0x0 },
10109                 { "Front Mic", 0x1 },
10110                 { "Line", 0x2 },
10111                 { "CD", 0x3 },
10112         },
10113 };
10114
10115 static struct hda_input_mux alc268_acer_capture_source = {
10116         .num_items = 3,
10117         .items = {
10118                 { "Mic", 0x0 },
10119                 { "Internal Mic", 0x6 },
10120                 { "Line", 0x2 },
10121         },
10122 };
10123
10124 #ifdef CONFIG_SND_DEBUG
10125 static struct snd_kcontrol_new alc268_test_mixer[] = {
10126         /* Volume widgets */
10127         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10128         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
10129         HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
10130         HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
10131         HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
10132         HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
10133         HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
10134         HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
10135         HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
10136         HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
10137         HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
10138         HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
10139         HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
10140         /* The below appears problematic on some hardwares */
10141         /*HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),*/
10142         HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
10143         HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
10144         HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
10145         HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),
10146
10147         /* Modes for retasking pin widgets */
10148         ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
10149         ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
10150         ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
10151         ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),
10152
10153         /* Controls for GPIO pins, assuming they are configured as outputs */
10154         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
10155         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
10156         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
10157         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
10158
10159         /* Switches to allow the digital SPDIF output pin to be enabled.
10160          * The ALC268 does not have an SPDIF input.
10161          */
10162         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),
10163
10164         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
10165          * this output to turn on an external amplifier.
10166          */
10167         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
10168         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
10169
10170         { } /* end */
10171 };
10172 #endif
10173
10174 /* create input playback/capture controls for the given pin */
10175 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
10176                                     const char *ctlname, int idx)
10177 {
10178         char name[32];
10179         int err;
10180
10181         sprintf(name, "%s Playback Volume", ctlname);
10182         if (nid == 0x14) {
10183                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
10184                                   HDA_COMPOSE_AMP_VAL(0x02, 3, idx,
10185                                                       HDA_OUTPUT));
10186                 if (err < 0)
10187                         return err;
10188         } else if (nid == 0x15) {
10189                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
10190                                   HDA_COMPOSE_AMP_VAL(0x03, 3, idx,
10191                                                       HDA_OUTPUT));
10192                 if (err < 0)
10193                         return err;
10194         } else
10195                 return -1;
10196         sprintf(name, "%s Playback Switch", ctlname);
10197         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
10198                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
10199         if (err < 0)
10200                 return err;
10201         return 0;
10202 }
10203
10204 /* add playback controls from the parsed DAC table */
10205 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
10206                                              const struct auto_pin_cfg *cfg)
10207 {
10208         hda_nid_t nid;
10209         int err;
10210
10211         spec->multiout.num_dacs = 2;    /* only use one dac */
10212         spec->multiout.dac_nids = spec->private_dac_nids;
10213         spec->multiout.dac_nids[0] = 2;
10214         spec->multiout.dac_nids[1] = 3;
10215
10216         nid = cfg->line_out_pins[0];
10217         if (nid)
10218                 alc268_new_analog_output(spec, nid, "Front", 0);        
10219
10220         nid = cfg->speaker_pins[0];
10221         if (nid == 0x1d) {
10222                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
10223                                   "Speaker Playback Volume",
10224                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
10225                 if (err < 0)
10226                         return err;
10227         }
10228         nid = cfg->hp_pins[0];
10229         if (nid)
10230                 alc268_new_analog_output(spec, nid, "Headphone", 0);
10231
10232         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
10233         if (nid == 0x16) {
10234                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10235                                   "Mono Playback Switch",
10236                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_INPUT));
10237                 if (err < 0)
10238                         return err;
10239         }
10240         return 0;       
10241 }
10242
10243 /* create playback/capture controls for input pins */
10244 static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
10245                                                 const struct auto_pin_cfg *cfg)
10246 {
10247         struct hda_input_mux *imux = &spec->private_imux;
10248         int i, idx1;
10249
10250         for (i = 0; i < AUTO_PIN_LAST; i++) {
10251                 switch(cfg->input_pins[i]) {
10252                 case 0x18:
10253                         idx1 = 0;       /* Mic 1 */
10254                         break;
10255                 case 0x19:
10256                         idx1 = 1;       /* Mic 2 */
10257                         break;
10258                 case 0x1a:
10259                         idx1 = 2;       /* Line In */
10260                         break;
10261                 case 0x1c:      
10262                         idx1 = 3;       /* CD */
10263                         break;
10264                 case 0x12:
10265                 case 0x13:
10266                         idx1 = 6;       /* digital mics */
10267                         break;
10268                 default:
10269                         continue;
10270                 }
10271                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
10272                 imux->items[imux->num_items].index = idx1;
10273                 imux->num_items++;      
10274         }
10275         return 0;
10276 }
10277
10278 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
10279 {
10280         struct alc_spec *spec = codec->spec;
10281         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
10282         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
10283         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
10284         unsigned int    dac_vol1, dac_vol2;
10285
10286         if (speaker_nid) {
10287                 snd_hda_codec_write(codec, speaker_nid, 0,
10288                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
10289                 snd_hda_codec_write(codec, 0x0f, 0,
10290                                     AC_VERB_SET_AMP_GAIN_MUTE,
10291                                     AMP_IN_UNMUTE(1));
10292                 snd_hda_codec_write(codec, 0x10, 0,
10293                                     AC_VERB_SET_AMP_GAIN_MUTE,
10294                                     AMP_IN_UNMUTE(1));
10295         } else {
10296                 snd_hda_codec_write(codec, 0x0f, 0,
10297                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
10298                 snd_hda_codec_write(codec, 0x10, 0,
10299                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
10300         }
10301
10302         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
10303         if (line_nid == 0x14)   
10304                 dac_vol2 = AMP_OUT_ZERO;
10305         else if (line_nid == 0x15)
10306                 dac_vol1 = AMP_OUT_ZERO;
10307         if (hp_nid == 0x14)     
10308                 dac_vol2 = AMP_OUT_ZERO;
10309         else if (hp_nid == 0x15)
10310                 dac_vol1 = AMP_OUT_ZERO;
10311         if (line_nid != 0x16 || hp_nid != 0x16 ||
10312             spec->autocfg.line_out_pins[1] != 0x16 ||
10313             spec->autocfg.line_out_pins[2] != 0x16)
10314                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
10315
10316         snd_hda_codec_write(codec, 0x02, 0,
10317                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
10318         snd_hda_codec_write(codec, 0x03, 0,
10319                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
10320 }
10321
10322 /* pcm configuration: identiacal with ALC880 */
10323 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
10324 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
10325 #define alc268_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
10326 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
10327
10328 /*
10329  * BIOS auto configuration
10330  */
10331 static int alc268_parse_auto_config(struct hda_codec *codec)
10332 {
10333         struct alc_spec *spec = codec->spec;
10334         int err;
10335         static hda_nid_t alc268_ignore[] = { 0 };
10336
10337         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
10338                                            alc268_ignore);
10339         if (err < 0)
10340                 return err;
10341         if (!spec->autocfg.line_outs)
10342                 return 0; /* can't find valid BIOS pin config */
10343
10344         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
10345         if (err < 0)
10346                 return err;
10347         err = alc268_auto_create_analog_input_ctls(spec, &spec->autocfg);
10348         if (err < 0)
10349                 return err;
10350
10351         spec->multiout.max_channels = 2;
10352
10353         /* digital only support output */
10354         if (spec->autocfg.dig_out_pin)
10355                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
10356
10357         if (spec->kctl_alloc)
10358                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
10359
10360         if (spec->autocfg.speaker_pins[0] != 0x1d)
10361                 spec->mixers[spec->num_mixers++] = alc268_beep_mixer;
10362
10363         spec->init_verbs[spec->num_init_verbs++] = alc268_volume_init_verbs;
10364         spec->num_mux_defs = 1;
10365         spec->input_mux = &spec->private_imux;
10366
10367         err = alc_auto_add_mic_boost(codec);
10368         if (err < 0)
10369                 return err;
10370
10371         return 1;
10372 }
10373
10374 #define alc268_auto_init_multi_out      alc882_auto_init_multi_out
10375 #define alc268_auto_init_hp_out         alc882_auto_init_hp_out
10376 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
10377
10378 /* init callback for auto-configuration model -- overriding the default init */
10379 static void alc268_auto_init(struct hda_codec *codec)
10380 {
10381         struct alc_spec *spec = codec->spec;
10382         alc268_auto_init_multi_out(codec);
10383         alc268_auto_init_hp_out(codec);
10384         alc268_auto_init_mono_speaker_out(codec);
10385         alc268_auto_init_analog_input(codec);
10386         if (spec->unsol_event)
10387                 alc_sku_automute(codec);
10388 }
10389
10390 /*
10391  * configuration and preset
10392  */
10393 static const char *alc268_models[ALC268_MODEL_LAST] = {
10394         [ALC267_QUANTA_IL1]     = "quanta-il1",
10395         [ALC268_3ST]            = "3stack",
10396         [ALC268_TOSHIBA]        = "toshiba",
10397         [ALC268_ACER]           = "acer",
10398         [ALC268_DELL]           = "dell",
10399         [ALC268_ZEPTO]          = "zepto",
10400 #ifdef CONFIG_SND_DEBUG
10401         [ALC268_TEST]           = "test",
10402 #endif
10403         [ALC268_AUTO]           = "auto",
10404 };
10405
10406 static struct snd_pci_quirk alc268_cfg_tbl[] = {
10407         SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
10408         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
10409         SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
10410         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
10411         SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER),
10412         SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
10413         SND_PCI_QUIRK(0x103c, 0x30cc, "TOSHIBA", ALC268_TOSHIBA),
10414         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
10415         SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA),
10416         SND_PCI_QUIRK(0x1179, 0xff50, "TOSHIBA A305", ALC268_TOSHIBA),
10417         SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
10418         SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
10419         SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
10420         {}
10421 };
10422
10423 static struct alc_config_preset alc268_presets[] = {
10424         [ALC267_QUANTA_IL1] = {
10425                 .mixers = { alc267_quanta_il1_mixer },
10426                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10427                                 alc267_quanta_il1_verbs },
10428                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10429                 .dac_nids = alc268_dac_nids,
10430                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10431                 .adc_nids = alc268_adc_nids_alt,
10432                 .hp_nid = 0x03,
10433                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10434                 .channel_mode = alc268_modes,
10435                 .input_mux = &alc268_capture_source,
10436                 .unsol_event = alc267_quanta_il1_unsol_event,
10437                 .init_hook = alc267_quanta_il1_automute,
10438         },
10439         [ALC268_3ST] = {
10440                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
10441                             alc268_beep_mixer },
10442                 .init_verbs = { alc268_base_init_verbs },
10443                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10444                 .dac_nids = alc268_dac_nids,
10445                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10446                 .adc_nids = alc268_adc_nids_alt,
10447                 .capsrc_nids = alc268_capsrc_nids,
10448                 .hp_nid = 0x03,
10449                 .dig_out_nid = ALC268_DIGOUT_NID,
10450                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10451                 .channel_mode = alc268_modes,
10452                 .input_mux = &alc268_capture_source,
10453         },
10454         [ALC268_TOSHIBA] = {
10455                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
10456                             alc268_beep_mixer },
10457                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10458                                 alc268_toshiba_verbs },
10459                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10460                 .dac_nids = alc268_dac_nids,
10461                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10462                 .adc_nids = alc268_adc_nids_alt,
10463                 .capsrc_nids = alc268_capsrc_nids,
10464                 .hp_nid = 0x03,
10465                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10466                 .channel_mode = alc268_modes,
10467                 .input_mux = &alc268_capture_source,
10468                 .unsol_event = alc268_toshiba_unsol_event,
10469                 .init_hook = alc268_toshiba_automute,
10470         },
10471         [ALC268_ACER] = {
10472                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
10473                             alc268_beep_mixer },
10474                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10475                                 alc268_acer_verbs },
10476                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10477                 .dac_nids = alc268_dac_nids,
10478                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10479                 .adc_nids = alc268_adc_nids_alt,
10480                 .capsrc_nids = alc268_capsrc_nids,
10481                 .hp_nid = 0x02,
10482                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10483                 .channel_mode = alc268_modes,
10484                 .input_mux = &alc268_acer_capture_source,
10485                 .unsol_event = alc268_acer_unsol_event,
10486                 .init_hook = alc268_acer_init_hook,
10487         },
10488         [ALC268_DELL] = {
10489                 .mixers = { alc268_dell_mixer, alc268_beep_mixer },
10490                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10491                                 alc268_dell_verbs },
10492                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10493                 .dac_nids = alc268_dac_nids,
10494                 .hp_nid = 0x02,
10495                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10496                 .channel_mode = alc268_modes,
10497                 .unsol_event = alc268_dell_unsol_event,
10498                 .init_hook = alc268_dell_init_hook,
10499                 .input_mux = &alc268_capture_source,
10500         },
10501         [ALC268_ZEPTO] = {
10502                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
10503                             alc268_beep_mixer },
10504                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10505                                 alc268_toshiba_verbs },
10506                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10507                 .dac_nids = alc268_dac_nids,
10508                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10509                 .adc_nids = alc268_adc_nids_alt,
10510                 .capsrc_nids = alc268_capsrc_nids,
10511                 .hp_nid = 0x03,
10512                 .dig_out_nid = ALC268_DIGOUT_NID,
10513                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10514                 .channel_mode = alc268_modes,
10515                 .input_mux = &alc268_capture_source,
10516                 .unsol_event = alc268_toshiba_unsol_event,
10517                 .init_hook = alc268_toshiba_automute
10518         },
10519 #ifdef CONFIG_SND_DEBUG
10520         [ALC268_TEST] = {
10521                 .mixers = { alc268_test_mixer, alc268_capture_mixer },
10522                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10523                                 alc268_volume_init_verbs },
10524                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10525                 .dac_nids = alc268_dac_nids,
10526                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10527                 .adc_nids = alc268_adc_nids_alt,
10528                 .capsrc_nids = alc268_capsrc_nids,
10529                 .hp_nid = 0x03,
10530                 .dig_out_nid = ALC268_DIGOUT_NID,
10531                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10532                 .channel_mode = alc268_modes,
10533                 .input_mux = &alc268_capture_source,
10534         },
10535 #endif
10536 };
10537
10538 static int patch_alc268(struct hda_codec *codec)
10539 {
10540         struct alc_spec *spec;
10541         int board_config;
10542         int err;
10543
10544         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
10545         if (spec == NULL)
10546                 return -ENOMEM;
10547
10548         codec->spec = spec;
10549
10550         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
10551                                                   alc268_models,
10552                                                   alc268_cfg_tbl);
10553
10554         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
10555                 printk(KERN_INFO "hda_codec: Unknown model for ALC268, "
10556                        "trying auto-probe from BIOS...\n");
10557                 board_config = ALC268_AUTO;
10558         }
10559
10560         if (board_config == ALC268_AUTO) {
10561                 /* automatic parse from the BIOS config */
10562                 err = alc268_parse_auto_config(codec);
10563                 if (err < 0) {
10564                         alc_free(codec);
10565                         return err;
10566                 } else if (!err) {
10567                         printk(KERN_INFO
10568                                "hda_codec: Cannot set up configuration "
10569                                "from BIOS.  Using base mode...\n");
10570                         board_config = ALC268_3ST;
10571                 }
10572         }
10573
10574         if (board_config != ALC268_AUTO)
10575                 setup_preset(spec, &alc268_presets[board_config]);
10576
10577         spec->stream_name_analog = "ALC268 Analog";
10578         spec->stream_analog_playback = &alc268_pcm_analog_playback;
10579         spec->stream_analog_capture = &alc268_pcm_analog_capture;
10580         spec->stream_analog_alt_capture = &alc268_pcm_analog_alt_capture;
10581
10582         spec->stream_name_digital = "ALC268 Digital";
10583         spec->stream_digital_playback = &alc268_pcm_digital_playback;
10584
10585         if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
10586                 /* override the amp caps for beep generator */
10587                 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
10588                                           (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
10589                                           (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
10590                                           (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
10591                                           (0 << AC_AMPCAP_MUTE_SHIFT));
10592
10593         if (!spec->adc_nids && spec->input_mux) {
10594                 /* check whether NID 0x07 is valid */
10595                 unsigned int wcap = get_wcaps(codec, 0x07);
10596                 int i;
10597
10598                 /* get type */
10599                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
10600                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
10601                         spec->adc_nids = alc268_adc_nids_alt;
10602                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
10603                         spec->mixers[spec->num_mixers] =
10604                                         alc268_capture_alt_mixer;
10605                         spec->num_mixers++;
10606                 } else {
10607                         spec->adc_nids = alc268_adc_nids;
10608                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
10609                         spec->mixers[spec->num_mixers] =
10610                                 alc268_capture_mixer;
10611                         spec->num_mixers++;
10612                 }
10613                 spec->capsrc_nids = alc268_capsrc_nids;
10614                 /* set default input source */
10615                 for (i = 0; i < spec->num_adc_nids; i++)
10616                         snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
10617                                 0, AC_VERB_SET_CONNECT_SEL,
10618                                 spec->input_mux->items[0].index);
10619         }
10620
10621         spec->vmaster_nid = 0x02;
10622
10623         codec->patch_ops = alc_patch_ops;
10624         if (board_config == ALC268_AUTO)
10625                 spec->init_hook = alc268_auto_init;
10626                 
10627         return 0;
10628 }
10629
10630 /*
10631  *  ALC269 channel source setting (2 channel)
10632  */
10633 #define ALC269_DIGOUT_NID       ALC880_DIGOUT_NID
10634
10635 #define alc269_dac_nids         alc260_dac_nids
10636
10637 static hda_nid_t alc269_adc_nids[1] = {
10638         /* ADC1 */
10639         0x07,
10640 };
10641
10642 #define alc269_modes            alc260_modes
10643 #define alc269_capture_source   alc880_lg_lw_capture_source
10644
10645 static struct snd_kcontrol_new alc269_base_mixer[] = {
10646         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10647         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10648         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10649         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10650         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10651         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10652         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10653         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10654         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10655         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10656         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10657         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
10658         { } /* end */
10659 };
10660
10661 /* capture mixer elements */
10662 static struct snd_kcontrol_new alc269_capture_mixer[] = {
10663         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
10664         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
10665         {
10666                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10667                 /* The multiple "Capture Source" controls confuse alsamixer
10668                  * So call somewhat different..
10669                  */
10670                 /* .name = "Capture Source", */
10671                 .name = "Input Source",
10672                 .count = 1,
10673                 .info = alc_mux_enum_info,
10674                 .get = alc_mux_enum_get,
10675                 .put = alc_mux_enum_put,
10676         },
10677         { } /* end */
10678 };
10679
10680 /*
10681  * generic initialization of ADC, input mixers and output mixers
10682  */
10683 static struct hda_verb alc269_init_verbs[] = {
10684         /*
10685          * Unmute ADC0 and set the default input to mic-in
10686          */
10687         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10688
10689         /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the
10690          * analog-loopback mixer widget
10691          * Note: PASD motherboards uses the Line In 2 as the input for
10692          * front panel mic (mic 2)
10693          */
10694         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10695         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10696         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10697         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10698         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10699         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10700
10701         /*
10702          * Set up output mixers (0x0c - 0x0e)
10703          */
10704         /* set vol=0 to output mixers */
10705         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10706         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10707
10708         /* set up input amps for analog loopback */
10709         /* Amp Indices: DAC = 0, mixer = 1 */
10710         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10711         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10712         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10713         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10714         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10715         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10716
10717         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10718         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10719         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10720         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10721         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10722         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10723         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10724
10725         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10726         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10727         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10728         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10729         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10730         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10731         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10732
10733         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
10734         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10735
10736         /* FIXME: use matrix-type input source selection */
10737         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
10738         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10739         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10740         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10741         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10742         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10743
10744         /* set EAPD */
10745         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
10746         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
10747         { }
10748 };
10749
10750 /* add playback controls from the parsed DAC table */
10751 static int alc269_auto_create_multi_out_ctls(struct alc_spec *spec,
10752                                              const struct auto_pin_cfg *cfg)
10753 {
10754         hda_nid_t nid;
10755         int err;
10756
10757         spec->multiout.num_dacs = 1;    /* only use one dac */
10758         spec->multiout.dac_nids = spec->private_dac_nids;
10759         spec->multiout.dac_nids[0] = 2;
10760
10761         nid = cfg->line_out_pins[0];
10762         if (nid) {
10763                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
10764                                   "Front Playback Volume",
10765                                   HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT));
10766                 if (err < 0)
10767                         return err;
10768                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10769                                   "Front Playback Switch",
10770                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
10771                 if (err < 0)
10772                         return err;
10773         }
10774
10775         nid = cfg->speaker_pins[0];
10776         if (nid) {
10777                 if (!cfg->line_out_pins[0]) {
10778                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10779                                           "Speaker Playback Volume",
10780                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
10781                                                               HDA_OUTPUT));
10782                         if (err < 0)
10783                                 return err;
10784                 }
10785                 if (nid == 0x16) {
10786                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10787                                           "Speaker Playback Switch",
10788                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10789                                                               HDA_OUTPUT));
10790                         if (err < 0)
10791                                 return err;
10792                 } else {
10793                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10794                                           "Speaker Playback Switch",
10795                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10796                                                               HDA_OUTPUT));
10797                         if (err < 0)
10798                                 return err;
10799                 }
10800         }
10801         nid = cfg->hp_pins[0];
10802         if (nid) {
10803                 /* spec->multiout.hp_nid = 2; */
10804                 if (!cfg->line_out_pins[0] && !cfg->speaker_pins[0]) {
10805                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10806                                           "Headphone Playback Volume",
10807                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
10808                                                               HDA_OUTPUT));
10809                         if (err < 0)
10810                                 return err;
10811                 }
10812                 if (nid == 0x16) {
10813                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10814                                           "Headphone Playback Switch",
10815                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10816                                                               HDA_OUTPUT));
10817                         if (err < 0)
10818                                 return err;
10819                 } else {
10820                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10821                                           "Headphone Playback Switch",
10822                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10823                                                               HDA_OUTPUT));
10824                         if (err < 0)
10825                                 return err;
10826                 }
10827         }
10828         return 0;
10829 }
10830
10831 #define alc269_auto_create_analog_input_ctls \
10832         alc880_auto_create_analog_input_ctls
10833
10834 #ifdef CONFIG_SND_HDA_POWER_SAVE
10835 #define alc269_loopbacks        alc880_loopbacks
10836 #endif
10837
10838 /* pcm configuration: identiacal with ALC880 */
10839 #define alc269_pcm_analog_playback      alc880_pcm_analog_playback
10840 #define alc269_pcm_analog_capture       alc880_pcm_analog_capture
10841 #define alc269_pcm_digital_playback     alc880_pcm_digital_playback
10842 #define alc269_pcm_digital_capture      alc880_pcm_digital_capture
10843
10844 /*
10845  * BIOS auto configuration
10846  */
10847 static int alc269_parse_auto_config(struct hda_codec *codec)
10848 {
10849         struct alc_spec *spec = codec->spec;
10850         int err;
10851         static hda_nid_t alc269_ignore[] = { 0x1d, 0 };
10852
10853         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
10854                                            alc269_ignore);
10855         if (err < 0)
10856                 return err;
10857
10858         err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
10859         if (err < 0)
10860                 return err;
10861         err = alc269_auto_create_analog_input_ctls(spec, &spec->autocfg);
10862         if (err < 0)
10863                 return err;
10864
10865         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
10866
10867         if (spec->autocfg.dig_out_pin)
10868                 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;
10869
10870         if (spec->kctl_alloc)
10871                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
10872
10873         spec->init_verbs[spec->num_init_verbs++] = alc269_init_verbs;
10874         spec->num_mux_defs = 1;
10875         spec->input_mux = &spec->private_imux;
10876
10877         err = alc_auto_add_mic_boost(codec);
10878         if (err < 0)
10879                 return err;
10880
10881         return 1;
10882 }
10883
10884 #define alc269_auto_init_multi_out      alc882_auto_init_multi_out
10885 #define alc269_auto_init_hp_out         alc882_auto_init_hp_out
10886 #define alc269_auto_init_analog_input   alc882_auto_init_analog_input
10887
10888
10889 /* init callback for auto-configuration model -- overriding the default init */
10890 static void alc269_auto_init(struct hda_codec *codec)
10891 {
10892         struct alc_spec *spec = codec->spec;
10893         alc269_auto_init_multi_out(codec);
10894         alc269_auto_init_hp_out(codec);
10895         alc269_auto_init_analog_input(codec);
10896         if (spec->unsol_event)
10897                 alc_sku_automute(codec);
10898 }
10899
10900 /*
10901  * configuration and preset
10902  */
10903 static const char *alc269_models[ALC269_MODEL_LAST] = {
10904         [ALC269_BASIC]          = "basic",
10905 };
10906
10907 static struct snd_pci_quirk alc269_cfg_tbl[] = {
10908         {}
10909 };
10910
10911 static struct alc_config_preset alc269_presets[] = {
10912         [ALC269_BASIC] = {
10913                 .mixers = { alc269_base_mixer },
10914                 .init_verbs = { alc269_init_verbs },
10915                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
10916                 .dac_nids = alc269_dac_nids,
10917                 .hp_nid = 0x03,
10918                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
10919                 .channel_mode = alc269_modes,
10920                 .input_mux = &alc269_capture_source,
10921         },
10922 };
10923
10924 static int patch_alc269(struct hda_codec *codec)
10925 {
10926         struct alc_spec *spec;
10927         int board_config;
10928         int err;
10929
10930         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
10931         if (spec == NULL)
10932                 return -ENOMEM;
10933
10934         codec->spec = spec;
10935
10936         board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
10937                                                   alc269_models,
10938                                                   alc269_cfg_tbl);
10939
10940         if (board_config < 0) {
10941                 printk(KERN_INFO "hda_codec: Unknown model for ALC269, "
10942                        "trying auto-probe from BIOS...\n");
10943                 board_config = ALC269_AUTO;
10944         }
10945
10946         if (board_config == ALC269_AUTO) {
10947                 /* automatic parse from the BIOS config */
10948                 err = alc269_parse_auto_config(codec);
10949                 if (err < 0) {
10950                         alc_free(codec);
10951                         return err;
10952                 } else if (!err) {
10953                         printk(KERN_INFO
10954                                "hda_codec: Cannot set up configuration "
10955                                "from BIOS.  Using base mode...\n");
10956                         board_config = ALC269_BASIC;
10957                 }
10958         }
10959
10960         if (board_config != ALC269_AUTO)
10961                 setup_preset(spec, &alc269_presets[board_config]);
10962
10963         spec->stream_name_analog = "ALC269 Analog";
10964         spec->stream_analog_playback = &alc269_pcm_analog_playback;
10965         spec->stream_analog_capture = &alc269_pcm_analog_capture;
10966
10967         spec->stream_name_digital = "ALC269 Digital";
10968         spec->stream_digital_playback = &alc269_pcm_digital_playback;
10969         spec->stream_digital_capture = &alc269_pcm_digital_capture;
10970
10971         spec->adc_nids = alc269_adc_nids;
10972         spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
10973         spec->mixers[spec->num_mixers] = alc269_capture_mixer;
10974         spec->num_mixers++;
10975
10976         codec->patch_ops = alc_patch_ops;
10977         if (board_config == ALC269_AUTO)
10978                 spec->init_hook = alc269_auto_init;
10979 #ifdef CONFIG_SND_HDA_POWER_SAVE
10980         if (!spec->loopback.amplist)
10981                 spec->loopback.amplist = alc269_loopbacks;
10982 #endif
10983
10984         return 0;
10985 }
10986
10987 /*
10988  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
10989  */
10990
10991 /*
10992  * set the path ways for 2 channel output
10993  * need to set the codec line out and mic 1 pin widgets to inputs
10994  */
10995 static struct hda_verb alc861_threestack_ch2_init[] = {
10996         /* set pin widget 1Ah (line in) for input */
10997         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
10998         /* set pin widget 18h (mic1/2) for input, for mic also enable
10999          * the vref
11000          */
11001         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11002
11003         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
11004 #if 0
11005         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
11006         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
11007 #endif
11008         { } /* end */
11009 };
11010 /*
11011  * 6ch mode
11012  * need to set the codec line out and mic 1 pin widgets to outputs
11013  */
11014 static struct hda_verb alc861_threestack_ch6_init[] = {
11015         /* set pin widget 1Ah (line in) for output (Back Surround)*/
11016         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11017         /* set pin widget 18h (mic1) for output (CLFE)*/
11018         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11019
11020         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
11021         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
11022
11023         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
11024 #if 0
11025         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
11026         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
11027 #endif
11028         { } /* end */
11029 };
11030
11031 static struct hda_channel_mode alc861_threestack_modes[2] = {
11032         { 2, alc861_threestack_ch2_init },
11033         { 6, alc861_threestack_ch6_init },
11034 };
11035 /* Set mic1 as input and unmute the mixer */
11036 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
11037         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11038         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
11039         { } /* end */
11040 };
11041 /* Set mic1 as output and mute mixer */
11042 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
11043         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11044         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
11045         { } /* end */
11046 };
11047
11048 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
11049         { 2, alc861_uniwill_m31_ch2_init },
11050         { 4, alc861_uniwill_m31_ch4_init },
11051 };
11052
11053 /* Set mic1 and line-in as input and unmute the mixer */
11054 static struct hda_verb alc861_asus_ch2_init[] = {
11055         /* set pin widget 1Ah (line in) for input */
11056         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11057         /* set pin widget 18h (mic1/2) for input, for mic also enable
11058          * the vref
11059          */
11060         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11061
11062         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
11063 #if 0
11064         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
11065         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
11066 #endif
11067         { } /* end */
11068 };
11069 /* Set mic1 nad line-in as output and mute mixer */
11070 static struct hda_verb alc861_asus_ch6_init[] = {
11071         /* set pin widget 1Ah (line in) for output (Back Surround)*/
11072         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11073         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
11074         /* set pin widget 18h (mic1) for output (CLFE)*/
11075         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11076         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
11077         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
11078         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
11079
11080         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
11081 #if 0
11082         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
11083         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
11084 #endif
11085         { } /* end */
11086 };
11087
11088 static struct hda_channel_mode alc861_asus_modes[2] = {
11089         { 2, alc861_asus_ch2_init },
11090         { 6, alc861_asus_ch6_init },
11091 };
11092
11093 /* patch-ALC861 */
11094
11095 static struct snd_kcontrol_new alc861_base_mixer[] = {
11096         /* output mixer control */
11097         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11098         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
11099         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
11100         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
11101         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
11102
11103         /*Input mixer control */
11104         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
11105            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
11106         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11107         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11108         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
11109         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
11110         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11111         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11112         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
11113         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
11114
11115         /* Capture mixer control */
11116         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11117         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11118         {
11119                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11120                 .name = "Capture Source",
11121                 .count = 1,
11122                 .info = alc_mux_enum_info,
11123                 .get = alc_mux_enum_get,
11124                 .put = alc_mux_enum_put,
11125         },
11126         { } /* end */
11127 };
11128
11129 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
11130         /* output mixer control */
11131         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11132         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
11133         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
11134         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
11135         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
11136
11137         /* Input mixer control */
11138         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
11139            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
11140         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11141         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11142         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
11143         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
11144         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11145         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11146         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
11147         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
11148
11149         /* Capture mixer control */
11150         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11151         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11152         {
11153                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11154                 .name = "Capture Source",
11155                 .count = 1,
11156                 .info = alc_mux_enum_info,
11157                 .get = alc_mux_enum_get,
11158                 .put = alc_mux_enum_put,
11159         },
11160         {
11161                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11162                 .name = "Channel Mode",
11163                 .info = alc_ch_mode_info,
11164                 .get = alc_ch_mode_get,
11165                 .put = alc_ch_mode_put,
11166                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
11167         },
11168         { } /* end */
11169 };
11170
11171 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
11172         /* output mixer control */
11173         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11174         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11175         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11176         
11177         /*Capture mixer control */
11178         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11179         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11180         {
11181                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11182                 .name = "Capture Source",
11183                 .count = 1,
11184                 .info = alc_mux_enum_info,
11185                 .get = alc_mux_enum_get,
11186                 .put = alc_mux_enum_put,
11187         },
11188
11189         { } /* end */
11190 };
11191
11192 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
11193         /* output mixer control */
11194         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11195         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
11196         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
11197         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
11198         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
11199
11200         /* Input mixer control */
11201         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
11202            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
11203         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11204         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11205         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
11206         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
11207         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11208         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11209         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
11210         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
11211
11212         /* Capture mixer control */
11213         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11214         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11215         {
11216                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11217                 .name = "Capture Source",
11218                 .count = 1,
11219                 .info = alc_mux_enum_info,
11220                 .get = alc_mux_enum_get,
11221                 .put = alc_mux_enum_put,
11222         },
11223         {
11224                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11225                 .name = "Channel Mode",
11226                 .info = alc_ch_mode_info,
11227                 .get = alc_ch_mode_get,
11228                 .put = alc_ch_mode_put,
11229                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
11230         },
11231         { } /* end */
11232 };
11233
11234 static struct snd_kcontrol_new alc861_asus_mixer[] = {
11235         /* output mixer control */
11236         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11237         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
11238         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
11239         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
11240         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
11241
11242         /* Input mixer control */
11243         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
11244         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11245         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11246         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11247         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
11248         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
11249         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11250         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11251         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
11252         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
11253
11254         /* Capture mixer control */
11255         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11256         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11257         {
11258                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11259                 .name = "Capture Source",
11260                 .count = 1,
11261                 .info = alc_mux_enum_info,
11262                 .get = alc_mux_enum_get,
11263                 .put = alc_mux_enum_put,
11264         },
11265         {
11266                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11267                 .name = "Channel Mode",
11268                 .info = alc_ch_mode_info,
11269                 .get = alc_ch_mode_get,
11270                 .put = alc_ch_mode_put,
11271                 .private_value = ARRAY_SIZE(alc861_asus_modes),
11272         },
11273         { }
11274 };
11275
11276 /* additional mixer */
11277 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
11278         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11279         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11280         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x23, 0x0, HDA_OUTPUT),
11281         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x23, 0x0, HDA_OUTPUT),
11282         { }
11283 };
11284
11285 /*
11286  * generic initialization of ADC, input mixers and output mixers
11287  */
11288 static struct hda_verb alc861_base_init_verbs[] = {
11289         /*
11290          * Unmute ADC0 and set the default input to mic-in
11291          */
11292         /* port-A for surround (rear panel) */
11293         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11294         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
11295         /* port-B for mic-in (rear panel) with vref */
11296         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11297         /* port-C for line-in (rear panel) */
11298         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11299         /* port-D for Front */
11300         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11301         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
11302         /* port-E for HP out (front panel) */
11303         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
11304         /* route front PCM to HP */
11305         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
11306         /* port-F for mic-in (front panel) with vref */
11307         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11308         /* port-G for CLFE (rear panel) */
11309         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11310         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
11311         /* port-H for side (rear panel) */
11312         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11313         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
11314         /* CD-in */
11315         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11316         /* route front mic to ADC1*/
11317         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11318         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11319         
11320         /* Unmute DAC0~3 & spdif out*/
11321         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11322         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11323         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11324         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11325         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11326         
11327         /* Unmute Mixer 14 (mic) 1c (Line in)*/
11328         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11329         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11330         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11331         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11332         
11333         /* Unmute Stereo Mixer 15 */
11334         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11335         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11336         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11337         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
11338
11339         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11340         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11341         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11342         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11343         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11344         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11345         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11346         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11347         /* hp used DAC 3 (Front) */
11348         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
11349         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11350
11351         { }
11352 };
11353
11354 static struct hda_verb alc861_threestack_init_verbs[] = {
11355         /*
11356          * Unmute ADC0 and set the default input to mic-in
11357          */
11358         /* port-A for surround (rear panel) */
11359         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11360         /* port-B for mic-in (rear panel) with vref */
11361         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11362         /* port-C for line-in (rear panel) */
11363         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11364         /* port-D for Front */
11365         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11366         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
11367         /* port-E for HP out (front panel) */
11368         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
11369         /* route front PCM to HP */
11370         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
11371         /* port-F for mic-in (front panel) with vref */
11372         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11373         /* port-G for CLFE (rear panel) */
11374         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11375         /* port-H for side (rear panel) */
11376         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11377         /* CD-in */
11378         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11379         /* route front mic to ADC1*/
11380         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11381         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11382         /* Unmute DAC0~3 & spdif out*/
11383         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11384         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11385         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11386         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11387         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11388         
11389         /* Unmute Mixer 14 (mic) 1c (Line in)*/
11390         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11391         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11392         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11393         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11394         
11395         /* Unmute Stereo Mixer 15 */
11396         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11397         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11398         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11399         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
11400
11401         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11402         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11403         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11404         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11405         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11406         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11407         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11408         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11409         /* hp used DAC 3 (Front) */
11410         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
11411         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11412         { }
11413 };
11414
11415 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
11416         /*
11417          * Unmute ADC0 and set the default input to mic-in
11418          */
11419         /* port-A for surround (rear panel) */
11420         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11421         /* port-B for mic-in (rear panel) with vref */
11422         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11423         /* port-C for line-in (rear panel) */
11424         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11425         /* port-D for Front */
11426         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11427         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
11428         /* port-E for HP out (front panel) */
11429         /* this has to be set to VREF80 */
11430         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11431         /* route front PCM to HP */
11432         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
11433         /* port-F for mic-in (front panel) with vref */
11434         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11435         /* port-G for CLFE (rear panel) */
11436         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11437         /* port-H for side (rear panel) */
11438         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11439         /* CD-in */
11440         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11441         /* route front mic to ADC1*/
11442         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11443         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11444         /* Unmute DAC0~3 & spdif out*/
11445         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11446         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11447         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11448         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11449         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11450         
11451         /* Unmute Mixer 14 (mic) 1c (Line in)*/
11452         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11453         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11454         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11455         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11456         
11457         /* Unmute Stereo Mixer 15 */
11458         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11459         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11460         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11461         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
11462
11463         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11464         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11465         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11466         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11467         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11468         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11469         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11470         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11471         /* hp used DAC 3 (Front) */
11472         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
11473         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11474         { }
11475 };
11476
11477 static struct hda_verb alc861_asus_init_verbs[] = {
11478         /*
11479          * Unmute ADC0 and set the default input to mic-in
11480          */
11481         /* port-A for surround (rear panel)
11482          * according to codec#0 this is the HP jack
11483          */
11484         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
11485         /* route front PCM to HP */
11486         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
11487         /* port-B for mic-in (rear panel) with vref */
11488         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11489         /* port-C for line-in (rear panel) */
11490         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11491         /* port-D for Front */
11492         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11493         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
11494         /* port-E for HP out (front panel) */
11495         /* this has to be set to VREF80 */
11496         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11497         /* route front PCM to HP */
11498         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
11499         /* port-F for mic-in (front panel) with vref */
11500         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11501         /* port-G for CLFE (rear panel) */
11502         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11503         /* port-H for side (rear panel) */
11504         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11505         /* CD-in */
11506         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11507         /* route front mic to ADC1*/
11508         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11509         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11510         /* Unmute DAC0~3 & spdif out*/
11511         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11512         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11513         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11514         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11515         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11516         /* Unmute Mixer 14 (mic) 1c (Line in)*/
11517         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11518         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11519         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11520         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11521         
11522         /* Unmute Stereo Mixer 15 */
11523         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11524         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11525         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11526         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
11527
11528         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11529         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11530         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11531         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11532         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11533         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11534         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11535         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11536         /* hp used DAC 3 (Front) */
11537         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
11538         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11539         { }
11540 };
11541
11542 /* additional init verbs for ASUS laptops */
11543 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
11544         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
11545         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
11546         { }
11547 };
11548
11549 /*
11550  * generic initialization of ADC, input mixers and output mixers
11551  */
11552 static struct hda_verb alc861_auto_init_verbs[] = {
11553         /*
11554          * Unmute ADC0 and set the default input to mic-in
11555          */
11556         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
11557         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11558         
11559         /* Unmute DAC0~3 & spdif out*/
11560         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11561         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11562         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11563         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11564         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11565         
11566         /* Unmute Mixer 14 (mic) 1c (Line in)*/
11567         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11568         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11569         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11570         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11571         
11572         /* Unmute Stereo Mixer 15 */
11573         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11574         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11575         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11576         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
11577
11578         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11579         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11580         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11581         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11582         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11583         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11584         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11585         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11586
11587         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11588         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11589         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11590         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
11591         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11592         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11593         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11594         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
11595
11596         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
11597
11598         { }
11599 };
11600
11601 static struct hda_verb alc861_toshiba_init_verbs[] = {
11602         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11603
11604         { }
11605 };
11606
11607 /* toggle speaker-output according to the hp-jack state */
11608 static void alc861_toshiba_automute(struct hda_codec *codec)
11609 {
11610         unsigned int present;
11611
11612         present = snd_hda_codec_read(codec, 0x0f, 0,
11613                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11614         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
11615                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
11616         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
11617                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
11618 }
11619
11620 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
11621                                        unsigned int res)
11622 {
11623         if ((res >> 26) == ALC880_HP_EVENT)
11624                 alc861_toshiba_automute(codec);
11625 }
11626
11627 /* pcm configuration: identiacal with ALC880 */
11628 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
11629 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
11630 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
11631 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
11632
11633
11634 #define ALC861_DIGOUT_NID       0x07
11635
11636 static struct hda_channel_mode alc861_8ch_modes[1] = {
11637         { 8, NULL }
11638 };
11639
11640 static hda_nid_t alc861_dac_nids[4] = {
11641         /* front, surround, clfe, side */
11642         0x03, 0x06, 0x05, 0x04
11643 };
11644
11645 static hda_nid_t alc660_dac_nids[3] = {
11646         /* front, clfe, surround */
11647         0x03, 0x05, 0x06
11648 };
11649
11650 static hda_nid_t alc861_adc_nids[1] = {
11651         /* ADC0-2 */
11652         0x08,
11653 };
11654
11655 static struct hda_input_mux alc861_capture_source = {
11656         .num_items = 5,
11657         .items = {
11658                 { "Mic", 0x0 },
11659                 { "Front Mic", 0x3 },
11660                 { "Line", 0x1 },
11661                 { "CD", 0x4 },
11662                 { "Mixer", 0x5 },
11663         },
11664 };
11665
11666 /* fill in the dac_nids table from the parsed pin configuration */
11667 static int alc861_auto_fill_dac_nids(struct alc_spec *spec,
11668                                      const struct auto_pin_cfg *cfg)
11669 {
11670         int i;
11671         hda_nid_t nid;
11672
11673         spec->multiout.dac_nids = spec->private_dac_nids;
11674         for (i = 0; i < cfg->line_outs; i++) {
11675                 nid = cfg->line_out_pins[i];
11676                 if (nid) {
11677                         if (i >= ARRAY_SIZE(alc861_dac_nids))
11678                                 continue;
11679                         spec->multiout.dac_nids[i] = alc861_dac_nids[i];
11680                 }
11681         }
11682         spec->multiout.num_dacs = cfg->line_outs;
11683         return 0;
11684 }
11685
11686 /* add playback controls from the parsed DAC table */
11687 static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
11688                                              const struct auto_pin_cfg *cfg)
11689 {
11690         char name[32];
11691         static const char *chname[4] = {
11692                 "Front", "Surround", NULL /*CLFE*/, "Side"
11693         };
11694         hda_nid_t nid;
11695         int i, idx, err;
11696
11697         for (i = 0; i < cfg->line_outs; i++) {
11698                 nid = spec->multiout.dac_nids[i];
11699                 if (!nid)
11700                         continue;
11701                 if (nid == 0x05) {
11702                         /* Center/LFE */
11703                         err = add_control(spec, ALC_CTL_BIND_MUTE,
11704                                           "Center Playback Switch",
11705                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
11706                                                               HDA_OUTPUT));
11707                         if (err < 0)
11708                                 return err;
11709                         err = add_control(spec, ALC_CTL_BIND_MUTE,
11710                                           "LFE Playback Switch",
11711                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
11712                                                               HDA_OUTPUT));
11713                         if (err < 0)
11714                                 return err;
11715                 } else {
11716                         for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1;
11717                              idx++)
11718                                 if (nid == alc861_dac_nids[idx])
11719                                         break;
11720                         sprintf(name, "%s Playback Switch", chname[idx]);
11721                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
11722                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
11723                                                               HDA_OUTPUT));
11724                         if (err < 0)
11725                                 return err;
11726                 }
11727         }
11728         return 0;
11729 }
11730
11731 static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
11732 {
11733         int err;
11734         hda_nid_t nid;
11735
11736         if (!pin)
11737                 return 0;
11738
11739         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
11740                 nid = 0x03;
11741                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11742                                   "Headphone Playback Switch",
11743                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
11744                 if (err < 0)
11745                         return err;
11746                 spec->multiout.hp_nid = nid;
11747         }
11748         return 0;
11749 }
11750
11751 /* create playback/capture controls for input pins */
11752 static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec,
11753                                                 const struct auto_pin_cfg *cfg)
11754 {
11755         struct hda_input_mux *imux = &spec->private_imux;
11756         int i, err, idx, idx1;
11757
11758         for (i = 0; i < AUTO_PIN_LAST; i++) {
11759                 switch (cfg->input_pins[i]) {
11760                 case 0x0c:
11761                         idx1 = 1;
11762                         idx = 2;        /* Line In */
11763                         break;
11764                 case 0x0f:
11765                         idx1 = 2;
11766                         idx = 2;        /* Line In */
11767                         break;
11768                 case 0x0d:
11769                         idx1 = 0;
11770                         idx = 1;        /* Mic In */
11771                         break;
11772                 case 0x10:
11773                         idx1 = 3;
11774                         idx = 1;        /* Mic In */
11775                         break;
11776                 case 0x11:
11777                         idx1 = 4;
11778                         idx = 0;        /* CD */
11779                         break;
11780                 default:
11781                         continue;
11782                 }
11783
11784                 err = new_analog_input(spec, cfg->input_pins[i],
11785                                        auto_pin_cfg_labels[i], idx, 0x15);
11786                 if (err < 0)
11787                         return err;
11788
11789                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
11790                 imux->items[imux->num_items].index = idx1;
11791                 imux->num_items++;
11792         }
11793         return 0;
11794 }
11795
11796 static struct snd_kcontrol_new alc861_capture_mixer[] = {
11797         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11798         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11799
11800         {
11801                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11802                 /* The multiple "Capture Source" controls confuse alsamixer
11803                  * So call somewhat different..
11804                  */
11805                 /* .name = "Capture Source", */
11806                 .name = "Input Source",
11807                 .count = 1,
11808                 .info = alc_mux_enum_info,
11809                 .get = alc_mux_enum_get,
11810                 .put = alc_mux_enum_put,
11811         },
11812         { } /* end */
11813 };
11814
11815 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
11816                                               hda_nid_t nid,
11817                                               int pin_type, int dac_idx)
11818 {
11819         alc_set_pin_output(codec, nid, pin_type);
11820 }
11821
11822 static void alc861_auto_init_multi_out(struct hda_codec *codec)
11823 {
11824         struct alc_spec *spec = codec->spec;
11825         int i;
11826
11827         alc_subsystem_id(codec, 0x0e, 0x0f, 0x0b);
11828         for (i = 0; i < spec->autocfg.line_outs; i++) {
11829                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
11830                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
11831                 if (nid)
11832                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
11833                                                           spec->multiout.dac_nids[i]);
11834         }
11835 }
11836
11837 static void alc861_auto_init_hp_out(struct hda_codec *codec)
11838 {
11839         struct alc_spec *spec = codec->spec;
11840         hda_nid_t pin;
11841
11842         pin = spec->autocfg.hp_pins[0];
11843         if (pin) /* connect to front */
11844                 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
11845                                                   spec->multiout.dac_nids[0]);
11846         pin = spec->autocfg.speaker_pins[0];
11847         if (pin)
11848                 alc861_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
11849 }
11850
11851 static void alc861_auto_init_analog_input(struct hda_codec *codec)
11852 {
11853         struct alc_spec *spec = codec->spec;
11854         int i;
11855
11856         for (i = 0; i < AUTO_PIN_LAST; i++) {
11857                 hda_nid_t nid = spec->autocfg.input_pins[i];
11858                 if (nid >= 0x0c && nid <= 0x11) {
11859                         snd_hda_codec_write(codec, nid, 0,
11860                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
11861                                             i <= AUTO_PIN_FRONT_MIC ?
11862                                             PIN_VREF80 : PIN_IN);
11863                 }
11864         }
11865 }
11866
11867 /* parse the BIOS configuration and set up the alc_spec */
11868 /* return 1 if successful, 0 if the proper config is not found,
11869  * or a negative error code
11870  */
11871 static int alc861_parse_auto_config(struct hda_codec *codec)
11872 {
11873         struct alc_spec *spec = codec->spec;
11874         int err;
11875         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
11876
11877         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11878                                            alc861_ignore);
11879         if (err < 0)
11880                 return err;
11881         if (!spec->autocfg.line_outs)
11882                 return 0; /* can't find valid BIOS pin config */
11883
11884         err = alc861_auto_fill_dac_nids(spec, &spec->autocfg);
11885         if (err < 0)
11886                 return err;
11887         err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg);
11888         if (err < 0)
11889                 return err;
11890         err = alc861_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
11891         if (err < 0)
11892                 return err;
11893         err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg);
11894         if (err < 0)
11895                 return err;
11896
11897         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
11898
11899         if (spec->autocfg.dig_out_pin)
11900                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
11901
11902         if (spec->kctl_alloc)
11903                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
11904
11905         spec->init_verbs[spec->num_init_verbs++] = alc861_auto_init_verbs;
11906
11907         spec->num_mux_defs = 1;
11908         spec->input_mux = &spec->private_imux;
11909
11910         spec->adc_nids = alc861_adc_nids;
11911         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
11912         spec->mixers[spec->num_mixers] = alc861_capture_mixer;
11913         spec->num_mixers++;
11914
11915         return 1;
11916 }
11917
11918 /* additional initialization for auto-configuration model */
11919 static void alc861_auto_init(struct hda_codec *codec)
11920 {
11921         struct alc_spec *spec = codec->spec;
11922         alc861_auto_init_multi_out(codec);
11923         alc861_auto_init_hp_out(codec);
11924         alc861_auto_init_analog_input(codec);
11925         if (spec->unsol_event)
11926                 alc_sku_automute(codec);
11927 }
11928
11929 #ifdef CONFIG_SND_HDA_POWER_SAVE
11930 static struct hda_amp_list alc861_loopbacks[] = {
11931         { 0x15, HDA_INPUT, 0 },
11932         { 0x15, HDA_INPUT, 1 },
11933         { 0x15, HDA_INPUT, 2 },
11934         { 0x15, HDA_INPUT, 3 },
11935         { } /* end */
11936 };
11937 #endif
11938
11939
11940 /*
11941  * configuration and preset
11942  */
11943 static const char *alc861_models[ALC861_MODEL_LAST] = {
11944         [ALC861_3ST]            = "3stack",
11945         [ALC660_3ST]            = "3stack-660",
11946         [ALC861_3ST_DIG]        = "3stack-dig",
11947         [ALC861_6ST_DIG]        = "6stack-dig",
11948         [ALC861_UNIWILL_M31]    = "uniwill-m31",
11949         [ALC861_TOSHIBA]        = "toshiba",
11950         [ALC861_ASUS]           = "asus",
11951         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
11952         [ALC861_AUTO]           = "auto",
11953 };
11954
11955 static struct snd_pci_quirk alc861_cfg_tbl[] = {
11956         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
11957         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
11958         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
11959         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
11960         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
11961         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
11962         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
11963         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
11964          *        Any other models that need this preset?
11965          */
11966         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
11967         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
11968         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
11969         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
11970         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
11971         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
11972         /* FIXME: the below seems conflict */
11973         /* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
11974         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
11975         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
11976         {}
11977 };
11978
11979 static struct alc_config_preset alc861_presets[] = {
11980         [ALC861_3ST] = {
11981                 .mixers = { alc861_3ST_mixer },
11982                 .init_verbs = { alc861_threestack_init_verbs },
11983                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
11984                 .dac_nids = alc861_dac_nids,
11985                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
11986                 .channel_mode = alc861_threestack_modes,
11987                 .need_dac_fix = 1,
11988                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
11989                 .adc_nids = alc861_adc_nids,
11990                 .input_mux = &alc861_capture_source,
11991         },
11992         [ALC861_3ST_DIG] = {
11993                 .mixers = { alc861_base_mixer },
11994                 .init_verbs = { alc861_threestack_init_verbs },
11995                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
11996                 .dac_nids = alc861_dac_nids,
11997                 .dig_out_nid = ALC861_DIGOUT_NID,
11998                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
11999                 .channel_mode = alc861_threestack_modes,
12000                 .need_dac_fix = 1,
12001                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12002                 .adc_nids = alc861_adc_nids,
12003                 .input_mux = &alc861_capture_source,
12004         },
12005         [ALC861_6ST_DIG] = {
12006                 .mixers = { alc861_base_mixer },
12007                 .init_verbs = { alc861_base_init_verbs },
12008                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12009                 .dac_nids = alc861_dac_nids,
12010                 .dig_out_nid = ALC861_DIGOUT_NID,
12011                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
12012                 .channel_mode = alc861_8ch_modes,
12013                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12014                 .adc_nids = alc861_adc_nids,
12015                 .input_mux = &alc861_capture_source,
12016         },
12017         [ALC660_3ST] = {
12018                 .mixers = { alc861_3ST_mixer },
12019                 .init_verbs = { alc861_threestack_init_verbs },
12020                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
12021                 .dac_nids = alc660_dac_nids,
12022                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
12023                 .channel_mode = alc861_threestack_modes,
12024                 .need_dac_fix = 1,
12025                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12026                 .adc_nids = alc861_adc_nids,
12027                 .input_mux = &alc861_capture_source,
12028         },
12029         [ALC861_UNIWILL_M31] = {
12030                 .mixers = { alc861_uniwill_m31_mixer },
12031                 .init_verbs = { alc861_uniwill_m31_init_verbs },
12032                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12033                 .dac_nids = alc861_dac_nids,
12034                 .dig_out_nid = ALC861_DIGOUT_NID,
12035                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
12036                 .channel_mode = alc861_uniwill_m31_modes,
12037                 .need_dac_fix = 1,
12038                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12039                 .adc_nids = alc861_adc_nids,
12040                 .input_mux = &alc861_capture_source,
12041         },
12042         [ALC861_TOSHIBA] = {
12043                 .mixers = { alc861_toshiba_mixer },
12044                 .init_verbs = { alc861_base_init_verbs,
12045                                 alc861_toshiba_init_verbs },
12046                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12047                 .dac_nids = alc861_dac_nids,
12048                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
12049                 .channel_mode = alc883_3ST_2ch_modes,
12050                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12051                 .adc_nids = alc861_adc_nids,
12052                 .input_mux = &alc861_capture_source,
12053                 .unsol_event = alc861_toshiba_unsol_event,
12054                 .init_hook = alc861_toshiba_automute,
12055         },
12056         [ALC861_ASUS] = {
12057                 .mixers = { alc861_asus_mixer },
12058                 .init_verbs = { alc861_asus_init_verbs },
12059                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12060                 .dac_nids = alc861_dac_nids,
12061                 .dig_out_nid = ALC861_DIGOUT_NID,
12062                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
12063                 .channel_mode = alc861_asus_modes,
12064                 .need_dac_fix = 1,
12065                 .hp_nid = 0x06,
12066                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12067                 .adc_nids = alc861_adc_nids,
12068                 .input_mux = &alc861_capture_source,
12069         },
12070         [ALC861_ASUS_LAPTOP] = {
12071                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
12072                 .init_verbs = { alc861_asus_init_verbs,
12073                                 alc861_asus_laptop_init_verbs },
12074                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12075                 .dac_nids = alc861_dac_nids,
12076                 .dig_out_nid = ALC861_DIGOUT_NID,
12077                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
12078                 .channel_mode = alc883_3ST_2ch_modes,
12079                 .need_dac_fix = 1,
12080                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12081                 .adc_nids = alc861_adc_nids,
12082                 .input_mux = &alc861_capture_source,
12083         },
12084 };
12085
12086
12087 static int patch_alc861(struct hda_codec *codec)
12088 {
12089         struct alc_spec *spec;
12090         int board_config;
12091         int err;
12092
12093         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
12094         if (spec == NULL)
12095                 return -ENOMEM;
12096
12097         codec->spec = spec;
12098
12099         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
12100                                                   alc861_models,
12101                                                   alc861_cfg_tbl);
12102
12103         if (board_config < 0) {
12104                 printk(KERN_INFO "hda_codec: Unknown model for ALC861, "
12105                        "trying auto-probe from BIOS...\n");
12106                 board_config = ALC861_AUTO;
12107         }
12108
12109         if (board_config == ALC861_AUTO) {
12110                 /* automatic parse from the BIOS config */
12111                 err = alc861_parse_auto_config(codec);
12112                 if (err < 0) {
12113                         alc_free(codec);
12114                         return err;
12115                 } else if (!err) {
12116                         printk(KERN_INFO
12117                                "hda_codec: Cannot set up configuration "
12118                                "from BIOS.  Using base mode...\n");
12119                    board_config = ALC861_3ST_DIG;
12120                 }
12121         }
12122
12123         if (board_config != ALC861_AUTO)
12124                 setup_preset(spec, &alc861_presets[board_config]);
12125
12126         spec->stream_name_analog = "ALC861 Analog";
12127         spec->stream_analog_playback = &alc861_pcm_analog_playback;
12128         spec->stream_analog_capture = &alc861_pcm_analog_capture;
12129
12130         spec->stream_name_digital = "ALC861 Digital";
12131         spec->stream_digital_playback = &alc861_pcm_digital_playback;
12132         spec->stream_digital_capture = &alc861_pcm_digital_capture;
12133
12134         spec->vmaster_nid = 0x03;
12135
12136         codec->patch_ops = alc_patch_ops;
12137         if (board_config == ALC861_AUTO)
12138                 spec->init_hook = alc861_auto_init;
12139 #ifdef CONFIG_SND_HDA_POWER_SAVE
12140         if (!spec->loopback.amplist)
12141                 spec->loopback.amplist = alc861_loopbacks;
12142 #endif
12143                 
12144         return 0;
12145 }
12146
12147 /*
12148  * ALC861-VD support
12149  *
12150  * Based on ALC882
12151  *
12152  * In addition, an independent DAC
12153  */
12154 #define ALC861VD_DIGOUT_NID     0x06
12155
12156 static hda_nid_t alc861vd_dac_nids[4] = {
12157         /* front, surr, clfe, side surr */
12158         0x02, 0x03, 0x04, 0x05
12159 };
12160
12161 /* dac_nids for ALC660vd are in a different order - according to
12162  * Realtek's driver.
12163  * This should probably tesult in a different mixer for 6stack models
12164  * of ALC660vd codecs, but for now there is only 3stack mixer
12165  * - and it is the same as in 861vd.
12166  * adc_nids in ALC660vd are (is) the same as in 861vd
12167  */
12168 static hda_nid_t alc660vd_dac_nids[3] = {
12169         /* front, rear, clfe, rear_surr */
12170         0x02, 0x04, 0x03
12171 };
12172
12173 static hda_nid_t alc861vd_adc_nids[1] = {
12174         /* ADC0 */
12175         0x09,
12176 };
12177
12178 static hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
12179
12180 /* input MUX */
12181 /* FIXME: should be a matrix-type input source selection */
12182 static struct hda_input_mux alc861vd_capture_source = {
12183         .num_items = 4,
12184         .items = {
12185                 { "Mic", 0x0 },
12186                 { "Front Mic", 0x1 },
12187                 { "Line", 0x2 },
12188                 { "CD", 0x4 },
12189         },
12190 };
12191
12192 static struct hda_input_mux alc861vd_dallas_capture_source = {
12193         .num_items = 2,
12194         .items = {
12195                 { "Ext Mic", 0x0 },
12196                 { "Int Mic", 0x1 },
12197         },
12198 };
12199
12200 static struct hda_input_mux alc861vd_hp_capture_source = {
12201         .num_items = 2,
12202         .items = {
12203                 { "Front Mic", 0x0 },
12204                 { "ATAPI Mic", 0x1 },
12205         },
12206 };
12207
12208 #define alc861vd_mux_enum_info alc_mux_enum_info
12209 #define alc861vd_mux_enum_get alc_mux_enum_get
12210 /* ALC861VD has the ALC882-type input selection (but has only one ADC) */
12211 #define alc861vd_mux_enum_put alc882_mux_enum_put
12212
12213 /*
12214  * 2ch mode
12215  */
12216 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
12217         { 2, NULL }
12218 };
12219
12220 /*
12221  * 6ch mode
12222  */
12223 static struct hda_verb alc861vd_6stack_ch6_init[] = {
12224         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12225         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12226         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12227         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12228         { } /* end */
12229 };
12230
12231 /*
12232  * 8ch mode
12233  */
12234 static struct hda_verb alc861vd_6stack_ch8_init[] = {
12235         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12236         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12237         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12238         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12239         { } /* end */
12240 };
12241
12242 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
12243         { 6, alc861vd_6stack_ch6_init },
12244         { 8, alc861vd_6stack_ch8_init },
12245 };
12246
12247 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
12248         {
12249                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12250                 .name = "Channel Mode",
12251                 .info = alc_ch_mode_info,
12252                 .get = alc_ch_mode_get,
12253                 .put = alc_ch_mode_put,
12254         },
12255         { } /* end */
12256 };
12257
12258 static struct snd_kcontrol_new alc861vd_capture_mixer[] = {
12259         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
12260         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
12261
12262         {
12263                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12264                 /* The multiple "Capture Source" controls confuse alsamixer
12265                  * So call somewhat different..
12266                  */
12267                 /* .name = "Capture Source", */
12268                 .name = "Input Source",
12269                 .count = 1,
12270                 .info = alc861vd_mux_enum_info,
12271                 .get = alc861vd_mux_enum_get,
12272                 .put = alc861vd_mux_enum_put,
12273         },
12274         { } /* end */
12275 };
12276
12277 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
12278  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
12279  */
12280 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
12281         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12282         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
12283
12284         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12285         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
12286
12287         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
12288                                 HDA_OUTPUT),
12289         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
12290                                 HDA_OUTPUT),
12291         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
12292         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
12293
12294         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
12295         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
12296
12297         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12298
12299         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12300         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12301         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12302
12303         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
12304         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12305         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12306
12307         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12308         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12309
12310         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
12311         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
12312
12313         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
12314         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
12315
12316         { } /* end */
12317 };
12318
12319 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
12320         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12321         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
12322
12323         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12324
12325         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12326         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12327         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12328
12329         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
12330         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12331         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12332
12333         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12334         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12335
12336         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
12337         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
12338
12339         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
12340         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
12341
12342         { } /* end */
12343 };
12344
12345 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
12346         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12347         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
12348         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12349
12350         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12351
12352         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12353         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12354         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12355
12356         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
12357         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12358         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12359
12360         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
12361         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
12362
12363         { } /* end */
12364 };
12365
12366 /* Pin assignment: Speaker=0x14, HP = 0x15,
12367  *                 Ext Mic=0x18, Int Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
12368  */
12369 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
12370         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12371         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
12372         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12373         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
12374         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
12375         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12376         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12377         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
12378         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12379         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12380         HDA_CODEC_VOLUME("PC Beep Volume", 0x0b, 0x05, HDA_INPUT),
12381         HDA_CODEC_MUTE("PC Beep Switch", 0x0b, 0x05, HDA_INPUT),
12382         { } /* end */
12383 };
12384
12385 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
12386  *                 Front Mic=0x18, ATAPI Mic = 0x19,
12387  */
12388 static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
12389         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12390         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
12391         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12392         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
12393         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12394         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12395         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12396         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12397         
12398         { } /* end */
12399 };
12400
12401 /*
12402  * generic initialization of ADC, input mixers and output mixers
12403  */
12404 static struct hda_verb alc861vd_volume_init_verbs[] = {
12405         /*
12406          * Unmute ADC0 and set the default input to mic-in
12407          */
12408         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
12409         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12410
12411         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
12412          * the analog-loopback mixer widget
12413          */
12414         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
12415         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12416         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12417         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12418         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12419         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
12420
12421         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
12422         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12423         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12424         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12425         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
12426
12427         /*
12428          * Set up output mixers (0x02 - 0x05)
12429          */
12430         /* set vol=0 to output mixers */
12431         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12432         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12433         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12434         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12435
12436         /* set up input amps for analog loopback */
12437         /* Amp Indices: DAC = 0, mixer = 1 */
12438         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12439         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12440         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12441         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12442         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12443         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12444         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12445         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12446
12447         { }
12448 };
12449
12450 /*
12451  * 3-stack pin configuration:
12452  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
12453  */
12454 static struct hda_verb alc861vd_3stack_init_verbs[] = {
12455         /*
12456          * Set pin mode and muting
12457          */
12458         /* set front pin widgets 0x14 for output */
12459         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12460         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12461         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
12462
12463         /* Mic (rear) pin: input vref at 80% */
12464         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12465         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12466         /* Front Mic pin: input vref at 80% */
12467         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12468         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12469         /* Line In pin: input */
12470         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12471         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12472         /* Line-2 In: Headphone output (output 0 - 0x0c) */
12473         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12474         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12475         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
12476         /* CD pin widget for input */
12477         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12478
12479         { }
12480 };
12481
12482 /*
12483  * 6-stack pin configuration:
12484  */
12485 static struct hda_verb alc861vd_6stack_init_verbs[] = {
12486         /*
12487          * Set pin mode and muting
12488          */
12489         /* set front pin widgets 0x14 for output */
12490         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12491         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12492         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
12493
12494         /* Rear Pin: output 1 (0x0d) */
12495         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12496         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12497         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12498         /* CLFE Pin: output 2 (0x0e) */
12499         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12500         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12501         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
12502         /* Side Pin: output 3 (0x0f) */
12503         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12504         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12505         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
12506
12507         /* Mic (rear) pin: input vref at 80% */
12508         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12509         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12510         /* Front Mic pin: input vref at 80% */
12511         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12512         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12513         /* Line In pin: input */
12514         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12515         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12516         /* Line-2 In: Headphone output (output 0 - 0x0c) */
12517         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12518         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12519         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
12520         /* CD pin widget for input */
12521         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12522
12523         { }
12524 };
12525
12526 static struct hda_verb alc861vd_eapd_verbs[] = {
12527         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
12528         { }
12529 };
12530
12531 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
12532         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12533         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12534         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
12535         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12536         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT}, 
12537         {}
12538 };
12539
12540 /* toggle speaker-output according to the hp-jack state */
12541 static void alc861vd_lenovo_hp_automute(struct hda_codec *codec)
12542 {
12543         unsigned int present;
12544         unsigned char bits;
12545
12546         present = snd_hda_codec_read(codec, 0x1b, 0,
12547                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12548         bits = present ? HDA_AMP_MUTE : 0;
12549         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
12550                                  HDA_AMP_MUTE, bits);
12551 }
12552
12553 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
12554 {
12555         unsigned int present;
12556         unsigned char bits;
12557
12558         present = snd_hda_codec_read(codec, 0x18, 0,
12559                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12560         bits = present ? HDA_AMP_MUTE : 0;
12561         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
12562                                  HDA_AMP_MUTE, bits);
12563 }
12564
12565 static void alc861vd_lenovo_automute(struct hda_codec *codec)
12566 {
12567         alc861vd_lenovo_hp_automute(codec);
12568         alc861vd_lenovo_mic_automute(codec);
12569 }
12570
12571 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
12572                                         unsigned int res)
12573 {
12574         switch (res >> 26) {
12575         case ALC880_HP_EVENT:
12576                 alc861vd_lenovo_hp_automute(codec);
12577                 break;
12578         case ALC880_MIC_EVENT:
12579                 alc861vd_lenovo_mic_automute(codec);
12580                 break;
12581         }
12582 }
12583
12584 static struct hda_verb alc861vd_dallas_verbs[] = {
12585         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12586         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12587         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12588         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12589
12590         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12591         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12592         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12593         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12594         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12595         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12596         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12597         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12598         
12599         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12600         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12601         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12602         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12603         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12604         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12605         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12606         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12607
12608         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
12609         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12610         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
12611         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12612         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12613         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12614         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12615         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12616
12617         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12618         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12619         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12620         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
12621
12622         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12623         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},  
12624         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12625
12626         { } /* end */
12627 };
12628
12629 /* toggle speaker-output according to the hp-jack state */
12630 static void alc861vd_dallas_automute(struct hda_codec *codec)
12631 {
12632         unsigned int present;
12633
12634         present = snd_hda_codec_read(codec, 0x15, 0,
12635                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12636         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
12637                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
12638 }
12639
12640 static void alc861vd_dallas_unsol_event(struct hda_codec *codec, unsigned int res)
12641 {
12642         if ((res >> 26) == ALC880_HP_EVENT)
12643                 alc861vd_dallas_automute(codec);
12644 }
12645
12646 #ifdef CONFIG_SND_HDA_POWER_SAVE
12647 #define alc861vd_loopbacks      alc880_loopbacks
12648 #endif
12649
12650 /* pcm configuration: identiacal with ALC880 */
12651 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
12652 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
12653 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
12654 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
12655
12656 /*
12657  * configuration and preset
12658  */
12659 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
12660         [ALC660VD_3ST]          = "3stack-660",
12661         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
12662         [ALC861VD_3ST]          = "3stack",
12663         [ALC861VD_3ST_DIG]      = "3stack-digout",
12664         [ALC861VD_6ST_DIG]      = "6stack-digout",
12665         [ALC861VD_LENOVO]       = "lenovo",
12666         [ALC861VD_DALLAS]       = "dallas",
12667         [ALC861VD_HP]           = "hp",
12668         [ALC861VD_AUTO]         = "auto",
12669 };
12670
12671 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
12672         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
12673         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
12674         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
12675         SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),
12676         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
12677         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
12678         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
12679         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
12680         SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS),
12681         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
12682         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
12683         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
12684         SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo", ALC861VD_LENOVO),
12685         SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo 3000 C200", ALC861VD_LENOVO),
12686         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
12687         {}
12688 };
12689
12690 static struct alc_config_preset alc861vd_presets[] = {
12691         [ALC660VD_3ST] = {
12692                 .mixers = { alc861vd_3st_mixer },
12693                 .init_verbs = { alc861vd_volume_init_verbs,
12694                                  alc861vd_3stack_init_verbs },
12695                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
12696                 .dac_nids = alc660vd_dac_nids,
12697                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12698                 .channel_mode = alc861vd_3stack_2ch_modes,
12699                 .input_mux = &alc861vd_capture_source,
12700         },
12701         [ALC660VD_3ST_DIG] = {
12702                 .mixers = { alc861vd_3st_mixer },
12703                 .init_verbs = { alc861vd_volume_init_verbs,
12704                                  alc861vd_3stack_init_verbs },
12705                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
12706                 .dac_nids = alc660vd_dac_nids,
12707                 .dig_out_nid = ALC861VD_DIGOUT_NID,
12708                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12709                 .channel_mode = alc861vd_3stack_2ch_modes,
12710                 .input_mux = &alc861vd_capture_source,
12711         },
12712         [ALC861VD_3ST] = {
12713                 .mixers = { alc861vd_3st_mixer },
12714                 .init_verbs = { alc861vd_volume_init_verbs,
12715                                  alc861vd_3stack_init_verbs },
12716                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
12717                 .dac_nids = alc861vd_dac_nids,
12718                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12719                 .channel_mode = alc861vd_3stack_2ch_modes,
12720                 .input_mux = &alc861vd_capture_source,
12721         },
12722         [ALC861VD_3ST_DIG] = {
12723                 .mixers = { alc861vd_3st_mixer },
12724                 .init_verbs = { alc861vd_volume_init_verbs,
12725                                  alc861vd_3stack_init_verbs },
12726                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
12727                 .dac_nids = alc861vd_dac_nids,
12728                 .dig_out_nid = ALC861VD_DIGOUT_NID,
12729                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12730                 .channel_mode = alc861vd_3stack_2ch_modes,
12731                 .input_mux = &alc861vd_capture_source,
12732         },
12733         [ALC861VD_6ST_DIG] = {
12734                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
12735                 .init_verbs = { alc861vd_volume_init_verbs,
12736                                 alc861vd_6stack_init_verbs },
12737                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
12738                 .dac_nids = alc861vd_dac_nids,
12739                 .dig_out_nid = ALC861VD_DIGOUT_NID,
12740                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
12741                 .channel_mode = alc861vd_6stack_modes,
12742                 .input_mux = &alc861vd_capture_source,
12743         },
12744         [ALC861VD_LENOVO] = {
12745                 .mixers = { alc861vd_lenovo_mixer },
12746                 .init_verbs = { alc861vd_volume_init_verbs,
12747                                 alc861vd_3stack_init_verbs,
12748                                 alc861vd_eapd_verbs,
12749                                 alc861vd_lenovo_unsol_verbs },
12750                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
12751                 .dac_nids = alc660vd_dac_nids,
12752                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12753                 .channel_mode = alc861vd_3stack_2ch_modes,
12754                 .input_mux = &alc861vd_capture_source,
12755                 .unsol_event = alc861vd_lenovo_unsol_event,
12756                 .init_hook = alc861vd_lenovo_automute,
12757         },
12758         [ALC861VD_DALLAS] = {
12759                 .mixers = { alc861vd_dallas_mixer },
12760                 .init_verbs = { alc861vd_dallas_verbs },
12761                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
12762                 .dac_nids = alc861vd_dac_nids,
12763                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12764                 .channel_mode = alc861vd_3stack_2ch_modes,
12765                 .input_mux = &alc861vd_dallas_capture_source,
12766                 .unsol_event = alc861vd_dallas_unsol_event,
12767                 .init_hook = alc861vd_dallas_automute,
12768         },
12769         [ALC861VD_HP] = {
12770                 .mixers = { alc861vd_hp_mixer },
12771                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
12772                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
12773                 .dac_nids = alc861vd_dac_nids,
12774                 .dig_out_nid = ALC861VD_DIGOUT_NID,
12775                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12776                 .channel_mode = alc861vd_3stack_2ch_modes,
12777                 .input_mux = &alc861vd_hp_capture_source,
12778                 .unsol_event = alc861vd_dallas_unsol_event,
12779                 .init_hook = alc861vd_dallas_automute,
12780         },              
12781 };
12782
12783 /*
12784  * BIOS auto configuration
12785  */
12786 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
12787                                 hda_nid_t nid, int pin_type, int dac_idx)
12788 {
12789         alc_set_pin_output(codec, nid, pin_type);
12790 }
12791
12792 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
12793 {
12794         struct alc_spec *spec = codec->spec;
12795         int i;
12796
12797         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
12798         for (i = 0; i <= HDA_SIDE; i++) {
12799                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
12800                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
12801                 if (nid)
12802                         alc861vd_auto_set_output_and_unmute(codec, nid,
12803                                                             pin_type, i);
12804         }
12805 }
12806
12807
12808 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
12809 {
12810         struct alc_spec *spec = codec->spec;
12811         hda_nid_t pin;
12812
12813         pin = spec->autocfg.hp_pins[0];
12814         if (pin) /* connect to front and  use dac 0 */
12815                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
12816         pin = spec->autocfg.speaker_pins[0];
12817         if (pin)
12818                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
12819 }
12820
12821 #define alc861vd_is_input_pin(nid)      alc880_is_input_pin(nid)
12822 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
12823
12824 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
12825 {
12826         struct alc_spec *spec = codec->spec;
12827         int i;
12828
12829         for (i = 0; i < AUTO_PIN_LAST; i++) {
12830                 hda_nid_t nid = spec->autocfg.input_pins[i];
12831                 if (alc861vd_is_input_pin(nid)) {
12832                         snd_hda_codec_write(codec, nid, 0,
12833                                         AC_VERB_SET_PIN_WIDGET_CONTROL,
12834                                         i <= AUTO_PIN_FRONT_MIC ?
12835                                                         PIN_VREF80 : PIN_IN);
12836                         if (nid != ALC861VD_PIN_CD_NID)
12837                                 snd_hda_codec_write(codec, nid, 0,
12838                                                 AC_VERB_SET_AMP_GAIN_MUTE,
12839                                                 AMP_OUT_MUTE);
12840                 }
12841         }
12842 }
12843
12844 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
12845 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
12846
12847 /* add playback controls from the parsed DAC table */
12848 /* Based on ALC880 version. But ALC861VD has separate,
12849  * different NIDs for mute/unmute switch and volume control */
12850 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
12851                                              const struct auto_pin_cfg *cfg)
12852 {
12853         char name[32];
12854         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
12855         hda_nid_t nid_v, nid_s;
12856         int i, err;
12857
12858         for (i = 0; i < cfg->line_outs; i++) {
12859                 if (!spec->multiout.dac_nids[i])
12860                         continue;
12861                 nid_v = alc861vd_idx_to_mixer_vol(
12862                                 alc880_dac_to_idx(
12863                                         spec->multiout.dac_nids[i]));
12864                 nid_s = alc861vd_idx_to_mixer_switch(
12865                                 alc880_dac_to_idx(
12866                                         spec->multiout.dac_nids[i]));
12867
12868                 if (i == 2) {
12869                         /* Center/LFE */
12870                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12871                                           "Center Playback Volume",
12872                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
12873                                                               HDA_OUTPUT));
12874                         if (err < 0)
12875                                 return err;
12876                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12877                                           "LFE Playback Volume",
12878                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
12879                                                               HDA_OUTPUT));
12880                         if (err < 0)
12881                                 return err;
12882                         err = add_control(spec, ALC_CTL_BIND_MUTE,
12883                                           "Center Playback Switch",
12884                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
12885                                                               HDA_INPUT));
12886                         if (err < 0)
12887                                 return err;
12888                         err = add_control(spec, ALC_CTL_BIND_MUTE,
12889                                           "LFE Playback Switch",
12890                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
12891                                                               HDA_INPUT));
12892                         if (err < 0)
12893                                 return err;
12894                 } else {
12895                         sprintf(name, "%s Playback Volume", chname[i]);
12896                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
12897                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
12898                                                               HDA_OUTPUT));
12899                         if (err < 0)
12900                                 return err;
12901                         sprintf(name, "%s Playback Switch", chname[i]);
12902                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
12903                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
12904                                                               HDA_INPUT));
12905                         if (err < 0)
12906                                 return err;
12907                 }
12908         }
12909         return 0;
12910 }
12911
12912 /* add playback controls for speaker and HP outputs */
12913 /* Based on ALC880 version. But ALC861VD has separate,
12914  * different NIDs for mute/unmute switch and volume control */
12915 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
12916                                         hda_nid_t pin, const char *pfx)
12917 {
12918         hda_nid_t nid_v, nid_s;
12919         int err;
12920         char name[32];
12921
12922         if (!pin)
12923                 return 0;
12924
12925         if (alc880_is_fixed_pin(pin)) {
12926                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
12927                 /* specify the DAC as the extra output */
12928                 if (!spec->multiout.hp_nid)
12929                         spec->multiout.hp_nid = nid_v;
12930                 else
12931                         spec->multiout.extra_out_nid[0] = nid_v;
12932                 /* control HP volume/switch on the output mixer amp */
12933                 nid_v = alc861vd_idx_to_mixer_vol(
12934                                 alc880_fixed_pin_idx(pin));
12935                 nid_s = alc861vd_idx_to_mixer_switch(
12936                                 alc880_fixed_pin_idx(pin));
12937
12938                 sprintf(name, "%s Playback Volume", pfx);
12939                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
12940                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
12941                 if (err < 0)
12942                         return err;
12943                 sprintf(name, "%s Playback Switch", pfx);
12944                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
12945                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
12946                 if (err < 0)
12947                         return err;
12948         } else if (alc880_is_multi_pin(pin)) {
12949                 /* set manual connection */
12950                 /* we have only a switch on HP-out PIN */
12951                 sprintf(name, "%s Playback Switch", pfx);
12952                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
12953                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
12954                 if (err < 0)
12955                         return err;
12956         }
12957         return 0;
12958 }
12959
12960 /* parse the BIOS configuration and set up the alc_spec
12961  * return 1 if successful, 0 if the proper config is not found,
12962  * or a negative error code
12963  * Based on ALC880 version - had to change it to override
12964  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
12965 static int alc861vd_parse_auto_config(struct hda_codec *codec)
12966 {
12967         struct alc_spec *spec = codec->spec;
12968         int err;
12969         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
12970
12971         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
12972                                            alc861vd_ignore);
12973         if (err < 0)
12974                 return err;
12975         if (!spec->autocfg.line_outs)
12976                 return 0; /* can't find valid BIOS pin config */
12977
12978         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
12979         if (err < 0)
12980                 return err;
12981         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
12982         if (err < 0)
12983                 return err;
12984         err = alc861vd_auto_create_extra_out(spec,
12985                                              spec->autocfg.speaker_pins[0],
12986                                              "Speaker");
12987         if (err < 0)
12988                 return err;
12989         err = alc861vd_auto_create_extra_out(spec,
12990                                              spec->autocfg.hp_pins[0],
12991                                              "Headphone");
12992         if (err < 0)
12993                 return err;
12994         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
12995         if (err < 0)
12996                 return err;
12997
12998         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
12999
13000         if (spec->autocfg.dig_out_pin)
13001                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
13002
13003         if (spec->kctl_alloc)
13004                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
13005
13006         spec->init_verbs[spec->num_init_verbs++]
13007                 = alc861vd_volume_init_verbs;
13008
13009         spec->num_mux_defs = 1;
13010         spec->input_mux = &spec->private_imux;
13011
13012         err = alc_auto_add_mic_boost(codec);
13013         if (err < 0)
13014                 return err;
13015
13016         return 1;
13017 }
13018
13019 /* additional initialization for auto-configuration model */
13020 static void alc861vd_auto_init(struct hda_codec *codec)
13021 {
13022         struct alc_spec *spec = codec->spec;
13023         alc861vd_auto_init_multi_out(codec);
13024         alc861vd_auto_init_hp_out(codec);
13025         alc861vd_auto_init_analog_input(codec);
13026         if (spec->unsol_event)
13027                 alc_sku_automute(codec);
13028 }
13029
13030 static int patch_alc861vd(struct hda_codec *codec)
13031 {
13032         struct alc_spec *spec;
13033         int err, board_config;
13034
13035         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13036         if (spec == NULL)
13037                 return -ENOMEM;
13038
13039         codec->spec = spec;
13040
13041         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
13042                                                   alc861vd_models,
13043                                                   alc861vd_cfg_tbl);
13044
13045         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
13046                 printk(KERN_INFO "hda_codec: Unknown model for ALC660VD/"
13047                         "ALC861VD, trying auto-probe from BIOS...\n");
13048                 board_config = ALC861VD_AUTO;
13049         }
13050
13051         if (board_config == ALC861VD_AUTO) {
13052                 /* automatic parse from the BIOS config */
13053                 err = alc861vd_parse_auto_config(codec);
13054                 if (err < 0) {
13055                         alc_free(codec);
13056                         return err;
13057                 } else if (!err) {
13058                         printk(KERN_INFO
13059                                "hda_codec: Cannot set up configuration "
13060                                "from BIOS.  Using base mode...\n");
13061                         board_config = ALC861VD_3ST;
13062                 }
13063         }
13064
13065         if (board_config != ALC861VD_AUTO)
13066                 setup_preset(spec, &alc861vd_presets[board_config]);
13067
13068         spec->stream_name_analog = "ALC861VD Analog";
13069         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
13070         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
13071
13072         spec->stream_name_digital = "ALC861VD Digital";
13073         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
13074         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
13075
13076         spec->adc_nids = alc861vd_adc_nids;
13077         spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
13078         spec->capsrc_nids = alc861vd_capsrc_nids;
13079
13080         spec->mixers[spec->num_mixers] = alc861vd_capture_mixer;
13081         spec->num_mixers++;
13082
13083         spec->vmaster_nid = 0x02;
13084
13085         codec->patch_ops = alc_patch_ops;
13086
13087         if (board_config == ALC861VD_AUTO)
13088                 spec->init_hook = alc861vd_auto_init;
13089 #ifdef CONFIG_SND_HDA_POWER_SAVE
13090         if (!spec->loopback.amplist)
13091                 spec->loopback.amplist = alc861vd_loopbacks;
13092 #endif
13093
13094         return 0;
13095 }
13096
13097 /*
13098  * ALC662 support
13099  *
13100  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
13101  * configuration.  Each pin widget can choose any input DACs and a mixer.
13102  * Each ADC is connected from a mixer of all inputs.  This makes possible
13103  * 6-channel independent captures.
13104  *
13105  * In addition, an independent DAC for the multi-playback (not used in this
13106  * driver yet).
13107  */
13108 #define ALC662_DIGOUT_NID       0x06
13109 #define ALC662_DIGIN_NID        0x0a
13110
13111 static hda_nid_t alc662_dac_nids[4] = {
13112         /* front, rear, clfe, rear_surr */
13113         0x02, 0x03, 0x04
13114 };
13115
13116 static hda_nid_t alc662_adc_nids[1] = {
13117         /* ADC1-2 */
13118         0x09,
13119 };
13120
13121 static hda_nid_t alc662_capsrc_nids[1] = { 0x22 };
13122
13123 /* input MUX */
13124 /* FIXME: should be a matrix-type input source selection */
13125 static struct hda_input_mux alc662_capture_source = {
13126         .num_items = 4,
13127         .items = {
13128                 { "Mic", 0x0 },
13129                 { "Front Mic", 0x1 },
13130                 { "Line", 0x2 },
13131                 { "CD", 0x4 },
13132         },
13133 };
13134
13135 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
13136         .num_items = 2,
13137         .items = {
13138                 { "Mic", 0x1 },
13139                 { "Line", 0x2 },
13140         },
13141 };
13142
13143 static struct hda_input_mux alc662_eeepc_capture_source = {
13144         .num_items = 2,
13145         .items = {
13146                 { "i-Mic", 0x1 },
13147                 { "e-Mic", 0x0 },
13148         },
13149 };
13150
13151 #define alc662_mux_enum_info alc_mux_enum_info
13152 #define alc662_mux_enum_get alc_mux_enum_get
13153 #define alc662_mux_enum_put alc882_mux_enum_put
13154
13155 /*
13156  * 2ch mode
13157  */
13158 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
13159         { 2, NULL }
13160 };
13161
13162 /*
13163  * 2ch mode
13164  */
13165 static struct hda_verb alc662_3ST_ch2_init[] = {
13166         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
13167         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
13168         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
13169         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
13170         { } /* end */
13171 };
13172
13173 /*
13174  * 6ch mode
13175  */
13176 static struct hda_verb alc662_3ST_ch6_init[] = {
13177         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13178         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
13179         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
13180         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13181         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
13182         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
13183         { } /* end */
13184 };
13185
13186 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
13187         { 2, alc662_3ST_ch2_init },
13188         { 6, alc662_3ST_ch6_init },
13189 };
13190
13191 /*
13192  * 2ch mode
13193  */
13194 static struct hda_verb alc662_sixstack_ch6_init[] = {
13195         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13196         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13197         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13198         { } /* end */
13199 };
13200
13201 /*
13202  * 6ch mode
13203  */
13204 static struct hda_verb alc662_sixstack_ch8_init[] = {
13205         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13206         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13207         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13208         { } /* end */
13209 };
13210
13211 static struct hda_channel_mode alc662_5stack_modes[2] = {
13212         { 2, alc662_sixstack_ch6_init },
13213         { 6, alc662_sixstack_ch8_init },
13214 };
13215
13216 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
13217  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
13218  */
13219
13220 static struct snd_kcontrol_new alc662_base_mixer[] = {
13221         /* output mixer control */
13222         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
13223         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
13224         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
13225         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
13226         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
13227         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
13228         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
13229         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
13230         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13231
13232         /*Input mixer control */
13233         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
13234         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
13235         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
13236         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
13237         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
13238         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
13239         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
13240         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
13241         { } /* end */
13242 };
13243
13244 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
13245         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13246         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
13247         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13248         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13249         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13250         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13251         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13252         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13253         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13254         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13255         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13256         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
13257         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
13258         { } /* end */
13259 };
13260
13261 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
13262         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13263         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
13264         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13265         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
13266         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
13267         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
13268         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
13269         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
13270         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13271         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13272         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13273         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13274         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13275         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13276         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13277         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13278         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13279         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
13280         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
13281         { } /* end */
13282 };
13283
13284 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
13285         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13286         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
13287         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13288         HDA_BIND_MUTE("Speaker Playback Switch", 0x03, 2, HDA_INPUT),
13289         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13290         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13291         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13292         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13293         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13294         { } /* end */
13295 };
13296
13297 static struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
13298         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13299
13300         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13301         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13302
13303         HDA_CODEC_VOLUME("e-Mic Boost", 0x18, 0, HDA_INPUT),
13304         HDA_CODEC_VOLUME("e-Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13305         HDA_CODEC_MUTE("e-Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13306
13307         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
13308         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13309         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13310         { } /* end */
13311 };
13312
13313 static struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
13314         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13315         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13316         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13317         HDA_BIND_MUTE("Surround Playback Switch", 0x03, 2, HDA_INPUT),
13318         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
13319         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
13320         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
13321         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
13322         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13323         HDA_BIND_MUTE("MuteCtrl Playback Switch", 0x0c, 2, HDA_INPUT),
13324         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13325         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13326         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13327         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13328         { } /* end */
13329 };
13330
13331 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
13332         {
13333                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13334                 .name = "Channel Mode",
13335                 .info = alc_ch_mode_info,
13336                 .get = alc_ch_mode_get,
13337                 .put = alc_ch_mode_put,
13338         },
13339         { } /* end */
13340 };
13341
13342 static struct hda_verb alc662_init_verbs[] = {
13343         /* ADC: mute amp left and right */
13344         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13345         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
13346         /* Front mixer: unmute input/output amp left and right (volume = 0) */
13347
13348         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13349         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13350         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13351         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13352         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
13353
13354         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13355         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13356         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13357         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13358         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13359         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13360
13361         /* Front Pin: output 0 (0x0c) */
13362         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13363         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13364
13365         /* Rear Pin: output 1 (0x0d) */
13366         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13367         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13368
13369         /* CLFE Pin: output 2 (0x0e) */
13370         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13371         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13372
13373         /* Mic (rear) pin: input vref at 80% */
13374         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13375         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13376         /* Front Mic pin: input vref at 80% */
13377         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13378         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13379         /* Line In pin: input */
13380         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13381         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13382         /* Line-2 In: Headphone output (output 0 - 0x0c) */
13383         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13384         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13385         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
13386         /* CD pin widget for input */
13387         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13388
13389         /* FIXME: use matrix-type input source selection */
13390         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
13391         /* Input mixer */
13392         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13393         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13394         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13395         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
13396
13397         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13398         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13399         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13400         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
13401         { }
13402 };
13403
13404 static struct hda_verb alc662_sue_init_verbs[] = {
13405         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
13406         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
13407         {}
13408 };
13409
13410 static struct hda_verb alc662_eeepc_sue_init_verbs[] = {
13411         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
13412         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13413         {}
13414 };
13415
13416 /* Set Unsolicited Event*/
13417 static struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
13418         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13419         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13420         {}
13421 };
13422
13423 /*
13424  * generic initialization of ADC, input mixers and output mixers
13425  */
13426 static struct hda_verb alc662_auto_init_verbs[] = {
13427         /*
13428          * Unmute ADC and set the default input to mic-in
13429          */
13430         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
13431         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13432
13433         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
13434          * mixer widget
13435          * Note: PASD motherboards uses the Line In 2 as the input for front
13436          * panel mic (mic 2)
13437          */
13438         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
13439         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13440         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13441         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13442         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13443         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
13444
13445         /*
13446          * Set up output mixers (0x0c - 0x0f)
13447          */
13448         /* set vol=0 to output mixers */
13449         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13450         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13451         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13452
13453         /* set up input amps for analog loopback */
13454         /* Amp Indices: DAC = 0, mixer = 1 */
13455         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13456         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13457         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13458         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13459         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13460         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13461
13462
13463         /* FIXME: use matrix-type input source selection */
13464         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
13465         /* Input mixer */
13466         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13467         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13468         { }
13469 };
13470
13471 /* capture mixer elements */
13472 static struct snd_kcontrol_new alc662_capture_mixer[] = {
13473         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
13474         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
13475         {
13476                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13477                 /* The multiple "Capture Source" controls confuse alsamixer
13478                  * So call somewhat different..
13479                  */
13480                 /* .name = "Capture Source", */
13481                 .name = "Input Source",
13482                 .count = 1,
13483                 .info = alc662_mux_enum_info,
13484                 .get = alc662_mux_enum_get,
13485                 .put = alc662_mux_enum_put,
13486         },
13487         { } /* end */
13488 };
13489
13490 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
13491 {
13492         unsigned int present;
13493         unsigned char bits;
13494
13495         present = snd_hda_codec_read(codec, 0x14, 0,
13496                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13497         bits = present ? HDA_AMP_MUTE : 0;
13498         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
13499                                  HDA_AMP_MUTE, bits);
13500 }
13501
13502 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
13503 {
13504         unsigned int present;
13505         unsigned char bits;
13506
13507         present = snd_hda_codec_read(codec, 0x1b, 0,
13508                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13509         bits = present ? HDA_AMP_MUTE : 0;
13510         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
13511                                  HDA_AMP_MUTE, bits);
13512         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
13513                                  HDA_AMP_MUTE, bits);
13514 }
13515
13516 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
13517                                            unsigned int res)
13518 {
13519         if ((res >> 26) == ALC880_HP_EVENT)
13520                 alc662_lenovo_101e_all_automute(codec);
13521         if ((res >> 26) == ALC880_FRONT_EVENT)
13522                 alc662_lenovo_101e_ispeaker_automute(codec);
13523 }
13524
13525 static void alc662_eeepc_mic_automute(struct hda_codec *codec)
13526 {
13527         unsigned int present;
13528
13529         present = snd_hda_codec_read(codec, 0x18, 0,
13530                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13531         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13532                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
13533         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13534                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
13535         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13536                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
13537         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13538                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
13539 }
13540
13541 /* unsolicited event for HP jack sensing */
13542 static void alc662_eeepc_unsol_event(struct hda_codec *codec,
13543                                      unsigned int res)
13544 {
13545         if ((res >> 26) == ALC880_HP_EVENT)
13546                 alc262_hippo1_automute( codec );
13547
13548         if ((res >> 26) == ALC880_MIC_EVENT)
13549                 alc662_eeepc_mic_automute(codec);
13550 }
13551
13552 static void alc662_eeepc_inithook(struct hda_codec *codec)
13553 {
13554         alc262_hippo1_automute( codec );
13555         alc662_eeepc_mic_automute(codec);
13556 }
13557
13558 static void alc662_eeepc_ep20_automute(struct hda_codec *codec)
13559 {
13560         unsigned int mute;
13561         unsigned int present;
13562
13563         snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
13564         present = snd_hda_codec_read(codec, 0x14, 0,
13565                                      AC_VERB_GET_PIN_SENSE, 0);
13566         present = (present & 0x80000000) != 0;
13567         if (present) {
13568                 /* mute internal speaker */
13569                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
13570                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
13571         } else {
13572                 /* unmute internal speaker if necessary */
13573                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
13574                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
13575                                          HDA_AMP_MUTE, mute);
13576         }
13577 }
13578
13579 /* unsolicited event for HP jack sensing */
13580 static void alc662_eeepc_ep20_unsol_event(struct hda_codec *codec,
13581                                           unsigned int res)
13582 {
13583         if ((res >> 26) == ALC880_HP_EVENT)
13584                 alc662_eeepc_ep20_automute(codec);
13585 }
13586
13587 static void alc662_eeepc_ep20_inithook(struct hda_codec *codec)
13588 {
13589         alc662_eeepc_ep20_automute(codec);
13590 }
13591
13592 #ifdef CONFIG_SND_HDA_POWER_SAVE
13593 #define alc662_loopbacks        alc880_loopbacks
13594 #endif
13595
13596
13597 /* pcm configuration: identiacal with ALC880 */
13598 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
13599 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
13600 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
13601 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
13602
13603 /*
13604  * configuration and preset
13605  */
13606 static const char *alc662_models[ALC662_MODEL_LAST] = {
13607         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
13608         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
13609         [ALC662_3ST_6ch]        = "3stack-6ch",
13610         [ALC662_5ST_DIG]        = "6stack-dig",
13611         [ALC662_LENOVO_101E]    = "lenovo-101e",
13612         [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
13613         [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
13614         [ALC662_AUTO]           = "auto",
13615 };
13616
13617 static struct snd_pci_quirk alc662_cfg_tbl[] = {
13618         SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
13619         SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
13620         SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
13621         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
13622         {}
13623 };
13624
13625 static struct alc_config_preset alc662_presets[] = {
13626         [ALC662_3ST_2ch_DIG] = {
13627                 .mixers = { alc662_3ST_2ch_mixer, alc662_capture_mixer },
13628                 .init_verbs = { alc662_init_verbs },
13629                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13630                 .dac_nids = alc662_dac_nids,
13631                 .dig_out_nid = ALC662_DIGOUT_NID,
13632                 .dig_in_nid = ALC662_DIGIN_NID,
13633                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
13634                 .channel_mode = alc662_3ST_2ch_modes,
13635                 .input_mux = &alc662_capture_source,
13636         },
13637         [ALC662_3ST_6ch_DIG] = {
13638                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer,
13639                             alc662_capture_mixer },
13640                 .init_verbs = { alc662_init_verbs },
13641                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13642                 .dac_nids = alc662_dac_nids,
13643                 .dig_out_nid = ALC662_DIGOUT_NID,
13644                 .dig_in_nid = ALC662_DIGIN_NID,
13645                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
13646                 .channel_mode = alc662_3ST_6ch_modes,
13647                 .need_dac_fix = 1,
13648                 .input_mux = &alc662_capture_source,
13649         },
13650         [ALC662_3ST_6ch] = {
13651                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer,
13652                             alc662_capture_mixer },
13653                 .init_verbs = { alc662_init_verbs },
13654                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13655                 .dac_nids = alc662_dac_nids,
13656                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
13657                 .channel_mode = alc662_3ST_6ch_modes,
13658                 .need_dac_fix = 1,
13659                 .input_mux = &alc662_capture_source,
13660         },
13661         [ALC662_5ST_DIG] = {
13662                 .mixers = { alc662_base_mixer, alc662_chmode_mixer,
13663                             alc662_capture_mixer },
13664                 .init_verbs = { alc662_init_verbs },
13665                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13666                 .dac_nids = alc662_dac_nids,
13667                 .dig_out_nid = ALC662_DIGOUT_NID,
13668                 .dig_in_nid = ALC662_DIGIN_NID,
13669                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
13670                 .channel_mode = alc662_5stack_modes,
13671                 .input_mux = &alc662_capture_source,
13672         },
13673         [ALC662_LENOVO_101E] = {
13674                 .mixers = { alc662_lenovo_101e_mixer, alc662_capture_mixer },
13675                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
13676                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13677                 .dac_nids = alc662_dac_nids,
13678                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
13679                 .channel_mode = alc662_3ST_2ch_modes,
13680                 .input_mux = &alc662_lenovo_101e_capture_source,
13681                 .unsol_event = alc662_lenovo_101e_unsol_event,
13682                 .init_hook = alc662_lenovo_101e_all_automute,
13683         },
13684         [ALC662_ASUS_EEEPC_P701] = {
13685                 .mixers = { alc662_eeepc_p701_mixer, alc662_capture_mixer },
13686                 .init_verbs = { alc662_init_verbs,
13687                                 alc662_eeepc_sue_init_verbs },
13688                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13689                 .dac_nids = alc662_dac_nids,
13690                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
13691                 .channel_mode = alc662_3ST_2ch_modes,
13692                 .input_mux = &alc662_eeepc_capture_source,
13693                 .unsol_event = alc662_eeepc_unsol_event,
13694                 .init_hook = alc662_eeepc_inithook,
13695         },
13696         [ALC662_ASUS_EEEPC_EP20] = {
13697                 .mixers = { alc662_eeepc_ep20_mixer, alc662_capture_mixer,
13698                             alc662_chmode_mixer },
13699                 .init_verbs = { alc662_init_verbs,
13700                                 alc662_eeepc_ep20_sue_init_verbs },
13701                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13702                 .dac_nids = alc662_dac_nids,
13703                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
13704                 .channel_mode = alc662_3ST_6ch_modes,
13705                 .input_mux = &alc662_lenovo_101e_capture_source,
13706                 .unsol_event = alc662_eeepc_ep20_unsol_event,
13707                 .init_hook = alc662_eeepc_ep20_inithook,
13708         },
13709
13710 };
13711
13712
13713 /*
13714  * BIOS auto configuration
13715  */
13716
13717 /* add playback controls from the parsed DAC table */
13718 static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec,
13719                                              const struct auto_pin_cfg *cfg)
13720 {
13721         char name[32];
13722         static const char *chname[4] = {
13723                 "Front", "Surround", NULL /*CLFE*/, "Side"
13724         };
13725         hda_nid_t nid;
13726         int i, err;
13727
13728         for (i = 0; i < cfg->line_outs; i++) {
13729                 if (!spec->multiout.dac_nids[i])
13730                         continue;
13731                 nid = alc880_idx_to_dac(i);
13732                 if (i == 2) {
13733                         /* Center/LFE */
13734                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
13735                                           "Center Playback Volume",
13736                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
13737                                                               HDA_OUTPUT));
13738                         if (err < 0)
13739                                 return err;
13740                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
13741                                           "LFE Playback Volume",
13742                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
13743                                                               HDA_OUTPUT));
13744                         if (err < 0)
13745                                 return err;
13746                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13747                                           "Center Playback Switch",
13748                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
13749                                                               HDA_INPUT));
13750                         if (err < 0)
13751                                 return err;
13752                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13753                                           "LFE Playback Switch",
13754                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
13755                                                               HDA_INPUT));
13756                         if (err < 0)
13757                                 return err;
13758                 } else {
13759                         sprintf(name, "%s Playback Volume", chname[i]);
13760                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
13761                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
13762                                                               HDA_OUTPUT));
13763                         if (err < 0)
13764                                 return err;
13765                         sprintf(name, "%s Playback Switch", chname[i]);
13766                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
13767                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
13768                                                               HDA_INPUT));
13769                         if (err < 0)
13770                                 return err;
13771                 }
13772         }
13773         return 0;
13774 }
13775
13776 /* add playback controls for speaker and HP outputs */
13777 static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
13778                                         const char *pfx)
13779 {
13780         hda_nid_t nid;
13781         int err;
13782         char name[32];
13783
13784         if (!pin)
13785                 return 0;
13786
13787         if (alc880_is_fixed_pin(pin)) {
13788                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
13789                 /* printk("DAC nid=%x\n",nid); */
13790                 /* specify the DAC as the extra output */
13791                 if (!spec->multiout.hp_nid)
13792                         spec->multiout.hp_nid = nid;
13793                 else
13794                         spec->multiout.extra_out_nid[0] = nid;
13795                 /* control HP volume/switch on the output mixer amp */
13796                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
13797                 sprintf(name, "%s Playback Volume", pfx);
13798                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
13799                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
13800                 if (err < 0)
13801                         return err;
13802                 sprintf(name, "%s Playback Switch", pfx);
13803                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
13804                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
13805                 if (err < 0)
13806                         return err;
13807         } else if (alc880_is_multi_pin(pin)) {
13808                 /* set manual connection */
13809                 /* we have only a switch on HP-out PIN */
13810                 sprintf(name, "%s Playback Switch", pfx);
13811                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
13812                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
13813                 if (err < 0)
13814                         return err;
13815         }
13816         return 0;
13817 }
13818
13819 /* create playback/capture controls for input pins */
13820 static int alc662_auto_create_analog_input_ctls(struct alc_spec *spec,
13821                                                 const struct auto_pin_cfg *cfg)
13822 {
13823         struct hda_input_mux *imux = &spec->private_imux;
13824         int i, err, idx;
13825
13826         for (i = 0; i < AUTO_PIN_LAST; i++) {
13827                 if (alc880_is_input_pin(cfg->input_pins[i])) {
13828                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
13829                         err = new_analog_input(spec, cfg->input_pins[i],
13830                                                auto_pin_cfg_labels[i],
13831                                                idx, 0x0b);
13832                         if (err < 0)
13833                                 return err;
13834                         imux->items[imux->num_items].label =
13835                                 auto_pin_cfg_labels[i];
13836                         imux->items[imux->num_items].index =
13837                                 alc880_input_pin_idx(cfg->input_pins[i]);
13838                         imux->num_items++;
13839                 }
13840         }
13841         return 0;
13842 }
13843
13844 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
13845                                               hda_nid_t nid, int pin_type,
13846                                               int dac_idx)
13847 {
13848         alc_set_pin_output(codec, nid, pin_type);
13849         /* need the manual connection? */
13850         if (alc880_is_multi_pin(nid)) {
13851                 struct alc_spec *spec = codec->spec;
13852                 int idx = alc880_multi_pin_idx(nid);
13853                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
13854                                     AC_VERB_SET_CONNECT_SEL,
13855                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
13856         }
13857 }
13858
13859 static void alc662_auto_init_multi_out(struct hda_codec *codec)
13860 {
13861         struct alc_spec *spec = codec->spec;
13862         int i;
13863
13864         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
13865         for (i = 0; i <= HDA_SIDE; i++) {
13866                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
13867                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
13868                 if (nid)
13869                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
13870                                                           i);
13871         }
13872 }
13873
13874 static void alc662_auto_init_hp_out(struct hda_codec *codec)
13875 {
13876         struct alc_spec *spec = codec->spec;
13877         hda_nid_t pin;
13878
13879         pin = spec->autocfg.hp_pins[0];
13880         if (pin) /* connect to front */
13881                 /* use dac 0 */
13882                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
13883         pin = spec->autocfg.speaker_pins[0];
13884         if (pin)
13885                 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
13886 }
13887
13888 #define alc662_is_input_pin(nid)        alc880_is_input_pin(nid)
13889 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
13890
13891 static void alc662_auto_init_analog_input(struct hda_codec *codec)
13892 {
13893         struct alc_spec *spec = codec->spec;
13894         int i;
13895
13896         for (i = 0; i < AUTO_PIN_LAST; i++) {
13897                 hda_nid_t nid = spec->autocfg.input_pins[i];
13898                 if (alc662_is_input_pin(nid)) {
13899                         snd_hda_codec_write(codec, nid, 0,
13900                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
13901                                             (i <= AUTO_PIN_FRONT_MIC ?
13902                                              PIN_VREF80 : PIN_IN));
13903                         if (nid != ALC662_PIN_CD_NID)
13904                                 snd_hda_codec_write(codec, nid, 0,
13905                                                     AC_VERB_SET_AMP_GAIN_MUTE,
13906                                                     AMP_OUT_MUTE);
13907                 }
13908         }
13909 }
13910
13911 static int alc662_parse_auto_config(struct hda_codec *codec)
13912 {
13913         struct alc_spec *spec = codec->spec;
13914         int err;
13915         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
13916
13917         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
13918                                            alc662_ignore);
13919         if (err < 0)
13920                 return err;
13921         if (!spec->autocfg.line_outs)
13922                 return 0; /* can't find valid BIOS pin config */
13923
13924         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
13925         if (err < 0)
13926                 return err;
13927         err = alc662_auto_create_multi_out_ctls(spec, &spec->autocfg);
13928         if (err < 0)
13929                 return err;
13930         err = alc662_auto_create_extra_out(spec,
13931                                            spec->autocfg.speaker_pins[0],
13932                                            "Speaker");
13933         if (err < 0)
13934                 return err;
13935         err = alc662_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
13936                                            "Headphone");
13937         if (err < 0)
13938                 return err;
13939         err = alc662_auto_create_analog_input_ctls(spec, &spec->autocfg);
13940         if (err < 0)
13941                 return err;
13942
13943         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
13944
13945         if (spec->autocfg.dig_out_pin)
13946                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
13947
13948         if (spec->kctl_alloc)
13949                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
13950
13951         spec->num_mux_defs = 1;
13952         spec->input_mux = &spec->private_imux;
13953         
13954         spec->init_verbs[spec->num_init_verbs++] = alc662_auto_init_verbs;
13955         spec->mixers[spec->num_mixers] = alc662_capture_mixer;
13956         spec->num_mixers++;
13957         return 1;
13958 }
13959
13960 /* additional initialization for auto-configuration model */
13961 static void alc662_auto_init(struct hda_codec *codec)
13962 {
13963         struct alc_spec *spec = codec->spec;
13964         alc662_auto_init_multi_out(codec);
13965         alc662_auto_init_hp_out(codec);
13966         alc662_auto_init_analog_input(codec);
13967         if (spec->unsol_event)
13968                 alc_sku_automute(codec);
13969 }
13970
13971 static int patch_alc662(struct hda_codec *codec)
13972 {
13973         struct alc_spec *spec;
13974         int err, board_config;
13975
13976         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13977         if (!spec)
13978                 return -ENOMEM;
13979
13980         codec->spec = spec;
13981
13982         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
13983                                                   alc662_models,
13984                                                   alc662_cfg_tbl);
13985         if (board_config < 0) {
13986                 printk(KERN_INFO "hda_codec: Unknown model for ALC662, "
13987                        "trying auto-probe from BIOS...\n");
13988                 board_config = ALC662_AUTO;
13989         }
13990
13991         if (board_config == ALC662_AUTO) {
13992                 /* automatic parse from the BIOS config */
13993                 err = alc662_parse_auto_config(codec);
13994                 if (err < 0) {
13995                         alc_free(codec);
13996                         return err;
13997                 } else if (!err) {
13998                         printk(KERN_INFO
13999                                "hda_codec: Cannot set up configuration "
14000                                "from BIOS.  Using base mode...\n");
14001                         board_config = ALC662_3ST_2ch_DIG;
14002                 }
14003         }
14004
14005         if (board_config != ALC662_AUTO)
14006                 setup_preset(spec, &alc662_presets[board_config]);
14007
14008         spec->stream_name_analog = "ALC662 Analog";
14009         spec->stream_analog_playback = &alc662_pcm_analog_playback;
14010         spec->stream_analog_capture = &alc662_pcm_analog_capture;
14011
14012         spec->stream_name_digital = "ALC662 Digital";
14013         spec->stream_digital_playback = &alc662_pcm_digital_playback;
14014         spec->stream_digital_capture = &alc662_pcm_digital_capture;
14015
14016         spec->adc_nids = alc662_adc_nids;
14017         spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
14018         spec->capsrc_nids = alc662_capsrc_nids;
14019
14020         spec->vmaster_nid = 0x02;
14021
14022         codec->patch_ops = alc_patch_ops;
14023         if (board_config == ALC662_AUTO)
14024                 spec->init_hook = alc662_auto_init;
14025 #ifdef CONFIG_SND_HDA_POWER_SAVE
14026         if (!spec->loopback.amplist)
14027                 spec->loopback.amplist = alc662_loopbacks;
14028 #endif
14029
14030         return 0;
14031 }
14032
14033 /*
14034  * patch entries
14035  */
14036 struct hda_codec_preset snd_hda_preset_realtek[] = {
14037         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
14038         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
14039         { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
14040         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
14041         { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
14042         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
14043           .patch = patch_alc861 },
14044         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
14045         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
14046         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
14047         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
14048           .patch = patch_alc883 },
14049         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
14050           .patch = patch_alc662 },
14051         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
14052         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
14053         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
14054         { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
14055           .patch = patch_alc882 }, /* should be patch_alc883() in future */
14056         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
14057         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
14058         { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 },
14059         {} /* terminator */
14060 };