]> git.karo-electronics.de Git - mv-sheeva.git/blob - sound/pci/hda/patch_realtek.c
[ALSA] hda-codec - Add test model for ALC268
[mv-sheeva.git] / sound / pci / hda / patch_realtek.c
1 /*
2  * Universal Interface for Intel High Definition Audio Codec
3  *
4  * HD audio interface patch for ALC 260/880/882 codecs
5  *
6  * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7  *                    PeiSen Hou <pshou@realtek.com.tw>
8  *                    Takashi Iwai <tiwai@suse.de>
9  *                    Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
10  *
11  *  This driver is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This driver is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
24  */
25
26 #include <sound/driver.h>
27 #include <linux/init.h>
28 #include <linux/delay.h>
29 #include <linux/slab.h>
30 #include <linux/pci.h>
31 #include <sound/core.h>
32 #include "hda_codec.h"
33 #include "hda_local.h"
34
35 #define ALC880_FRONT_EVENT              0x01
36 #define ALC880_DCVOL_EVENT              0x02
37 #define ALC880_HP_EVENT                 0x04
38 #define ALC880_MIC_EVENT                0x08
39
40 /* ALC880 board config type */
41 enum {
42         ALC880_3ST,
43         ALC880_3ST_DIG,
44         ALC880_5ST,
45         ALC880_5ST_DIG,
46         ALC880_W810,
47         ALC880_Z71V,
48         ALC880_6ST,
49         ALC880_6ST_DIG,
50         ALC880_F1734,
51         ALC880_ASUS,
52         ALC880_ASUS_DIG,
53         ALC880_ASUS_W1V,
54         ALC880_ASUS_DIG2,
55         ALC880_FUJITSU,
56         ALC880_UNIWILL_DIG,
57         ALC880_UNIWILL,
58         ALC880_UNIWILL_P53,
59         ALC880_CLEVO,
60         ALC880_TCL_S700,
61         ALC880_LG,
62         ALC880_LG_LW,
63 #ifdef CONFIG_SND_DEBUG
64         ALC880_TEST,
65 #endif
66         ALC880_AUTO,
67         ALC880_MODEL_LAST /* last tag */
68 };
69
70 /* ALC260 models */
71 enum {
72         ALC260_BASIC,
73         ALC260_HP,
74         ALC260_HP_3013,
75         ALC260_FUJITSU_S702X,
76         ALC260_ACER,
77         ALC260_WILL,
78         ALC260_REPLACER_672V,
79 #ifdef CONFIG_SND_DEBUG
80         ALC260_TEST,
81 #endif
82         ALC260_AUTO,
83         ALC260_MODEL_LAST /* last tag */
84 };
85
86 /* ALC262 models */
87 enum {
88         ALC262_BASIC,
89         ALC262_HIPPO,
90         ALC262_HIPPO_1,
91         ALC262_FUJITSU,
92         ALC262_HP_BPC,
93         ALC262_HP_BPC_D7000_WL,
94         ALC262_HP_BPC_D7000_WF,
95         ALC262_HP_TC_T5735,
96         ALC262_BENQ_ED8,
97         ALC262_SONY_ASSAMD,
98         ALC262_BENQ_T31,
99         ALC262_ULTRA,
100         ALC262_AUTO,
101         ALC262_MODEL_LAST /* last tag */
102 };
103
104 /* ALC268 models */
105 enum {
106         ALC268_3ST,
107         ALC268_TOSHIBA,
108         ALC268_ACER,
109 #ifdef CONFIG_SND_DEBUG
110         ALC268_TEST,
111 #endif
112         ALC268_AUTO,
113         ALC268_MODEL_LAST /* last tag */
114 };
115
116 /* ALC269 models */
117 enum {
118         ALC269_BASIC,
119         ALC269_AUTO,
120         ALC269_MODEL_LAST /* last tag */
121 };
122
123 /* ALC861 models */
124 enum {
125         ALC861_3ST,
126         ALC660_3ST,
127         ALC861_3ST_DIG,
128         ALC861_6ST_DIG,
129         ALC861_UNIWILL_M31,
130         ALC861_TOSHIBA,
131         ALC861_ASUS,
132         ALC861_ASUS_LAPTOP,
133         ALC861_AUTO,
134         ALC861_MODEL_LAST,
135 };
136
137 /* ALC861-VD models */
138 enum {
139         ALC660VD_3ST,
140         ALC660VD_3ST_DIG,
141         ALC861VD_3ST,
142         ALC861VD_3ST_DIG,
143         ALC861VD_6ST_DIG,
144         ALC861VD_LENOVO,
145         ALC861VD_DALLAS,
146         ALC861VD_HP,
147         ALC861VD_AUTO,
148         ALC861VD_MODEL_LAST,
149 };
150
151 /* ALC662 models */
152 enum {
153         ALC662_3ST_2ch_DIG,
154         ALC662_3ST_6ch_DIG,
155         ALC662_3ST_6ch,
156         ALC662_5ST_DIG,
157         ALC662_LENOVO_101E,
158         ALC662_ASUS_EEEPC_P701,
159         ALC662_AUTO,
160         ALC662_MODEL_LAST,
161 };
162
163 /* ALC882 models */
164 enum {
165         ALC882_3ST_DIG,
166         ALC882_6ST_DIG,
167         ALC882_ARIMA,
168         ALC882_W2JC,
169         ALC882_TARGA,
170         ALC882_ASUS_A7J,
171         ALC882_ASUS_A7M,
172         ALC885_MACPRO,
173         ALC885_MBP3,
174         ALC885_IMAC24,
175         ALC882_AUTO,
176         ALC882_MODEL_LAST,
177 };
178
179 /* ALC883 models */
180 enum {
181         ALC883_3ST_2ch_DIG,
182         ALC883_3ST_6ch_DIG,
183         ALC883_3ST_6ch,
184         ALC883_6ST_DIG,
185         ALC883_TARGA_DIG,
186         ALC883_TARGA_2ch_DIG,
187         ALC883_ACER,
188         ALC883_ACER_ASPIRE,
189         ALC883_MEDION,
190         ALC883_MEDION_MD2,      
191         ALC883_LAPTOP_EAPD,
192         ALC883_LENOVO_101E_2ch,
193         ALC883_LENOVO_NB0763,
194         ALC888_LENOVO_MS7195_DIG,
195         ALC883_HAIER_W66,               
196         ALC888_6ST_HP,
197         ALC888_3ST_HP,
198         ALC883_MITAC,
199         ALC883_AUTO,
200         ALC883_MODEL_LAST,
201 };
202
203 /* for GPIO Poll */
204 #define GPIO_MASK       0x03
205
206 struct alc_spec {
207         /* codec parameterization */
208         struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
209         unsigned int num_mixers;
210
211         const struct hda_verb *init_verbs[5];   /* initialization verbs
212                                                  * don't forget NULL
213                                                  * termination!
214                                                  */
215         unsigned int num_init_verbs;
216
217         char *stream_name_analog;       /* analog PCM stream */
218         struct hda_pcm_stream *stream_analog_playback;
219         struct hda_pcm_stream *stream_analog_capture;
220
221         char *stream_name_digital;      /* digital PCM stream */
222         struct hda_pcm_stream *stream_digital_playback;
223         struct hda_pcm_stream *stream_digital_capture;
224
225         /* playback */
226         struct hda_multi_out multiout;  /* playback set-up
227                                          * max_channels, dacs must be set
228                                          * dig_out_nid and hp_nid are optional
229                                          */
230
231         /* capture */
232         unsigned int num_adc_nids;
233         hda_nid_t *adc_nids;
234         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
235
236         /* capture source */
237         unsigned int num_mux_defs;
238         const struct hda_input_mux *input_mux;
239         unsigned int cur_mux[3];
240
241         /* channel model */
242         const struct hda_channel_mode *channel_mode;
243         int num_channel_mode;
244         int need_dac_fix;
245
246         /* PCM information */
247         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
248
249         /* dynamic controls, init_verbs and input_mux */
250         struct auto_pin_cfg autocfg;
251         unsigned int num_kctl_alloc, num_kctl_used;
252         struct snd_kcontrol_new *kctl_alloc;
253         struct hda_input_mux private_imux;
254         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
255
256         /* hooks */
257         void (*init_hook)(struct hda_codec *codec);
258         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
259
260         /* for pin sensing */
261         unsigned int sense_updated: 1;
262         unsigned int jack_present: 1;
263
264 #ifdef CONFIG_SND_HDA_POWER_SAVE
265         struct hda_loopback_check loopback;
266 #endif
267 };
268
269 /*
270  * configuration template - to be copied to the spec instance
271  */
272 struct alc_config_preset {
273         struct snd_kcontrol_new *mixers[5]; /* should be identical size
274                                              * with spec
275                                              */
276         const struct hda_verb *init_verbs[5];
277         unsigned int num_dacs;
278         hda_nid_t *dac_nids;
279         hda_nid_t dig_out_nid;          /* optional */
280         hda_nid_t hp_nid;               /* optional */
281         unsigned int num_adc_nids;
282         hda_nid_t *adc_nids;
283         hda_nid_t dig_in_nid;
284         unsigned int num_channel_mode;
285         const struct hda_channel_mode *channel_mode;
286         int need_dac_fix;
287         unsigned int num_mux_defs;
288         const struct hda_input_mux *input_mux;
289         void (*unsol_event)(struct hda_codec *, unsigned int);
290         void (*init_hook)(struct hda_codec *);
291 #ifdef CONFIG_SND_HDA_POWER_SAVE
292         struct hda_amp_list *loopbacks;
293 #endif
294 };
295
296
297 /*
298  * input MUX handling
299  */
300 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
301                              struct snd_ctl_elem_info *uinfo)
302 {
303         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
304         struct alc_spec *spec = codec->spec;
305         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
306         if (mux_idx >= spec->num_mux_defs)
307                 mux_idx = 0;
308         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
309 }
310
311 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
312                             struct snd_ctl_elem_value *ucontrol)
313 {
314         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
315         struct alc_spec *spec = codec->spec;
316         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
317
318         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
319         return 0;
320 }
321
322 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
323                             struct snd_ctl_elem_value *ucontrol)
324 {
325         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
326         struct alc_spec *spec = codec->spec;
327         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
328         unsigned int mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
329         return snd_hda_input_mux_put(codec, &spec->input_mux[mux_idx], ucontrol,
330                                      spec->adc_nids[adc_idx],
331                                      &spec->cur_mux[adc_idx]);
332 }
333
334
335 /*
336  * channel mode setting
337  */
338 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
339                             struct snd_ctl_elem_info *uinfo)
340 {
341         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
342         struct alc_spec *spec = codec->spec;
343         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
344                                     spec->num_channel_mode);
345 }
346
347 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
348                            struct snd_ctl_elem_value *ucontrol)
349 {
350         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
351         struct alc_spec *spec = codec->spec;
352         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
353                                    spec->num_channel_mode,
354                                    spec->multiout.max_channels);
355 }
356
357 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
358                            struct snd_ctl_elem_value *ucontrol)
359 {
360         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
361         struct alc_spec *spec = codec->spec;
362         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
363                                       spec->num_channel_mode,
364                                       &spec->multiout.max_channels);
365         if (err >= 0 && spec->need_dac_fix)
366                 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
367         return err;
368 }
369
370 /*
371  * Control the mode of pin widget settings via the mixer.  "pc" is used
372  * instead of "%" to avoid consequences of accidently treating the % as 
373  * being part of a format specifier.  Maximum allowed length of a value is
374  * 63 characters plus NULL terminator.
375  *
376  * Note: some retasking pin complexes seem to ignore requests for input
377  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
378  * are requested.  Therefore order this list so that this behaviour will not
379  * cause problems when mixer clients move through the enum sequentially.
380  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
381  * March 2006.
382  */
383 static char *alc_pin_mode_names[] = {
384         "Mic 50pc bias", "Mic 80pc bias",
385         "Line in", "Line out", "Headphone out",
386 };
387 static unsigned char alc_pin_mode_values[] = {
388         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
389 };
390 /* The control can present all 5 options, or it can limit the options based
391  * in the pin being assumed to be exclusively an input or an output pin.  In
392  * addition, "input" pins may or may not process the mic bias option
393  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
394  * accept requests for bias as of chip versions up to March 2006) and/or
395  * wiring in the computer.
396  */
397 #define ALC_PIN_DIR_IN              0x00
398 #define ALC_PIN_DIR_OUT             0x01
399 #define ALC_PIN_DIR_INOUT           0x02
400 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
401 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
402
403 /* Info about the pin modes supported by the different pin direction modes. 
404  * For each direction the minimum and maximum values are given.
405  */
406 static signed char alc_pin_mode_dir_info[5][2] = {
407         { 0, 2 },    /* ALC_PIN_DIR_IN */
408         { 3, 4 },    /* ALC_PIN_DIR_OUT */
409         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
410         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
411         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
412 };
413 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
414 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
415 #define alc_pin_mode_n_items(_dir) \
416         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
417
418 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
419                              struct snd_ctl_elem_info *uinfo)
420 {
421         unsigned int item_num = uinfo->value.enumerated.item;
422         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
423
424         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
425         uinfo->count = 1;
426         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
427
428         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
429                 item_num = alc_pin_mode_min(dir);
430         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
431         return 0;
432 }
433
434 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
435                             struct snd_ctl_elem_value *ucontrol)
436 {
437         unsigned int i;
438         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
439         hda_nid_t nid = kcontrol->private_value & 0xffff;
440         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
441         long *valp = ucontrol->value.integer.value;
442         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
443                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
444                                                  0x00);
445
446         /* Find enumerated value for current pinctl setting */
447         i = alc_pin_mode_min(dir);
448         while (alc_pin_mode_values[i] != pinctl && i <= alc_pin_mode_max(dir))
449                 i++;
450         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
451         return 0;
452 }
453
454 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
455                             struct snd_ctl_elem_value *ucontrol)
456 {
457         signed int change;
458         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
459         hda_nid_t nid = kcontrol->private_value & 0xffff;
460         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
461         long val = *ucontrol->value.integer.value;
462         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
463                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
464                                                  0x00);
465
466         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
467                 val = alc_pin_mode_min(dir);
468
469         change = pinctl != alc_pin_mode_values[val];
470         if (change) {
471                 /* Set pin mode to that requested */
472                 snd_hda_codec_write_cache(codec, nid, 0,
473                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
474                                           alc_pin_mode_values[val]);
475
476                 /* Also enable the retasking pin's input/output as required 
477                  * for the requested pin mode.  Enum values of 2 or less are
478                  * input modes.
479                  *
480                  * Dynamically switching the input/output buffers probably
481                  * reduces noise slightly (particularly on input) so we'll
482                  * do it.  However, having both input and output buffers
483                  * enabled simultaneously doesn't seem to be problematic if
484                  * this turns out to be necessary in the future.
485                  */
486                 if (val <= 2) {
487                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
488                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
489                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
490                                                  HDA_AMP_MUTE, 0);
491                 } else {
492                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
493                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
494                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
495                                                  HDA_AMP_MUTE, 0);
496                 }
497         }
498         return change;
499 }
500
501 #define ALC_PIN_MODE(xname, nid, dir) \
502         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
503           .info = alc_pin_mode_info, \
504           .get = alc_pin_mode_get, \
505           .put = alc_pin_mode_put, \
506           .private_value = nid | (dir<<16) }
507
508 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
509  * together using a mask with more than one bit set.  This control is
510  * currently used only by the ALC260 test model.  At this stage they are not
511  * needed for any "production" models.
512  */
513 #ifdef CONFIG_SND_DEBUG
514 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
515
516 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
517                              struct snd_ctl_elem_value *ucontrol)
518 {
519         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
520         hda_nid_t nid = kcontrol->private_value & 0xffff;
521         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
522         long *valp = ucontrol->value.integer.value;
523         unsigned int val = snd_hda_codec_read(codec, nid, 0,
524                                               AC_VERB_GET_GPIO_DATA, 0x00);
525
526         *valp = (val & mask) != 0;
527         return 0;
528 }
529 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
530                              struct snd_ctl_elem_value *ucontrol)
531 {
532         signed int change;
533         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
534         hda_nid_t nid = kcontrol->private_value & 0xffff;
535         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
536         long val = *ucontrol->value.integer.value;
537         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
538                                                     AC_VERB_GET_GPIO_DATA,
539                                                     0x00);
540
541         /* Set/unset the masked GPIO bit(s) as needed */
542         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
543         if (val == 0)
544                 gpio_data &= ~mask;
545         else
546                 gpio_data |= mask;
547         snd_hda_codec_write_cache(codec, nid, 0,
548                                   AC_VERB_SET_GPIO_DATA, gpio_data);
549
550         return change;
551 }
552 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
553         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
554           .info = alc_gpio_data_info, \
555           .get = alc_gpio_data_get, \
556           .put = alc_gpio_data_put, \
557           .private_value = nid | (mask<<16) }
558 #endif   /* CONFIG_SND_DEBUG */
559
560 /* A switch control to allow the enabling of the digital IO pins on the
561  * ALC260.  This is incredibly simplistic; the intention of this control is
562  * to provide something in the test model allowing digital outputs to be
563  * identified if present.  If models are found which can utilise these
564  * outputs a more complete mixer control can be devised for those models if
565  * necessary.
566  */
567 #ifdef CONFIG_SND_DEBUG
568 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
569
570 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
571                               struct snd_ctl_elem_value *ucontrol)
572 {
573         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
574         hda_nid_t nid = kcontrol->private_value & 0xffff;
575         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
576         long *valp = ucontrol->value.integer.value;
577         unsigned int val = snd_hda_codec_read(codec, nid, 0,
578                                               AC_VERB_GET_DIGI_CONVERT_1, 0x00);
579
580         *valp = (val & mask) != 0;
581         return 0;
582 }
583 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
584                               struct snd_ctl_elem_value *ucontrol)
585 {
586         signed int change;
587         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
588         hda_nid_t nid = kcontrol->private_value & 0xffff;
589         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
590         long val = *ucontrol->value.integer.value;
591         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
592                                                     AC_VERB_GET_DIGI_CONVERT_1,
593                                                     0x00);
594
595         /* Set/unset the masked control bit(s) as needed */
596         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
597         if (val==0)
598                 ctrl_data &= ~mask;
599         else
600                 ctrl_data |= mask;
601         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
602                                   ctrl_data);
603
604         return change;
605 }
606 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
607         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
608           .info = alc_spdif_ctrl_info, \
609           .get = alc_spdif_ctrl_get, \
610           .put = alc_spdif_ctrl_put, \
611           .private_value = nid | (mask<<16) }
612 #endif   /* CONFIG_SND_DEBUG */
613
614 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
615  * Again, this is only used in the ALC26x test models to help identify when
616  * the EAPD line must be asserted for features to work.
617  */
618 #ifdef CONFIG_SND_DEBUG
619 #define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
620
621 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
622                               struct snd_ctl_elem_value *ucontrol)
623 {
624         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
625         hda_nid_t nid = kcontrol->private_value & 0xffff;
626         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
627         long *valp = ucontrol->value.integer.value;
628         unsigned int val = snd_hda_codec_read(codec, nid, 0,
629                                               AC_VERB_GET_EAPD_BTLENABLE, 0x00);
630
631         *valp = (val & mask) != 0;
632         return 0;
633 }
634
635 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
636                               struct snd_ctl_elem_value *ucontrol)
637 {
638         int change;
639         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
640         hda_nid_t nid = kcontrol->private_value & 0xffff;
641         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
642         long val = *ucontrol->value.integer.value;
643         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
644                                                     AC_VERB_GET_EAPD_BTLENABLE,
645                                                     0x00);
646
647         /* Set/unset the masked control bit(s) as needed */
648         change = (!val ? 0 : mask) != (ctrl_data & mask);
649         if (!val)
650                 ctrl_data &= ~mask;
651         else
652                 ctrl_data |= mask;
653         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
654                                   ctrl_data);
655
656         return change;
657 }
658
659 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
660         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
661           .info = alc_eapd_ctrl_info, \
662           .get = alc_eapd_ctrl_get, \
663           .put = alc_eapd_ctrl_put, \
664           .private_value = nid | (mask<<16) }
665 #endif   /* CONFIG_SND_DEBUG */
666
667 /*
668  * set up from the preset table
669  */
670 static void setup_preset(struct alc_spec *spec,
671                          const struct alc_config_preset *preset)
672 {
673         int i;
674
675         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
676                 spec->mixers[spec->num_mixers++] = preset->mixers[i];
677         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
678              i++)
679                 spec->init_verbs[spec->num_init_verbs++] =
680                         preset->init_verbs[i];
681         
682         spec->channel_mode = preset->channel_mode;
683         spec->num_channel_mode = preset->num_channel_mode;
684         spec->need_dac_fix = preset->need_dac_fix;
685
686         spec->multiout.max_channels = spec->channel_mode[0].channels;
687
688         spec->multiout.num_dacs = preset->num_dacs;
689         spec->multiout.dac_nids = preset->dac_nids;
690         spec->multiout.dig_out_nid = preset->dig_out_nid;
691         spec->multiout.hp_nid = preset->hp_nid;
692         
693         spec->num_mux_defs = preset->num_mux_defs;
694         if (!spec->num_mux_defs)
695                 spec->num_mux_defs = 1;
696         spec->input_mux = preset->input_mux;
697
698         spec->num_adc_nids = preset->num_adc_nids;
699         spec->adc_nids = preset->adc_nids;
700         spec->dig_in_nid = preset->dig_in_nid;
701
702         spec->unsol_event = preset->unsol_event;
703         spec->init_hook = preset->init_hook;
704 #ifdef CONFIG_SND_HDA_POWER_SAVE
705         spec->loopback.amplist = preset->loopbacks;
706 #endif
707 }
708
709 /* Enable GPIO mask and set output */
710 static struct hda_verb alc_gpio1_init_verbs[] = {
711         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
712         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
713         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
714         { }
715 };
716
717 static struct hda_verb alc_gpio2_init_verbs[] = {
718         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
719         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
720         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
721         { }
722 };
723
724 static struct hda_verb alc_gpio3_init_verbs[] = {
725         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
726         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
727         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
728         { }
729 };
730
731 static void alc_sku_automute(struct hda_codec *codec)
732 {
733         struct alc_spec *spec = codec->spec;
734         unsigned int mute;
735         unsigned int present;
736         unsigned int hp_nid = spec->autocfg.hp_pins[0];
737         unsigned int sp_nid = spec->autocfg.speaker_pins[0];
738
739         /* need to execute and sync at first */
740         snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
741         present = snd_hda_codec_read(codec, hp_nid, 0,
742                                      AC_VERB_GET_PIN_SENSE, 0);
743         spec->jack_present = (present & 0x80000000) != 0;
744         if (spec->jack_present) {
745                 /* mute internal speaker */
746                 snd_hda_codec_amp_stereo(codec, sp_nid, HDA_OUTPUT, 0,
747                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
748         } else {
749                 /* unmute internal speaker if necessary */
750                 mute = snd_hda_codec_amp_read(codec, hp_nid, 0, HDA_OUTPUT, 0);
751                 snd_hda_codec_amp_stereo(codec, sp_nid, HDA_OUTPUT, 0,
752                                          HDA_AMP_MUTE, mute);
753         }
754 }
755
756 /* unsolicited event for HP jack sensing */
757 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
758 {
759         if (codec->vendor_id == 0x10ec0880)
760                 res >>= 28;
761         else
762                 res >>= 26;
763         if (res != ALC880_HP_EVENT)
764                 return;
765
766         alc_sku_automute(codec);
767 }
768
769 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
770  *      31 ~ 16 :       Manufacture ID
771  *      15 ~ 8  :       SKU ID
772  *      7  ~ 0  :       Assembly ID
773  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
774  */
775 static void alc_subsystem_id(struct hda_codec *codec,
776                              unsigned int porta, unsigned int porte,
777                              unsigned int portd)
778 {
779         unsigned int ass, tmp, i;
780         unsigned nid;
781         struct alc_spec *spec = codec->spec;
782
783         ass = codec->subsystem_id & 0xffff;
784         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
785                 goto do_sku;
786
787         /*      
788          * 31~30        : port conetcivity
789          * 29~21        : reserve
790          * 20           : PCBEEP input
791          * 19~16        : Check sum (15:1)
792          * 15~1         : Custom
793          * 0            : override
794         */
795         nid = 0x1d;
796         if (codec->vendor_id == 0x10ec0260)
797                 nid = 0x17;
798         ass = snd_hda_codec_read(codec, nid, 0,
799                                  AC_VERB_GET_CONFIG_DEFAULT, 0);
800         if (!(ass & 1) && !(ass & 0x100000))
801                 return;
802         if ((ass >> 30) != 1)   /* no physical connection */
803                 return;
804
805         /* check sum */
806         tmp = 0;
807         for (i = 1; i < 16; i++) {
808                 if ((ass >> i) && 1)
809                         tmp++;
810         }
811         if (((ass >> 16) & 0xf) != tmp)
812                 return;
813 do_sku:
814         /*
815          * 0 : override
816          * 1 :  Swap Jack
817          * 2 : 0 --> Desktop, 1 --> Laptop
818          * 3~5 : External Amplifier control
819          * 7~6 : Reserved
820         */
821         tmp = (ass & 0x38) >> 3;        /* external Amp control */
822         switch (tmp) {
823         case 1:
824                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
825                 break;
826         case 3:
827                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
828                 break;
829         case 7:
830                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
831                 break;
832         case 5: /* set EAPD output high */
833                 switch (codec->vendor_id) {
834                 case 0x10ec0260:
835                         snd_hda_codec_write(codec, 0x0f, 0,
836                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
837                         snd_hda_codec_write(codec, 0x10, 0,
838                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
839                         break;
840                 case 0x10ec0262:
841                 case 0x10ec0267:
842                 case 0x10ec0268:
843                 case 0x10ec0269:
844                 case 0x10ec0862:
845                 case 0x10ec0662:        
846                         snd_hda_codec_write(codec, 0x14, 0,
847                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
848                         snd_hda_codec_write(codec, 0x15, 0,
849                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
850                         break;
851                 }
852                 switch (codec->vendor_id) {
853                 case 0x10ec0260:
854                         snd_hda_codec_write(codec, 0x1a, 0,
855                                             AC_VERB_SET_COEF_INDEX, 7);
856                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
857                                                  AC_VERB_GET_PROC_COEF, 0);
858                         snd_hda_codec_write(codec, 0x1a, 0,
859                                             AC_VERB_SET_COEF_INDEX, 7);
860                         snd_hda_codec_write(codec, 0x1a, 0,
861                                             AC_VERB_SET_PROC_COEF,
862                                             tmp | 0x2010);
863                         break;
864                 case 0x10ec0262:
865                 case 0x10ec0880:
866                 case 0x10ec0882:
867                 case 0x10ec0883:
868                 case 0x10ec0885:
869                 case 0x10ec0888:
870                         snd_hda_codec_write(codec, 0x20, 0,
871                                             AC_VERB_SET_COEF_INDEX, 7);
872                         tmp = snd_hda_codec_read(codec, 0x20, 0,
873                                                  AC_VERB_GET_PROC_COEF, 0);
874                         snd_hda_codec_write(codec, 0x20, 0,
875                                             AC_VERB_SET_COEF_INDEX, 7); 
876                         snd_hda_codec_write(codec, 0x20, 0,
877                                             AC_VERB_SET_PROC_COEF,
878                                             tmp | 0x2010);
879                         break;
880                 case 0x10ec0267:
881                 case 0x10ec0268:
882                         snd_hda_codec_write(codec, 0x20, 0,
883                                             AC_VERB_SET_COEF_INDEX, 7);
884                         tmp = snd_hda_codec_read(codec, 0x20, 0,
885                                                  AC_VERB_GET_PROC_COEF, 0);
886                         snd_hda_codec_write(codec, 0x20, 0,
887                                             AC_VERB_SET_COEF_INDEX, 7); 
888                         snd_hda_codec_write(codec, 0x20, 0,
889                                             AC_VERB_SET_PROC_COEF,
890                                             tmp | 0x3000);
891                         break;
892                 }
893         default:
894                 break;
895         }
896         
897         /* is laptop and enable the function "Mute internal speaker
898          * when the external headphone out jack is plugged"
899          */
900         if (!(ass & 0x4) || !(ass & 0x8000))
901                 return;
902         /*
903          * 10~8 : Jack location
904          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
905          * 14~13: Resvered
906          * 15   : 1 --> enable the function "Mute internal speaker
907          *              when the external headphone out jack is plugged"
908          */
909         if (!spec->autocfg.speaker_pins[0]) {
910                 if (spec->multiout.dac_nids[0])
911                         spec->autocfg.speaker_pins[0] =
912                                 spec->multiout.dac_nids[0];
913                 else
914                         return;
915         }
916
917         if (!spec->autocfg.hp_pins[0]) {
918                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
919                 if (tmp == 0)
920                         spec->autocfg.hp_pins[0] = porta;
921                 else if (tmp == 1)
922                         spec->autocfg.hp_pins[0] = porte;
923                 else if (tmp == 2)
924                         spec->autocfg.hp_pins[0] = portd;
925                 else
926                         return;
927         }
928
929         snd_hda_codec_write(codec, spec->autocfg.hp_pins[0], 0,
930                             AC_VERB_SET_UNSOLICITED_ENABLE,
931                             AC_USRSP_EN | ALC880_HP_EVENT);
932         spec->unsol_event = alc_sku_unsol_event;
933         spec->init_hook = alc_sku_automute;     
934 }
935
936 /*
937  * Fix-up pin default configurations
938  */
939
940 struct alc_pincfg {
941         hda_nid_t nid;
942         u32 val;
943 };
944
945 static void alc_fix_pincfg(struct hda_codec *codec,
946                            const struct snd_pci_quirk *quirk,
947                            const struct alc_pincfg **pinfix)
948 {
949         const struct alc_pincfg *cfg;
950
951         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
952         if (!quirk)
953                 return;
954
955         cfg = pinfix[quirk->value];
956         for (; cfg->nid; cfg++) {
957                 int i;
958                 u32 val = cfg->val;
959                 for (i = 0; i < 4; i++) {
960                         snd_hda_codec_write(codec, cfg->nid, 0,
961                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0 + i,
962                                     val & 0xff);
963                         val >>= 8;
964                 }
965         }
966 }
967
968 /*
969  * ALC880 3-stack model
970  *
971  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
972  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
973  *                 F-Mic = 0x1b, HP = 0x19
974  */
975
976 static hda_nid_t alc880_dac_nids[4] = {
977         /* front, rear, clfe, rear_surr */
978         0x02, 0x05, 0x04, 0x03
979 };
980
981 static hda_nid_t alc880_adc_nids[3] = {
982         /* ADC0-2 */
983         0x07, 0x08, 0x09,
984 };
985
986 /* The datasheet says the node 0x07 is connected from inputs,
987  * but it shows zero connection in the real implementation on some devices.
988  * Note: this is a 915GAV bug, fixed on 915GLV
989  */
990 static hda_nid_t alc880_adc_nids_alt[2] = {
991         /* ADC1-2 */
992         0x08, 0x09,
993 };
994
995 #define ALC880_DIGOUT_NID       0x06
996 #define ALC880_DIGIN_NID        0x0a
997
998 static struct hda_input_mux alc880_capture_source = {
999         .num_items = 4,
1000         .items = {
1001                 { "Mic", 0x0 },
1002                 { "Front Mic", 0x3 },
1003                 { "Line", 0x2 },
1004                 { "CD", 0x4 },
1005         },
1006 };
1007
1008 /* channel source setting (2/6 channel selection for 3-stack) */
1009 /* 2ch mode */
1010 static struct hda_verb alc880_threestack_ch2_init[] = {
1011         /* set line-in to input, mute it */
1012         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1013         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1014         /* set mic-in to input vref 80%, mute it */
1015         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1016         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1017         { } /* end */
1018 };
1019
1020 /* 6ch mode */
1021 static struct hda_verb alc880_threestack_ch6_init[] = {
1022         /* set line-in to output, unmute it */
1023         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1024         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1025         /* set mic-in to output, unmute it */
1026         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1027         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1028         { } /* end */
1029 };
1030
1031 static struct hda_channel_mode alc880_threestack_modes[2] = {
1032         { 2, alc880_threestack_ch2_init },
1033         { 6, alc880_threestack_ch6_init },
1034 };
1035
1036 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1037         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1038         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1039         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1040         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1041         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1042         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1043         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1044         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1045         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1046         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1047         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1048         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1049         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1050         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1051         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
1052         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
1053         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1054         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1055         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
1056         {
1057                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1058                 .name = "Channel Mode",
1059                 .info = alc_ch_mode_info,
1060                 .get = alc_ch_mode_get,
1061                 .put = alc_ch_mode_put,
1062         },
1063         { } /* end */
1064 };
1065
1066 /* capture mixer elements */
1067 static struct snd_kcontrol_new alc880_capture_mixer[] = {
1068         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
1069         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
1070         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
1071         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
1072         HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
1073         HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
1074         {
1075                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1076                 /* The multiple "Capture Source" controls confuse alsamixer
1077                  * So call somewhat different..
1078                  * FIXME: the controls appear in the "playback" view!
1079                  */
1080                 /* .name = "Capture Source", */
1081                 .name = "Input Source",
1082                 .count = 3,
1083                 .info = alc_mux_enum_info,
1084                 .get = alc_mux_enum_get,
1085                 .put = alc_mux_enum_put,
1086         },
1087         { } /* end */
1088 };
1089
1090 /* capture mixer elements (in case NID 0x07 not available) */
1091 static struct snd_kcontrol_new alc880_capture_alt_mixer[] = {
1092         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1093         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1094         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
1095         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
1096         {
1097                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1098                 /* The multiple "Capture Source" controls confuse alsamixer
1099                  * So call somewhat different..
1100                  * FIXME: the controls appear in the "playback" view!
1101                  */
1102                 /* .name = "Capture Source", */
1103                 .name = "Input Source",
1104                 .count = 2,
1105                 .info = alc_mux_enum_info,
1106                 .get = alc_mux_enum_get,
1107                 .put = alc_mux_enum_put,
1108         },
1109         { } /* end */
1110 };
1111
1112
1113
1114 /*
1115  * ALC880 5-stack model
1116  *
1117  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
1118  *      Side = 0x02 (0xd)
1119  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
1120  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
1121  */
1122
1123 /* additional mixers to alc880_three_stack_mixer */
1124 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
1125         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1126         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
1127         { } /* end */
1128 };
1129
1130 /* channel source setting (6/8 channel selection for 5-stack) */
1131 /* 6ch mode */
1132 static struct hda_verb alc880_fivestack_ch6_init[] = {
1133         /* set line-in to input, mute it */
1134         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1135         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1136         { } /* end */
1137 };
1138
1139 /* 8ch mode */
1140 static struct hda_verb alc880_fivestack_ch8_init[] = {
1141         /* set line-in to output, unmute it */
1142         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1143         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1144         { } /* end */
1145 };
1146
1147 static struct hda_channel_mode alc880_fivestack_modes[2] = {
1148         { 6, alc880_fivestack_ch6_init },
1149         { 8, alc880_fivestack_ch8_init },
1150 };
1151
1152
1153 /*
1154  * ALC880 6-stack model
1155  *
1156  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
1157  *      Side = 0x05 (0x0f)
1158  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
1159  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
1160  */
1161
1162 static hda_nid_t alc880_6st_dac_nids[4] = {
1163         /* front, rear, clfe, rear_surr */
1164         0x02, 0x03, 0x04, 0x05
1165 };
1166
1167 static struct hda_input_mux alc880_6stack_capture_source = {
1168         .num_items = 4,
1169         .items = {
1170                 { "Mic", 0x0 },
1171                 { "Front Mic", 0x1 },
1172                 { "Line", 0x2 },
1173                 { "CD", 0x4 },
1174         },
1175 };
1176
1177 /* fixed 8-channels */
1178 static struct hda_channel_mode alc880_sixstack_modes[1] = {
1179         { 8, NULL },
1180 };
1181
1182 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
1183         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1184         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1185         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1186         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1187         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1188         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1189         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1190         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1191         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1192         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1193         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1194         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1195         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1196         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1197         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1198         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1199         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1200         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1201         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1202         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1203         {
1204                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1205                 .name = "Channel Mode",
1206                 .info = alc_ch_mode_info,
1207                 .get = alc_ch_mode_get,
1208                 .put = alc_ch_mode_put,
1209         },
1210         { } /* end */
1211 };
1212
1213
1214 /*
1215  * ALC880 W810 model
1216  *
1217  * W810 has rear IO for:
1218  * Front (DAC 02)
1219  * Surround (DAC 03)
1220  * Center/LFE (DAC 04)
1221  * Digital out (06)
1222  *
1223  * The system also has a pair of internal speakers, and a headphone jack.
1224  * These are both connected to Line2 on the codec, hence to DAC 02.
1225  * 
1226  * There is a variable resistor to control the speaker or headphone
1227  * volume. This is a hardware-only device without a software API.
1228  *
1229  * Plugging headphones in will disable the internal speakers. This is
1230  * implemented in hardware, not via the driver using jack sense. In
1231  * a similar fashion, plugging into the rear socket marked "front" will
1232  * disable both the speakers and headphones.
1233  *
1234  * For input, there's a microphone jack, and an "audio in" jack.
1235  * These may not do anything useful with this driver yet, because I
1236  * haven't setup any initialization verbs for these yet...
1237  */
1238
1239 static hda_nid_t alc880_w810_dac_nids[3] = {
1240         /* front, rear/surround, clfe */
1241         0x02, 0x03, 0x04
1242 };
1243
1244 /* fixed 6 channels */
1245 static struct hda_channel_mode alc880_w810_modes[1] = {
1246         { 6, NULL }
1247 };
1248
1249 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
1250 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
1251         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1252         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1253         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1254         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1255         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1256         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1257         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1258         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1259         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1260         { } /* end */
1261 };
1262
1263
1264 /*
1265  * Z710V model
1266  *
1267  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
1268  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
1269  *                 Line = 0x1a
1270  */
1271
1272 static hda_nid_t alc880_z71v_dac_nids[1] = {
1273         0x02
1274 };
1275 #define ALC880_Z71V_HP_DAC      0x03
1276
1277 /* fixed 2 channels */
1278 static struct hda_channel_mode alc880_2_jack_modes[1] = {
1279         { 2, NULL }
1280 };
1281
1282 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
1283         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1284         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1285         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1286         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
1287         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1288         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1289         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1290         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1291         { } /* end */
1292 };
1293
1294
1295 /* FIXME! */
1296 /*
1297  * ALC880 F1734 model
1298  *
1299  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
1300  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
1301  */
1302
1303 static hda_nid_t alc880_f1734_dac_nids[1] = {
1304         0x03
1305 };
1306 #define ALC880_F1734_HP_DAC     0x02
1307
1308 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
1309         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1310         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1311         HDA_CODEC_VOLUME("Internal Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1312         HDA_BIND_MUTE("Internal Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1313         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1314         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1315         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1316         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1317         { } /* end */
1318 };
1319
1320
1321 /* FIXME! */
1322 /*
1323  * ALC880 ASUS model
1324  *
1325  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1326  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1327  *  Mic = 0x18, Line = 0x1a
1328  */
1329
1330 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
1331 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
1332
1333 static struct snd_kcontrol_new alc880_asus_mixer[] = {
1334         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1335         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1336         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1337         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1338         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1339         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1340         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1341         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1342         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1343         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1344         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1345         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1346         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1347         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1348         {
1349                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1350                 .name = "Channel Mode",
1351                 .info = alc_ch_mode_info,
1352                 .get = alc_ch_mode_get,
1353                 .put = alc_ch_mode_put,
1354         },
1355         { } /* end */
1356 };
1357
1358 /* FIXME! */
1359 /*
1360  * ALC880 ASUS W1V model
1361  *
1362  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1363  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1364  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
1365  */
1366
1367 /* additional mixers to alc880_asus_mixer */
1368 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
1369         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
1370         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
1371         { } /* end */
1372 };
1373
1374 /* additional mixers to alc880_asus_mixer */
1375 static struct snd_kcontrol_new alc880_pcbeep_mixer[] = {
1376         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1377         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1378         { } /* end */
1379 };
1380
1381 /* TCL S700 */
1382 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
1383         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1384         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1385         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1386         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
1387         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
1388         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
1389         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
1390         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1391         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1392         {
1393                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1394                 /* The multiple "Capture Source" controls confuse alsamixer
1395                  * So call somewhat different..
1396                  * FIXME: the controls appear in the "playback" view!
1397                  */
1398                 /* .name = "Capture Source", */
1399                 .name = "Input Source",
1400                 .count = 1,
1401                 .info = alc_mux_enum_info,
1402                 .get = alc_mux_enum_get,
1403                 .put = alc_mux_enum_put,
1404         },
1405         { } /* end */
1406 };
1407
1408 /* Uniwill */
1409 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
1410         HDA_CODEC_VOLUME("HPhone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1411         HDA_BIND_MUTE("HPhone Playback Switch", 0x0c, 2, HDA_INPUT),
1412         HDA_CODEC_VOLUME("iSpeaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1413         HDA_BIND_MUTE("iSpeaker Playback Switch", 0x0d, 2, HDA_INPUT),
1414         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1415         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1416         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1417         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1418         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1419         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1420         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1421         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1422         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1423         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1424         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1425         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1426         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1427         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1428         {
1429                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1430                 .name = "Channel Mode",
1431                 .info = alc_ch_mode_info,
1432                 .get = alc_ch_mode_get,
1433                 .put = alc_ch_mode_put,
1434         },
1435         { } /* end */
1436 };
1437
1438 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
1439         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1440         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1441         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1442         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1443         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1444         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1445         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1446         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1447         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1448         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1449         { } /* end */
1450 };
1451
1452 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
1453         HDA_CODEC_VOLUME("HPhone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1454         HDA_BIND_MUTE("HPhone Playback Switch", 0x0c, 2, HDA_INPUT),
1455         HDA_CODEC_VOLUME("iSpeaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1456         HDA_BIND_MUTE("iSpeaker Playback Switch", 0x0d, 2, HDA_INPUT),
1457         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1458         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1459         { } /* end */
1460 };
1461
1462 /*
1463  * build control elements
1464  */
1465 static int alc_build_controls(struct hda_codec *codec)
1466 {
1467         struct alc_spec *spec = codec->spec;
1468         int err;
1469         int i;
1470
1471         for (i = 0; i < spec->num_mixers; i++) {
1472                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1473                 if (err < 0)
1474                         return err;
1475         }
1476
1477         if (spec->multiout.dig_out_nid) {
1478                 err = snd_hda_create_spdif_out_ctls(codec,
1479                                                     spec->multiout.dig_out_nid);
1480                 if (err < 0)
1481                         return err;
1482         }
1483         if (spec->dig_in_nid) {
1484                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1485                 if (err < 0)
1486                         return err;
1487         }
1488         return 0;
1489 }
1490
1491
1492 /*
1493  * initialize the codec volumes, etc
1494  */
1495
1496 /*
1497  * generic initialization of ADC, input mixers and output mixers
1498  */
1499 static struct hda_verb alc880_volume_init_verbs[] = {
1500         /*
1501          * Unmute ADC0-2 and set the default input to mic-in
1502          */
1503         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
1504         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1505         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
1506         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1507         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
1508         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1509
1510         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1511          * mixer widget
1512          * Note: PASD motherboards uses the Line In 2 as the input for front
1513          * panel mic (mic 2)
1514          */
1515         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
1516         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1517         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1518         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
1519         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
1520         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
1521         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
1522         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
1523
1524         /*
1525          * Set up output mixers (0x0c - 0x0f)
1526          */
1527         /* set vol=0 to output mixers */
1528         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1529         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1530         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1531         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1532         /* set up input amps for analog loopback */
1533         /* Amp Indices: DAC = 0, mixer = 1 */
1534         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1535         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1536         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1537         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1538         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1539         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1540         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1541         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1542
1543         { }
1544 };
1545
1546 /*
1547  * 3-stack pin configuration:
1548  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
1549  */
1550 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
1551         /*
1552          * preset connection lists of input pins
1553          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1554          */
1555         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
1556         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1557         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
1558
1559         /*
1560          * Set pin mode and muting
1561          */
1562         /* set front pin widgets 0x14 for output */
1563         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1564         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1565         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1566         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1567         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1568         /* Mic2 (as headphone out) for HP output */
1569         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1570         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1571         /* Line In pin widget for input */
1572         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1573         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1574         /* Line2 (as front mic) pin widget for input and vref at 80% */
1575         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1576         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1577         /* CD pin widget for input */
1578         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1579
1580         { }
1581 };
1582
1583 /*
1584  * 5-stack pin configuration:
1585  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
1586  * line-in/side = 0x1a, f-mic = 0x1b
1587  */
1588 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
1589         /*
1590          * preset connection lists of input pins
1591          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1592          */
1593         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1594         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
1595
1596         /*
1597          * Set pin mode and muting
1598          */
1599         /* set pin widgets 0x14-0x17 for output */
1600         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1601         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1602         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1603         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1604         /* unmute pins for output (no gain on this amp) */
1605         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1606         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1607         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1608         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1609
1610         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1611         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1612         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1613         /* Mic2 (as headphone out) for HP output */
1614         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1615         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1616         /* Line In pin widget for input */
1617         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1618         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1619         /* Line2 (as front mic) pin widget for input and vref at 80% */
1620         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1621         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1622         /* CD pin widget for input */
1623         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1624
1625         { }
1626 };
1627
1628 /*
1629  * W810 pin configuration:
1630  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
1631  */
1632 static struct hda_verb alc880_pin_w810_init_verbs[] = {
1633         /* hphone/speaker input selector: front DAC */
1634         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
1635
1636         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1637         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1638         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1639         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1640         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1641         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1642
1643         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1644         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1645
1646         { }
1647 };
1648
1649 /*
1650  * Z71V pin configuration:
1651  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
1652  */
1653 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
1654         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1655         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1656         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1657         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1658
1659         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1660         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1661         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1662         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1663
1664         { }
1665 };
1666
1667 /*
1668  * 6-stack pin configuration:
1669  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
1670  * f-mic = 0x19, line = 0x1a, HP = 0x1b
1671  */
1672 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
1673         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1674
1675         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1676         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1677         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1678         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1679         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1680         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1681         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1682         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1683
1684         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1685         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1686         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1687         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1688         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1689         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1690         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1691         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1692         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1693         
1694         { }
1695 };
1696
1697 /*
1698  * Uniwill pin configuration:
1699  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
1700  * line = 0x1a
1701  */
1702 static struct hda_verb alc880_uniwill_init_verbs[] = {
1703         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1704
1705         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1706         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1707         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1708         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1709         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1710         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1711         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1712         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1713         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1714         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1715         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1716         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1717         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1718         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1719
1720         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1721         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1722         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1723         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1724         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1725         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1726         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
1727         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
1728         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1729
1730         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
1731         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
1732
1733         { }
1734 };
1735
1736 /*
1737 * Uniwill P53
1738 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19, 
1739  */
1740 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
1741         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1742
1743         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1744         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1745         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1746         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1747         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1748         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1749         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1750         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1751         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1752         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1753         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1754         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1755
1756         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1757         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1758         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1759         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1760         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1761         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1762
1763         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
1764         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
1765
1766         { }
1767 };
1768
1769 static struct hda_verb alc880_beep_init_verbs[] = {
1770         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
1771         { }
1772 };
1773
1774 /* toggle speaker-output according to the hp-jack state */
1775 static void alc880_uniwill_hp_automute(struct hda_codec *codec)
1776 {
1777         unsigned int present;
1778         unsigned char bits;
1779
1780         present = snd_hda_codec_read(codec, 0x14, 0,
1781                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1782         bits = present ? HDA_AMP_MUTE : 0;
1783         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
1784                                  HDA_AMP_MUTE, bits);
1785         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
1786                                  HDA_AMP_MUTE, bits);
1787 }
1788
1789 /* auto-toggle front mic */
1790 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
1791 {
1792         unsigned int present;
1793         unsigned char bits;
1794
1795         present = snd_hda_codec_read(codec, 0x18, 0,
1796                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1797         bits = present ? HDA_AMP_MUTE : 0;
1798         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
1799 }
1800
1801 static void alc880_uniwill_automute(struct hda_codec *codec)
1802 {
1803         alc880_uniwill_hp_automute(codec);
1804         alc880_uniwill_mic_automute(codec);
1805 }
1806
1807 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
1808                                        unsigned int res)
1809 {
1810         /* Looks like the unsol event is incompatible with the standard
1811          * definition.  4bit tag is placed at 28 bit!
1812          */
1813         switch (res >> 28) {
1814         case ALC880_HP_EVENT:
1815                 alc880_uniwill_hp_automute(codec);
1816                 break;
1817         case ALC880_MIC_EVENT:
1818                 alc880_uniwill_mic_automute(codec);
1819                 break;
1820         }
1821 }
1822
1823 static void alc880_uniwill_p53_hp_automute(struct hda_codec *codec)
1824 {
1825         unsigned int present;
1826         unsigned char bits;
1827
1828         present = snd_hda_codec_read(codec, 0x14, 0,
1829                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1830         bits = present ? HDA_AMP_MUTE : 0;
1831         snd_hda_codec_amp_stereo(codec, 0x15, HDA_INPUT, 0, HDA_AMP_MUTE, bits);
1832 }
1833
1834 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
1835 {
1836         unsigned int present;
1837         
1838         present = snd_hda_codec_read(codec, 0x21, 0,
1839                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
1840         present &= HDA_AMP_VOLMASK;
1841         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
1842                                  HDA_AMP_VOLMASK, present);
1843         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
1844                                  HDA_AMP_VOLMASK, present);
1845 }
1846
1847 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
1848                                            unsigned int res)
1849 {
1850         /* Looks like the unsol event is incompatible with the standard
1851          * definition.  4bit tag is placed at 28 bit!
1852          */
1853         if ((res >> 28) == ALC880_HP_EVENT)
1854                 alc880_uniwill_p53_hp_automute(codec);
1855         if ((res >> 28) == ALC880_DCVOL_EVENT)
1856                 alc880_uniwill_p53_dcvol_automute(codec);
1857 }
1858
1859 /* FIXME! */
1860 /*
1861  * F1734 pin configuration:
1862  * HP = 0x14, speaker-out = 0x15, mic = 0x18
1863  */
1864 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
1865         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
1866         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
1867         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
1868         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
1869
1870         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1871         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1872         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1873         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1874
1875         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1876         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1877         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1878         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1879         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1880         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1881         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1882         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1883         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1884
1885         { }
1886 };
1887
1888 /* FIXME! */
1889 /*
1890  * ASUS pin configuration:
1891  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
1892  */
1893 static struct hda_verb alc880_pin_asus_init_verbs[] = {
1894         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
1895         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
1896         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
1897         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
1898
1899         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1900         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1901         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1902         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1903         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1904         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1905         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1906         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1907
1908         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1909         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1910         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1911         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1912         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1913         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1914         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1915         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1916         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1917         
1918         { }
1919 };
1920
1921 /* Enable GPIO mask and set output */
1922 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
1923 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
1924
1925 /* Clevo m520g init */
1926 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
1927         /* headphone output */
1928         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
1929         /* line-out */
1930         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1931         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1932         /* Line-in */
1933         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1934         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1935         /* CD */
1936         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1937         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1938         /* Mic1 (rear panel) */
1939         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1940         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1941         /* Mic2 (front panel) */
1942         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1943         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1944         /* headphone */
1945         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1946         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1947         /* change to EAPD mode */
1948         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
1949         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
1950
1951         { }
1952 };
1953
1954 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
1955         /* change to EAPD mode */
1956         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
1957         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
1958
1959         /* Headphone output */
1960         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1961         /* Front output*/
1962         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1963         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1964
1965         /* Line In pin widget for input */
1966         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1967         /* CD pin widget for input */
1968         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1969         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1970         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1971
1972         /* change to EAPD mode */
1973         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
1974         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
1975
1976         { }
1977 };
1978
1979 /*
1980  * LG m1 express dual
1981  *
1982  * Pin assignment:
1983  *   Rear Line-In/Out (blue): 0x14
1984  *   Build-in Mic-In: 0x15
1985  *   Speaker-out: 0x17
1986  *   HP-Out (green): 0x1b
1987  *   Mic-In/Out (red): 0x19
1988  *   SPDIF-Out: 0x1e
1989  */
1990
1991 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
1992 static hda_nid_t alc880_lg_dac_nids[3] = {
1993         0x05, 0x02, 0x03
1994 };
1995
1996 /* seems analog CD is not working */
1997 static struct hda_input_mux alc880_lg_capture_source = {
1998         .num_items = 3,
1999         .items = {
2000                 { "Mic", 0x1 },
2001                 { "Line", 0x5 },
2002                 { "Internal Mic", 0x6 },
2003         },
2004 };
2005
2006 /* 2,4,6 channel modes */
2007 static struct hda_verb alc880_lg_ch2_init[] = {
2008         /* set line-in and mic-in to input */
2009         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2010         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2011         { }
2012 };
2013
2014 static struct hda_verb alc880_lg_ch4_init[] = {
2015         /* set line-in to out and mic-in to input */
2016         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2017         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2018         { }
2019 };
2020
2021 static struct hda_verb alc880_lg_ch6_init[] = {
2022         /* set line-in and mic-in to output */
2023         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2024         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2025         { }
2026 };
2027
2028 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
2029         { 2, alc880_lg_ch2_init },
2030         { 4, alc880_lg_ch4_init },
2031         { 6, alc880_lg_ch6_init },
2032 };
2033
2034 static struct snd_kcontrol_new alc880_lg_mixer[] = {
2035         /* FIXME: it's not really "master" but front channels */
2036         HDA_CODEC_VOLUME("Master Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2037         HDA_BIND_MUTE("Master Playback Switch", 0x0f, 2, HDA_INPUT),
2038         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2039         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
2040         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
2041         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
2042         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
2043         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
2044         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2045         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2046         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
2047         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
2048         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
2049         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
2050         {
2051                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2052                 .name = "Channel Mode",
2053                 .info = alc_ch_mode_info,
2054                 .get = alc_ch_mode_get,
2055                 .put = alc_ch_mode_put,
2056         },
2057         { } /* end */
2058 };
2059
2060 static struct hda_verb alc880_lg_init_verbs[] = {
2061         /* set capture source to mic-in */
2062         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2063         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2064         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2065         /* mute all amp mixer inputs */
2066         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
2067         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2068         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2069         /* line-in to input */
2070         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2071         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2072         /* built-in mic */
2073         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2074         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2075         /* speaker-out */
2076         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2077         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2078         /* mic-in to input */
2079         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2080         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2081         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2082         /* HP-out */
2083         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
2084         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2085         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2086         /* jack sense */
2087         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2088         { }
2089 };
2090
2091 /* toggle speaker-output according to the hp-jack state */
2092 static void alc880_lg_automute(struct hda_codec *codec)
2093 {
2094         unsigned int present;
2095         unsigned char bits;
2096
2097         present = snd_hda_codec_read(codec, 0x1b, 0,
2098                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2099         bits = present ? HDA_AMP_MUTE : 0;
2100         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
2101                                  HDA_AMP_MUTE, bits);
2102 }
2103
2104 static void alc880_lg_unsol_event(struct hda_codec *codec, unsigned int res)
2105 {
2106         /* Looks like the unsol event is incompatible with the standard
2107          * definition.  4bit tag is placed at 28 bit!
2108          */
2109         if ((res >> 28) == 0x01)
2110                 alc880_lg_automute(codec);
2111 }
2112
2113 /*
2114  * LG LW20
2115  *
2116  * Pin assignment:
2117  *   Speaker-out: 0x14
2118  *   Mic-In: 0x18
2119  *   Built-in Mic-In: 0x19
2120  *   Line-In: 0x1b
2121  *   HP-Out: 0x1a
2122  *   SPDIF-Out: 0x1e
2123  */
2124
2125 static struct hda_input_mux alc880_lg_lw_capture_source = {
2126         .num_items = 3,
2127         .items = {
2128                 { "Mic", 0x0 },
2129                 { "Internal Mic", 0x1 },
2130                 { "Line In", 0x2 },
2131         },
2132 };
2133
2134 #define alc880_lg_lw_modes alc880_threestack_modes
2135
2136 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
2137         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2138         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2139         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2140         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
2141         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2142         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2143         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2144         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2145         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2146         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2147         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2148         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2149         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
2150         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
2151         {
2152                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2153                 .name = "Channel Mode",
2154                 .info = alc_ch_mode_info,
2155                 .get = alc_ch_mode_get,
2156                 .put = alc_ch_mode_put,
2157         },
2158         { } /* end */
2159 };
2160
2161 static struct hda_verb alc880_lg_lw_init_verbs[] = {
2162         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2163         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2164         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2165
2166         /* set capture source to mic-in */
2167         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2168         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2169         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2170         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2171         /* speaker-out */
2172         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2173         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2174         /* HP-out */
2175         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2176         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2177         /* mic-in to input */
2178         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2179         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2180         /* built-in mic */
2181         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2182         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2183         /* jack sense */
2184         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2185         { }
2186 };
2187
2188 /* toggle speaker-output according to the hp-jack state */
2189 static void alc880_lg_lw_automute(struct hda_codec *codec)
2190 {
2191         unsigned int present;
2192         unsigned char bits;
2193
2194         present = snd_hda_codec_read(codec, 0x1b, 0,
2195                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2196         bits = present ? HDA_AMP_MUTE : 0;
2197         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
2198                                  HDA_AMP_MUTE, bits);
2199 }
2200
2201 static void alc880_lg_lw_unsol_event(struct hda_codec *codec, unsigned int res)
2202 {
2203         /* Looks like the unsol event is incompatible with the standard
2204          * definition.  4bit tag is placed at 28 bit!
2205          */
2206         if ((res >> 28) == 0x01)
2207                 alc880_lg_lw_automute(codec);
2208 }
2209
2210 #ifdef CONFIG_SND_HDA_POWER_SAVE
2211 static struct hda_amp_list alc880_loopbacks[] = {
2212         { 0x0b, HDA_INPUT, 0 },
2213         { 0x0b, HDA_INPUT, 1 },
2214         { 0x0b, HDA_INPUT, 2 },
2215         { 0x0b, HDA_INPUT, 3 },
2216         { 0x0b, HDA_INPUT, 4 },
2217         { } /* end */
2218 };
2219
2220 static struct hda_amp_list alc880_lg_loopbacks[] = {
2221         { 0x0b, HDA_INPUT, 1 },
2222         { 0x0b, HDA_INPUT, 6 },
2223         { 0x0b, HDA_INPUT, 7 },
2224         { } /* end */
2225 };
2226 #endif
2227
2228 /*
2229  * Common callbacks
2230  */
2231
2232 static int alc_init(struct hda_codec *codec)
2233 {
2234         struct alc_spec *spec = codec->spec;
2235         unsigned int i;
2236
2237         for (i = 0; i < spec->num_init_verbs; i++)
2238                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2239
2240         if (spec->init_hook)
2241                 spec->init_hook(codec);
2242
2243         return 0;
2244 }
2245
2246 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2247 {
2248         struct alc_spec *spec = codec->spec;
2249
2250         if (spec->unsol_event)
2251                 spec->unsol_event(codec, res);
2252 }
2253
2254 #ifdef CONFIG_SND_HDA_POWER_SAVE
2255 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2256 {
2257         struct alc_spec *spec = codec->spec;
2258         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2259 }
2260 #endif
2261
2262 /*
2263  * Analog playback callbacks
2264  */
2265 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
2266                                     struct hda_codec *codec,
2267                                     struct snd_pcm_substream *substream)
2268 {
2269         struct alc_spec *spec = codec->spec;
2270         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
2271 }
2272
2273 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2274                                        struct hda_codec *codec,
2275                                        unsigned int stream_tag,
2276                                        unsigned int format,
2277                                        struct snd_pcm_substream *substream)
2278 {
2279         struct alc_spec *spec = codec->spec;
2280         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2281                                                 stream_tag, format, substream);
2282 }
2283
2284 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2285                                        struct hda_codec *codec,
2286                                        struct snd_pcm_substream *substream)
2287 {
2288         struct alc_spec *spec = codec->spec;
2289         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2290 }
2291
2292 /*
2293  * Digital out
2294  */
2295 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2296                                         struct hda_codec *codec,
2297                                         struct snd_pcm_substream *substream)
2298 {
2299         struct alc_spec *spec = codec->spec;
2300         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2301 }
2302
2303 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2304                                            struct hda_codec *codec,
2305                                            unsigned int stream_tag,
2306                                            unsigned int format,
2307                                            struct snd_pcm_substream *substream)
2308 {
2309         struct alc_spec *spec = codec->spec;
2310         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2311                                              stream_tag, format, substream);
2312 }
2313
2314 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2315                                          struct hda_codec *codec,
2316                                          struct snd_pcm_substream *substream)
2317 {
2318         struct alc_spec *spec = codec->spec;
2319         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2320 }
2321
2322 /*
2323  * Analog capture
2324  */
2325 static int alc880_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2326                                       struct hda_codec *codec,
2327                                       unsigned int stream_tag,
2328                                       unsigned int format,
2329                                       struct snd_pcm_substream *substream)
2330 {
2331         struct alc_spec *spec = codec->spec;
2332
2333         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
2334                                    stream_tag, 0, format);
2335         return 0;
2336 }
2337
2338 static int alc880_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2339                                       struct hda_codec *codec,
2340                                       struct snd_pcm_substream *substream)
2341 {
2342         struct alc_spec *spec = codec->spec;
2343
2344         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
2345                                    0, 0, 0);
2346         return 0;
2347 }
2348
2349
2350 /*
2351  */
2352 static struct hda_pcm_stream alc880_pcm_analog_playback = {
2353         .substreams = 1,
2354         .channels_min = 2,
2355         .channels_max = 8,
2356         /* NID is set in alc_build_pcms */
2357         .ops = {
2358                 .open = alc880_playback_pcm_open,
2359                 .prepare = alc880_playback_pcm_prepare,
2360                 .cleanup = alc880_playback_pcm_cleanup
2361         },
2362 };
2363
2364 static struct hda_pcm_stream alc880_pcm_analog_capture = {
2365         .substreams = 2,
2366         .channels_min = 2,
2367         .channels_max = 2,
2368         /* NID is set in alc_build_pcms */
2369         .ops = {
2370                 .prepare = alc880_capture_pcm_prepare,
2371                 .cleanup = alc880_capture_pcm_cleanup
2372         },
2373 };
2374
2375 static struct hda_pcm_stream alc880_pcm_digital_playback = {
2376         .substreams = 1,
2377         .channels_min = 2,
2378         .channels_max = 2,
2379         /* NID is set in alc_build_pcms */
2380         .ops = {
2381                 .open = alc880_dig_playback_pcm_open,
2382                 .close = alc880_dig_playback_pcm_close,
2383                 .prepare = alc880_dig_playback_pcm_prepare
2384         },
2385 };
2386
2387 static struct hda_pcm_stream alc880_pcm_digital_capture = {
2388         .substreams = 1,
2389         .channels_min = 2,
2390         .channels_max = 2,
2391         /* NID is set in alc_build_pcms */
2392 };
2393
2394 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2395 static struct hda_pcm_stream alc_pcm_null_playback = {
2396         .substreams = 0,
2397         .channels_min = 0,
2398         .channels_max = 0,
2399 };
2400
2401 static int alc_build_pcms(struct hda_codec *codec)
2402 {
2403         struct alc_spec *spec = codec->spec;
2404         struct hda_pcm *info = spec->pcm_rec;
2405         int i;
2406
2407         codec->num_pcms = 1;
2408         codec->pcm_info = info;
2409
2410         info->name = spec->stream_name_analog;
2411         if (spec->stream_analog_playback) {
2412                 snd_assert(spec->multiout.dac_nids, return -EINVAL);
2413                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
2414                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2415         }
2416         if (spec->stream_analog_capture) {
2417                 snd_assert(spec->adc_nids, return -EINVAL);
2418                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
2419                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2420         }
2421
2422         if (spec->channel_mode) {
2423                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2424                 for (i = 0; i < spec->num_channel_mode; i++) {
2425                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2426                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2427                         }
2428                 }
2429         }
2430
2431         /* SPDIF for stream index #1 */
2432         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2433                 codec->num_pcms = 2;
2434                 info = spec->pcm_rec + 1;
2435                 info->name = spec->stream_name_digital;
2436                 if (spec->multiout.dig_out_nid &&
2437                     spec->stream_digital_playback) {
2438                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
2439                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2440                 }
2441                 if (spec->dig_in_nid &&
2442                     spec->stream_digital_capture) {
2443                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
2444                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2445                 }
2446         }
2447
2448         /* If the use of more than one ADC is requested for the current
2449          * model, configure a second analog capture-only PCM.
2450          */
2451         /* Additional Analaog capture for index #2 */
2452         if (spec->num_adc_nids > 1 && spec->stream_analog_capture &&
2453             spec->adc_nids) {
2454                 codec->num_pcms = 3;
2455                 info = spec->pcm_rec + 2;
2456                 info->name = spec->stream_name_analog;
2457                 /* No playback stream for second PCM */
2458                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = alc_pcm_null_playback;
2459                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2460                 if (spec->stream_analog_capture) {
2461                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
2462                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[1];
2463                 }
2464         }
2465
2466         return 0;
2467 }
2468
2469 static void alc_free(struct hda_codec *codec)
2470 {
2471         struct alc_spec *spec = codec->spec;
2472         unsigned int i;
2473
2474         if (!spec)
2475                 return;
2476
2477         if (spec->kctl_alloc) {
2478                 for (i = 0; i < spec->num_kctl_used; i++)
2479                         kfree(spec->kctl_alloc[i].name);
2480                 kfree(spec->kctl_alloc);
2481         }
2482         kfree(spec);
2483 }
2484
2485 /*
2486  */
2487 static struct hda_codec_ops alc_patch_ops = {
2488         .build_controls = alc_build_controls,
2489         .build_pcms = alc_build_pcms,
2490         .init = alc_init,
2491         .free = alc_free,
2492         .unsol_event = alc_unsol_event,
2493 #ifdef CONFIG_SND_HDA_POWER_SAVE
2494         .check_power_status = alc_check_power_status,
2495 #endif
2496 };
2497
2498
2499 /*
2500  * Test configuration for debugging
2501  *
2502  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
2503  * enum controls.
2504  */
2505 #ifdef CONFIG_SND_DEBUG
2506 static hda_nid_t alc880_test_dac_nids[4] = {
2507         0x02, 0x03, 0x04, 0x05
2508 };
2509
2510 static struct hda_input_mux alc880_test_capture_source = {
2511         .num_items = 7,
2512         .items = {
2513                 { "In-1", 0x0 },
2514                 { "In-2", 0x1 },
2515                 { "In-3", 0x2 },
2516                 { "In-4", 0x3 },
2517                 { "CD", 0x4 },
2518                 { "Front", 0x5 },
2519                 { "Surround", 0x6 },
2520         },
2521 };
2522
2523 static struct hda_channel_mode alc880_test_modes[4] = {
2524         { 2, NULL },
2525         { 4, NULL },
2526         { 6, NULL },
2527         { 8, NULL },
2528 };
2529
2530 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
2531                                  struct snd_ctl_elem_info *uinfo)
2532 {
2533         static char *texts[] = {
2534                 "N/A", "Line Out", "HP Out",
2535                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
2536         };
2537         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2538         uinfo->count = 1;
2539         uinfo->value.enumerated.items = 8;
2540         if (uinfo->value.enumerated.item >= 8)
2541                 uinfo->value.enumerated.item = 7;
2542         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2543         return 0;
2544 }
2545
2546 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
2547                                 struct snd_ctl_elem_value *ucontrol)
2548 {
2549         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2550         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2551         unsigned int pin_ctl, item = 0;
2552
2553         pin_ctl = snd_hda_codec_read(codec, nid, 0,
2554                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2555         if (pin_ctl & AC_PINCTL_OUT_EN) {
2556                 if (pin_ctl & AC_PINCTL_HP_EN)
2557                         item = 2;
2558                 else
2559                         item = 1;
2560         } else if (pin_ctl & AC_PINCTL_IN_EN) {
2561                 switch (pin_ctl & AC_PINCTL_VREFEN) {
2562                 case AC_PINCTL_VREF_HIZ: item = 3; break;
2563                 case AC_PINCTL_VREF_50:  item = 4; break;
2564                 case AC_PINCTL_VREF_GRD: item = 5; break;
2565                 case AC_PINCTL_VREF_80:  item = 6; break;
2566                 case AC_PINCTL_VREF_100: item = 7; break;
2567                 }
2568         }
2569         ucontrol->value.enumerated.item[0] = item;
2570         return 0;
2571 }
2572
2573 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
2574                                 struct snd_ctl_elem_value *ucontrol)
2575 {
2576         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2577         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2578         static unsigned int ctls[] = {
2579                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
2580                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
2581                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
2582                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
2583                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
2584                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
2585         };
2586         unsigned int old_ctl, new_ctl;
2587
2588         old_ctl = snd_hda_codec_read(codec, nid, 0,
2589                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2590         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
2591         if (old_ctl != new_ctl) {
2592                 int val;
2593                 snd_hda_codec_write_cache(codec, nid, 0,
2594                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
2595                                           new_ctl);
2596                 val = ucontrol->value.enumerated.item[0] >= 3 ?
2597                         HDA_AMP_MUTE : 0;
2598                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
2599                                          HDA_AMP_MUTE, val);
2600                 return 1;
2601         }
2602         return 0;
2603 }
2604
2605 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
2606                                  struct snd_ctl_elem_info *uinfo)
2607 {
2608         static char *texts[] = {
2609                 "Front", "Surround", "CLFE", "Side"
2610         };
2611         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2612         uinfo->count = 1;
2613         uinfo->value.enumerated.items = 4;
2614         if (uinfo->value.enumerated.item >= 4)
2615                 uinfo->value.enumerated.item = 3;
2616         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2617         return 0;
2618 }
2619
2620 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
2621                                 struct snd_ctl_elem_value *ucontrol)
2622 {
2623         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2624         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2625         unsigned int sel;
2626
2627         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
2628         ucontrol->value.enumerated.item[0] = sel & 3;
2629         return 0;
2630 }
2631
2632 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
2633                                 struct snd_ctl_elem_value *ucontrol)
2634 {
2635         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2636         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2637         unsigned int sel;
2638
2639         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
2640         if (ucontrol->value.enumerated.item[0] != sel) {
2641                 sel = ucontrol->value.enumerated.item[0] & 3;
2642                 snd_hda_codec_write_cache(codec, nid, 0,
2643                                           AC_VERB_SET_CONNECT_SEL, sel);
2644                 return 1;
2645         }
2646         return 0;
2647 }
2648
2649 #define PIN_CTL_TEST(xname,nid) {                       \
2650                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
2651                         .name = xname,                 \
2652                         .info = alc_test_pin_ctl_info, \
2653                         .get = alc_test_pin_ctl_get,   \
2654                         .put = alc_test_pin_ctl_put,   \
2655                         .private_value = nid           \
2656                         }
2657
2658 #define PIN_SRC_TEST(xname,nid) {                       \
2659                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
2660                         .name = xname,                 \
2661                         .info = alc_test_pin_src_info, \
2662                         .get = alc_test_pin_src_get,   \
2663                         .put = alc_test_pin_src_put,   \
2664                         .private_value = nid           \
2665                         }
2666
2667 static struct snd_kcontrol_new alc880_test_mixer[] = {
2668         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2669         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2670         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
2671         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2672         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2673         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2674         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
2675         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2676         PIN_CTL_TEST("Front Pin Mode", 0x14),
2677         PIN_CTL_TEST("Surround Pin Mode", 0x15),
2678         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
2679         PIN_CTL_TEST("Side Pin Mode", 0x17),
2680         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
2681         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
2682         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
2683         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
2684         PIN_SRC_TEST("In-1 Pin Source", 0x18),
2685         PIN_SRC_TEST("In-2 Pin Source", 0x19),
2686         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
2687         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
2688         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
2689         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
2690         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
2691         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
2692         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
2693         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
2694         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
2695         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
2696         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
2697         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
2698         {
2699                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2700                 .name = "Channel Mode",
2701                 .info = alc_ch_mode_info,
2702                 .get = alc_ch_mode_get,
2703                 .put = alc_ch_mode_put,
2704         },
2705         { } /* end */
2706 };
2707
2708 static struct hda_verb alc880_test_init_verbs[] = {
2709         /* Unmute inputs of 0x0c - 0x0f */
2710         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2711         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2712         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2713         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2714         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2715         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2716         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2717         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2718         /* Vol output for 0x0c-0x0f */
2719         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2720         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2721         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2722         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2723         /* Set output pins 0x14-0x17 */
2724         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2725         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2726         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2727         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2728         /* Unmute output pins 0x14-0x17 */
2729         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2730         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2731         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2732         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2733         /* Set input pins 0x18-0x1c */
2734         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2735         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2736         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2737         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2738         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2739         /* Mute input pins 0x18-0x1b */
2740         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2741         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2742         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2743         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2744         /* ADC set up */
2745         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2746         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2747         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2748         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2749         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2750         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2751         /* Analog input/passthru */
2752         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2753         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2754         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2755         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2756         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2757         { }
2758 };
2759 #endif
2760
2761 /*
2762  */
2763
2764 static const char *alc880_models[ALC880_MODEL_LAST] = {
2765         [ALC880_3ST]            = "3stack",
2766         [ALC880_TCL_S700]       = "tcl",
2767         [ALC880_3ST_DIG]        = "3stack-digout",
2768         [ALC880_CLEVO]          = "clevo",
2769         [ALC880_5ST]            = "5stack",
2770         [ALC880_5ST_DIG]        = "5stack-digout",
2771         [ALC880_W810]           = "w810",
2772         [ALC880_Z71V]           = "z71v",
2773         [ALC880_6ST]            = "6stack",
2774         [ALC880_6ST_DIG]        = "6stack-digout",
2775         [ALC880_ASUS]           = "asus",
2776         [ALC880_ASUS_W1V]       = "asus-w1v",
2777         [ALC880_ASUS_DIG]       = "asus-dig",
2778         [ALC880_ASUS_DIG2]      = "asus-dig2",
2779         [ALC880_UNIWILL_DIG]    = "uniwill",
2780         [ALC880_UNIWILL_P53]    = "uniwill-p53",
2781         [ALC880_FUJITSU]        = "fujitsu",
2782         [ALC880_F1734]          = "F1734",
2783         [ALC880_LG]             = "lg",
2784         [ALC880_LG_LW]          = "lg-lw",
2785 #ifdef CONFIG_SND_DEBUG
2786         [ALC880_TEST]           = "test",
2787 #endif
2788         [ALC880_AUTO]           = "auto",
2789 };
2790
2791 static struct snd_pci_quirk alc880_cfg_tbl[] = {
2792         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
2793         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
2794         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
2795         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
2796         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
2797         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
2798         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
2799         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
2800         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
2801         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
2802         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
2803         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
2804         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
2805         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
2806         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
2807         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
2808         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
2809         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
2810         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
2811         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
2812         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
2813         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS", ALC880_ASUS),
2814         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
2815         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
2816         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
2817         SND_PCI_QUIRK(0x1043, 0, "ASUS", ALC880_ASUS), /* default ASUS */
2818         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
2819         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
2820         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
2821         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
2822         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
2823         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
2824         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
2825         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
2826         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
2827         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
2828         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
2829         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
2830         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
2831         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
2832         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
2833         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
2834         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
2835         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
2836         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
2837         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
2838         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
2839         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
2840         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
2841         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
2842         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
2843         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
2844         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
2845         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
2846         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
2847         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
2848         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
2849         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
2850         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
2851         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
2852         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
2853         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
2854         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
2855         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
2856         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
2857         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
2858         SND_PCI_QUIRK(0x8086, 0, "Intel mobo", ALC880_3ST), /* default Intel */
2859         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
2860         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
2861         {}
2862 };
2863
2864 /*
2865  * ALC880 codec presets
2866  */
2867 static struct alc_config_preset alc880_presets[] = {
2868         [ALC880_3ST] = {
2869                 .mixers = { alc880_three_stack_mixer },
2870                 .init_verbs = { alc880_volume_init_verbs,
2871                                 alc880_pin_3stack_init_verbs },
2872                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2873                 .dac_nids = alc880_dac_nids,
2874                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
2875                 .channel_mode = alc880_threestack_modes,
2876                 .need_dac_fix = 1,
2877                 .input_mux = &alc880_capture_source,
2878         },
2879         [ALC880_3ST_DIG] = {
2880                 .mixers = { alc880_three_stack_mixer },
2881                 .init_verbs = { alc880_volume_init_verbs,
2882                                 alc880_pin_3stack_init_verbs },
2883                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2884                 .dac_nids = alc880_dac_nids,
2885                 .dig_out_nid = ALC880_DIGOUT_NID,
2886                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
2887                 .channel_mode = alc880_threestack_modes,
2888                 .need_dac_fix = 1,
2889                 .input_mux = &alc880_capture_source,
2890         },
2891         [ALC880_TCL_S700] = {
2892                 .mixers = { alc880_tcl_s700_mixer },
2893                 .init_verbs = { alc880_volume_init_verbs,
2894                                 alc880_pin_tcl_S700_init_verbs,
2895                                 alc880_gpio2_init_verbs },
2896                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2897                 .dac_nids = alc880_dac_nids,
2898                 .hp_nid = 0x03,
2899                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
2900                 .channel_mode = alc880_2_jack_modes,
2901                 .input_mux = &alc880_capture_source,
2902         },
2903         [ALC880_5ST] = {
2904                 .mixers = { alc880_three_stack_mixer,
2905                             alc880_five_stack_mixer},
2906                 .init_verbs = { alc880_volume_init_verbs,
2907                                 alc880_pin_5stack_init_verbs },
2908                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2909                 .dac_nids = alc880_dac_nids,
2910                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
2911                 .channel_mode = alc880_fivestack_modes,
2912                 .input_mux = &alc880_capture_source,
2913         },
2914         [ALC880_5ST_DIG] = {
2915                 .mixers = { alc880_three_stack_mixer,
2916                             alc880_five_stack_mixer },
2917                 .init_verbs = { alc880_volume_init_verbs,
2918                                 alc880_pin_5stack_init_verbs },
2919                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2920                 .dac_nids = alc880_dac_nids,
2921                 .dig_out_nid = ALC880_DIGOUT_NID,
2922                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
2923                 .channel_mode = alc880_fivestack_modes,
2924                 .input_mux = &alc880_capture_source,
2925         },
2926         [ALC880_6ST] = {
2927                 .mixers = { alc880_six_stack_mixer },
2928                 .init_verbs = { alc880_volume_init_verbs,
2929                                 alc880_pin_6stack_init_verbs },
2930                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
2931                 .dac_nids = alc880_6st_dac_nids,
2932                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
2933                 .channel_mode = alc880_sixstack_modes,
2934                 .input_mux = &alc880_6stack_capture_source,
2935         },
2936         [ALC880_6ST_DIG] = {
2937                 .mixers = { alc880_six_stack_mixer },
2938                 .init_verbs = { alc880_volume_init_verbs,
2939                                 alc880_pin_6stack_init_verbs },
2940                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
2941                 .dac_nids = alc880_6st_dac_nids,
2942                 .dig_out_nid = ALC880_DIGOUT_NID,
2943                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
2944                 .channel_mode = alc880_sixstack_modes,
2945                 .input_mux = &alc880_6stack_capture_source,
2946         },
2947         [ALC880_W810] = {
2948                 .mixers = { alc880_w810_base_mixer },
2949                 .init_verbs = { alc880_volume_init_verbs,
2950                                 alc880_pin_w810_init_verbs,
2951                                 alc880_gpio2_init_verbs },
2952                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
2953                 .dac_nids = alc880_w810_dac_nids,
2954                 .dig_out_nid = ALC880_DIGOUT_NID,
2955                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
2956                 .channel_mode = alc880_w810_modes,
2957                 .input_mux = &alc880_capture_source,
2958         },
2959         [ALC880_Z71V] = {
2960                 .mixers = { alc880_z71v_mixer },
2961                 .init_verbs = { alc880_volume_init_verbs,
2962                                 alc880_pin_z71v_init_verbs },
2963                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
2964                 .dac_nids = alc880_z71v_dac_nids,
2965                 .dig_out_nid = ALC880_DIGOUT_NID,
2966                 .hp_nid = 0x03,
2967                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
2968                 .channel_mode = alc880_2_jack_modes,
2969                 .input_mux = &alc880_capture_source,
2970         },
2971         [ALC880_F1734] = {
2972                 .mixers = { alc880_f1734_mixer },
2973                 .init_verbs = { alc880_volume_init_verbs,
2974                                 alc880_pin_f1734_init_verbs },
2975                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
2976                 .dac_nids = alc880_f1734_dac_nids,
2977                 .hp_nid = 0x02,
2978                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
2979                 .channel_mode = alc880_2_jack_modes,
2980                 .input_mux = &alc880_capture_source,
2981         },
2982         [ALC880_ASUS] = {
2983                 .mixers = { alc880_asus_mixer },
2984                 .init_verbs = { alc880_volume_init_verbs,
2985                                 alc880_pin_asus_init_verbs,
2986                                 alc880_gpio1_init_verbs },
2987                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2988                 .dac_nids = alc880_asus_dac_nids,
2989                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
2990                 .channel_mode = alc880_asus_modes,
2991                 .need_dac_fix = 1,
2992                 .input_mux = &alc880_capture_source,
2993         },
2994         [ALC880_ASUS_DIG] = {
2995                 .mixers = { alc880_asus_mixer },
2996                 .init_verbs = { alc880_volume_init_verbs,
2997                                 alc880_pin_asus_init_verbs,
2998                                 alc880_gpio1_init_verbs },
2999                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3000                 .dac_nids = alc880_asus_dac_nids,
3001                 .dig_out_nid = ALC880_DIGOUT_NID,
3002                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3003                 .channel_mode = alc880_asus_modes,
3004                 .need_dac_fix = 1,
3005                 .input_mux = &alc880_capture_source,
3006         },
3007         [ALC880_ASUS_DIG2] = {
3008                 .mixers = { alc880_asus_mixer },
3009                 .init_verbs = { alc880_volume_init_verbs,
3010                                 alc880_pin_asus_init_verbs,
3011                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
3012                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3013                 .dac_nids = alc880_asus_dac_nids,
3014                 .dig_out_nid = ALC880_DIGOUT_NID,
3015                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3016                 .channel_mode = alc880_asus_modes,
3017                 .need_dac_fix = 1,
3018                 .input_mux = &alc880_capture_source,
3019         },
3020         [ALC880_ASUS_W1V] = {
3021                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
3022                 .init_verbs = { alc880_volume_init_verbs,
3023                                 alc880_pin_asus_init_verbs,
3024                                 alc880_gpio1_init_verbs },
3025                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3026                 .dac_nids = alc880_asus_dac_nids,
3027                 .dig_out_nid = ALC880_DIGOUT_NID,
3028                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3029                 .channel_mode = alc880_asus_modes,
3030                 .need_dac_fix = 1,
3031                 .input_mux = &alc880_capture_source,
3032         },
3033         [ALC880_UNIWILL_DIG] = {
3034                 .mixers = { alc880_asus_mixer, alc880_pcbeep_mixer },
3035                 .init_verbs = { alc880_volume_init_verbs,
3036                                 alc880_pin_asus_init_verbs },
3037                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3038                 .dac_nids = alc880_asus_dac_nids,
3039                 .dig_out_nid = ALC880_DIGOUT_NID,
3040                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3041                 .channel_mode = alc880_asus_modes,
3042                 .need_dac_fix = 1,
3043                 .input_mux = &alc880_capture_source,
3044         },
3045         [ALC880_UNIWILL] = {
3046                 .mixers = { alc880_uniwill_mixer },
3047                 .init_verbs = { alc880_volume_init_verbs,
3048                                 alc880_uniwill_init_verbs },
3049                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3050                 .dac_nids = alc880_asus_dac_nids,
3051                 .dig_out_nid = ALC880_DIGOUT_NID,
3052                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3053                 .channel_mode = alc880_threestack_modes,
3054                 .need_dac_fix = 1,
3055                 .input_mux = &alc880_capture_source,
3056                 .unsol_event = alc880_uniwill_unsol_event,
3057                 .init_hook = alc880_uniwill_automute,
3058         },
3059         [ALC880_UNIWILL_P53] = {
3060                 .mixers = { alc880_uniwill_p53_mixer },
3061                 .init_verbs = { alc880_volume_init_verbs,
3062                                 alc880_uniwill_p53_init_verbs },
3063                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3064                 .dac_nids = alc880_asus_dac_nids,
3065                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3066                 .channel_mode = alc880_threestack_modes,
3067                 .input_mux = &alc880_capture_source,
3068                 .unsol_event = alc880_uniwill_p53_unsol_event,
3069                 .init_hook = alc880_uniwill_p53_hp_automute,
3070         },
3071         [ALC880_FUJITSU] = {
3072                 .mixers = { alc880_fujitsu_mixer,
3073                             alc880_pcbeep_mixer, },
3074                 .init_verbs = { alc880_volume_init_verbs,
3075                                 alc880_uniwill_p53_init_verbs,
3076                                 alc880_beep_init_verbs },
3077                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3078                 .dac_nids = alc880_dac_nids,
3079                 .dig_out_nid = ALC880_DIGOUT_NID,
3080                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3081                 .channel_mode = alc880_2_jack_modes,
3082                 .input_mux = &alc880_capture_source,
3083                 .unsol_event = alc880_uniwill_p53_unsol_event,
3084                 .init_hook = alc880_uniwill_p53_hp_automute,
3085         },
3086         [ALC880_CLEVO] = {
3087                 .mixers = { alc880_three_stack_mixer },
3088                 .init_verbs = { alc880_volume_init_verbs,
3089                                 alc880_pin_clevo_init_verbs },
3090                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3091                 .dac_nids = alc880_dac_nids,
3092                 .hp_nid = 0x03,
3093                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3094                 .channel_mode = alc880_threestack_modes,
3095                 .need_dac_fix = 1,
3096                 .input_mux = &alc880_capture_source,
3097         },
3098         [ALC880_LG] = {
3099                 .mixers = { alc880_lg_mixer },
3100                 .init_verbs = { alc880_volume_init_verbs,
3101                                 alc880_lg_init_verbs },
3102                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
3103                 .dac_nids = alc880_lg_dac_nids,
3104                 .dig_out_nid = ALC880_DIGOUT_NID,
3105                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
3106                 .channel_mode = alc880_lg_ch_modes,
3107                 .need_dac_fix = 1,
3108                 .input_mux = &alc880_lg_capture_source,
3109                 .unsol_event = alc880_lg_unsol_event,
3110                 .init_hook = alc880_lg_automute,
3111 #ifdef CONFIG_SND_HDA_POWER_SAVE
3112                 .loopbacks = alc880_lg_loopbacks,
3113 #endif
3114         },
3115         [ALC880_LG_LW] = {
3116                 .mixers = { alc880_lg_lw_mixer },
3117                 .init_verbs = { alc880_volume_init_verbs,
3118                                 alc880_lg_lw_init_verbs },
3119                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3120                 .dac_nids = alc880_dac_nids,
3121                 .dig_out_nid = ALC880_DIGOUT_NID,
3122                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
3123                 .channel_mode = alc880_lg_lw_modes,
3124                 .input_mux = &alc880_lg_lw_capture_source,
3125                 .unsol_event = alc880_lg_lw_unsol_event,
3126                 .init_hook = alc880_lg_lw_automute,
3127         },
3128 #ifdef CONFIG_SND_DEBUG
3129         [ALC880_TEST] = {
3130                 .mixers = { alc880_test_mixer },
3131                 .init_verbs = { alc880_test_init_verbs },
3132                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
3133                 .dac_nids = alc880_test_dac_nids,
3134                 .dig_out_nid = ALC880_DIGOUT_NID,
3135                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
3136                 .channel_mode = alc880_test_modes,
3137                 .input_mux = &alc880_test_capture_source,
3138         },
3139 #endif
3140 };
3141
3142 /*
3143  * Automatic parse of I/O pins from the BIOS configuration
3144  */
3145
3146 #define NUM_CONTROL_ALLOC       32
3147 #define NUM_VERB_ALLOC          32
3148
3149 enum {
3150         ALC_CTL_WIDGET_VOL,
3151         ALC_CTL_WIDGET_MUTE,
3152         ALC_CTL_BIND_MUTE,
3153 };
3154 static struct snd_kcontrol_new alc880_control_templates[] = {
3155         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
3156         HDA_CODEC_MUTE(NULL, 0, 0, 0),
3157         HDA_BIND_MUTE(NULL, 0, 0, 0),
3158 };
3159
3160 /* add dynamic controls */
3161 static int add_control(struct alc_spec *spec, int type, const char *name,
3162                        unsigned long val)
3163 {
3164         struct snd_kcontrol_new *knew;
3165
3166         if (spec->num_kctl_used >= spec->num_kctl_alloc) {
3167                 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
3168
3169                 /* array + terminator */
3170                 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL);
3171                 if (!knew)
3172                         return -ENOMEM;
3173                 if (spec->kctl_alloc) {
3174                         memcpy(knew, spec->kctl_alloc,
3175                                sizeof(*knew) * spec->num_kctl_alloc);
3176                         kfree(spec->kctl_alloc);
3177                 }
3178                 spec->kctl_alloc = knew;
3179                 spec->num_kctl_alloc = num;
3180         }
3181
3182         knew = &spec->kctl_alloc[spec->num_kctl_used];
3183         *knew = alc880_control_templates[type];
3184         knew->name = kstrdup(name, GFP_KERNEL);
3185         if (!knew->name)
3186                 return -ENOMEM;
3187         knew->private_value = val;
3188         spec->num_kctl_used++;
3189         return 0;
3190 }
3191
3192 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
3193 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
3194 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
3195 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
3196 #define alc880_is_input_pin(nid)        ((nid) >= 0x18)
3197 #define alc880_input_pin_idx(nid)       ((nid) - 0x18)
3198 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
3199 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
3200 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
3201 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
3202 #define ALC880_PIN_CD_NID               0x1c
3203
3204 /* fill in the dac_nids table from the parsed pin configuration */
3205 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
3206                                      const struct auto_pin_cfg *cfg)
3207 {
3208         hda_nid_t nid;
3209         int assigned[4];
3210         int i, j;
3211
3212         memset(assigned, 0, sizeof(assigned));
3213         spec->multiout.dac_nids = spec->private_dac_nids;
3214
3215         /* check the pins hardwired to audio widget */
3216         for (i = 0; i < cfg->line_outs; i++) {
3217                 nid = cfg->line_out_pins[i];
3218                 if (alc880_is_fixed_pin(nid)) {
3219                         int idx = alc880_fixed_pin_idx(nid);
3220                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
3221                         assigned[idx] = 1;
3222                 }
3223         }
3224         /* left pins can be connect to any audio widget */
3225         for (i = 0; i < cfg->line_outs; i++) {
3226                 nid = cfg->line_out_pins[i];
3227                 if (alc880_is_fixed_pin(nid))
3228                         continue;
3229                 /* search for an empty channel */
3230                 for (j = 0; j < cfg->line_outs; j++) {
3231                         if (!assigned[j]) {
3232                                 spec->multiout.dac_nids[i] =
3233                                         alc880_idx_to_dac(j);
3234                                 assigned[j] = 1;
3235                                 break;
3236                         }
3237                 }
3238         }
3239         spec->multiout.num_dacs = cfg->line_outs;
3240         return 0;
3241 }
3242
3243 /* add playback controls from the parsed DAC table */
3244 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
3245                                              const struct auto_pin_cfg *cfg)
3246 {
3247         char name[32];
3248         static const char *chname[4] = {
3249                 "Front", "Surround", NULL /*CLFE*/, "Side"
3250         };
3251         hda_nid_t nid;
3252         int i, err;
3253
3254         for (i = 0; i < cfg->line_outs; i++) {
3255                 if (!spec->multiout.dac_nids[i])
3256                         continue;
3257                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
3258                 if (i == 2) {
3259                         /* Center/LFE */
3260                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3261                                           "Center Playback Volume",
3262                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
3263                                                               HDA_OUTPUT));
3264                         if (err < 0)
3265                                 return err;
3266                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3267                                           "LFE Playback Volume",
3268                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
3269                                                               HDA_OUTPUT));
3270                         if (err < 0)
3271                                 return err;
3272                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3273                                           "Center Playback Switch",
3274                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
3275                                                               HDA_INPUT));
3276                         if (err < 0)
3277                                 return err;
3278                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3279                                           "LFE Playback Switch",
3280                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
3281                                                               HDA_INPUT));
3282                         if (err < 0)
3283                                 return err;
3284                 } else {
3285                         sprintf(name, "%s Playback Volume", chname[i]);
3286                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3287                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3288                                                               HDA_OUTPUT));
3289                         if (err < 0)
3290                                 return err;
3291                         sprintf(name, "%s Playback Switch", chname[i]);
3292                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3293                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
3294                                                               HDA_INPUT));
3295                         if (err < 0)
3296                                 return err;
3297                 }
3298         }
3299         return 0;
3300 }
3301
3302 /* add playback controls for speaker and HP outputs */
3303 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
3304                                         const char *pfx)
3305 {
3306         hda_nid_t nid;
3307         int err;
3308         char name[32];
3309
3310         if (!pin)
3311                 return 0;
3312
3313         if (alc880_is_fixed_pin(pin)) {
3314                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
3315                 /* specify the DAC as the extra output */
3316                 if (!spec->multiout.hp_nid)
3317                         spec->multiout.hp_nid = nid;
3318                 else
3319                         spec->multiout.extra_out_nid[0] = nid;
3320                 /* control HP volume/switch on the output mixer amp */
3321                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
3322                 sprintf(name, "%s Playback Volume", pfx);
3323                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3324                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3325                 if (err < 0)
3326                         return err;
3327                 sprintf(name, "%s Playback Switch", pfx);
3328                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3329                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
3330                 if (err < 0)
3331                         return err;
3332         } else if (alc880_is_multi_pin(pin)) {
3333                 /* set manual connection */
3334                 /* we have only a switch on HP-out PIN */
3335                 sprintf(name, "%s Playback Switch", pfx);
3336                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3337                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3338                 if (err < 0)
3339                         return err;
3340         }
3341         return 0;
3342 }
3343
3344 /* create input playback/capture controls for the given pin */
3345 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
3346                             const char *ctlname,
3347                             int idx, hda_nid_t mix_nid)
3348 {
3349         char name[32];
3350         int err;
3351
3352         sprintf(name, "%s Playback Volume", ctlname);
3353         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3354                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3355         if (err < 0)
3356                 return err;
3357         sprintf(name, "%s Playback Switch", ctlname);
3358         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3359                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3360         if (err < 0)
3361                 return err;
3362         return 0;
3363 }
3364
3365 /* create playback/capture controls for input pins */
3366 static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
3367                                                 const struct auto_pin_cfg *cfg)
3368 {
3369         struct hda_input_mux *imux = &spec->private_imux;
3370         int i, err, idx;
3371
3372         for (i = 0; i < AUTO_PIN_LAST; i++) {
3373                 if (alc880_is_input_pin(cfg->input_pins[i])) {
3374                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
3375                         err = new_analog_input(spec, cfg->input_pins[i],
3376                                                auto_pin_cfg_labels[i],
3377                                                idx, 0x0b);
3378                         if (err < 0)
3379                                 return err;
3380                         imux->items[imux->num_items].label =
3381                                 auto_pin_cfg_labels[i];
3382                         imux->items[imux->num_items].index =
3383                                 alc880_input_pin_idx(cfg->input_pins[i]);
3384                         imux->num_items++;
3385                 }
3386         }
3387         return 0;
3388 }
3389
3390 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
3391                                               hda_nid_t nid, int pin_type,
3392                                               int dac_idx)
3393 {
3394         /* set as output */
3395         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3396                             pin_type);
3397         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3398                             AMP_OUT_UNMUTE);
3399         /* need the manual connection? */
3400         if (alc880_is_multi_pin(nid)) {
3401                 struct alc_spec *spec = codec->spec;
3402                 int idx = alc880_multi_pin_idx(nid);
3403                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
3404                                     AC_VERB_SET_CONNECT_SEL,
3405                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
3406         }
3407 }
3408
3409 static int get_pin_type(int line_out_type)
3410 {
3411         if (line_out_type == AUTO_PIN_HP_OUT)
3412                 return PIN_HP;
3413         else
3414                 return PIN_OUT;
3415 }
3416
3417 static void alc880_auto_init_multi_out(struct hda_codec *codec)
3418 {
3419         struct alc_spec *spec = codec->spec;
3420         int i;
3421         
3422         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
3423         for (i = 0; i < spec->autocfg.line_outs; i++) {
3424                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3425                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3426                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
3427         }
3428 }
3429
3430 static void alc880_auto_init_extra_out(struct hda_codec *codec)
3431 {
3432         struct alc_spec *spec = codec->spec;
3433         hda_nid_t pin;
3434
3435         pin = spec->autocfg.speaker_pins[0];
3436         if (pin) /* connect to front */
3437                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
3438         pin = spec->autocfg.hp_pins[0];
3439         if (pin) /* connect to front */
3440                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
3441 }
3442
3443 static void alc880_auto_init_analog_input(struct hda_codec *codec)
3444 {
3445         struct alc_spec *spec = codec->spec;
3446         int i;
3447
3448         for (i = 0; i < AUTO_PIN_LAST; i++) {
3449                 hda_nid_t nid = spec->autocfg.input_pins[i];
3450                 if (alc880_is_input_pin(nid)) {
3451                         snd_hda_codec_write(codec, nid, 0,
3452                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
3453                                             i <= AUTO_PIN_FRONT_MIC ?
3454                                             PIN_VREF80 : PIN_IN);
3455                         if (nid != ALC880_PIN_CD_NID)
3456                                 snd_hda_codec_write(codec, nid, 0,
3457                                                     AC_VERB_SET_AMP_GAIN_MUTE,
3458                                                     AMP_OUT_MUTE);
3459                 }
3460         }
3461 }
3462
3463 /* parse the BIOS configuration and set up the alc_spec */
3464 /* return 1 if successful, 0 if the proper config is not found,
3465  * or a negative error code
3466  */
3467 static int alc880_parse_auto_config(struct hda_codec *codec)
3468 {
3469         struct alc_spec *spec = codec->spec;
3470         int err;
3471         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
3472
3473         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
3474                                            alc880_ignore);
3475         if (err < 0)
3476                 return err;
3477         if (!spec->autocfg.line_outs)
3478                 return 0; /* can't find valid BIOS pin config */
3479
3480         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
3481         if (err < 0)
3482                 return err;
3483         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
3484         if (err < 0)
3485                 return err;
3486         err = alc880_auto_create_extra_out(spec,
3487                                            spec->autocfg.speaker_pins[0],
3488                                            "Speaker");
3489         if (err < 0)
3490                 return err;
3491         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
3492                                            "Headphone");
3493         if (err < 0)
3494                 return err;
3495         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
3496         if (err < 0)
3497                 return err;
3498
3499         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3500
3501         if (spec->autocfg.dig_out_pin)
3502                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
3503         if (spec->autocfg.dig_in_pin)
3504                 spec->dig_in_nid = ALC880_DIGIN_NID;
3505
3506         if (spec->kctl_alloc)
3507                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
3508
3509         spec->init_verbs[spec->num_init_verbs++] = alc880_volume_init_verbs;
3510
3511         spec->num_mux_defs = 1;
3512         spec->input_mux = &spec->private_imux;
3513
3514         return 1;
3515 }
3516
3517 /* additional initialization for auto-configuration model */
3518 static void alc880_auto_init(struct hda_codec *codec)
3519 {
3520         alc880_auto_init_multi_out(codec);
3521         alc880_auto_init_extra_out(codec);
3522         alc880_auto_init_analog_input(codec);
3523 }
3524
3525 /*
3526  * OK, here we have finally the patch for ALC880
3527  */
3528
3529 static int patch_alc880(struct hda_codec *codec)
3530 {
3531         struct alc_spec *spec;
3532         int board_config;
3533         int err;
3534
3535         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3536         if (spec == NULL)
3537                 return -ENOMEM;
3538
3539         codec->spec = spec;
3540
3541         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
3542                                                   alc880_models,
3543                                                   alc880_cfg_tbl);
3544         if (board_config < 0) {
3545                 printk(KERN_INFO "hda_codec: Unknown model for ALC880, "
3546                        "trying auto-probe from BIOS...\n");
3547                 board_config = ALC880_AUTO;
3548         }
3549
3550         if (board_config == ALC880_AUTO) {
3551                 /* automatic parse from the BIOS config */
3552                 err = alc880_parse_auto_config(codec);
3553                 if (err < 0) {
3554                         alc_free(codec);
3555                         return err;
3556                 } else if (!err) {
3557                         printk(KERN_INFO
3558                                "hda_codec: Cannot set up configuration "
3559                                "from BIOS.  Using 3-stack mode...\n");
3560                         board_config = ALC880_3ST;
3561                 }
3562         }
3563
3564         if (board_config != ALC880_AUTO)
3565                 setup_preset(spec, &alc880_presets[board_config]);
3566
3567         spec->stream_name_analog = "ALC880 Analog";
3568         spec->stream_analog_playback = &alc880_pcm_analog_playback;
3569         spec->stream_analog_capture = &alc880_pcm_analog_capture;
3570
3571         spec->stream_name_digital = "ALC880 Digital";
3572         spec->stream_digital_playback = &alc880_pcm_digital_playback;
3573         spec->stream_digital_capture = &alc880_pcm_digital_capture;
3574
3575         if (!spec->adc_nids && spec->input_mux) {
3576                 /* check whether NID 0x07 is valid */
3577                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
3578                 /* get type */
3579                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
3580                 if (wcap != AC_WID_AUD_IN) {
3581                         spec->adc_nids = alc880_adc_nids_alt;
3582                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
3583                         spec->mixers[spec->num_mixers] =
3584                                 alc880_capture_alt_mixer;
3585                         spec->num_mixers++;
3586                 } else {
3587                         spec->adc_nids = alc880_adc_nids;
3588                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
3589                         spec->mixers[spec->num_mixers] = alc880_capture_mixer;
3590                         spec->num_mixers++;
3591                 }
3592         }
3593
3594         codec->patch_ops = alc_patch_ops;
3595         if (board_config == ALC880_AUTO)
3596                 spec->init_hook = alc880_auto_init;
3597 #ifdef CONFIG_SND_HDA_POWER_SAVE
3598         if (!spec->loopback.amplist)
3599                 spec->loopback.amplist = alc880_loopbacks;
3600 #endif
3601
3602         return 0;
3603 }
3604
3605
3606 /*
3607  * ALC260 support
3608  */
3609
3610 static hda_nid_t alc260_dac_nids[1] = {
3611         /* front */
3612         0x02,
3613 };
3614
3615 static hda_nid_t alc260_adc_nids[1] = {
3616         /* ADC0 */
3617         0x04,
3618 };
3619
3620 static hda_nid_t alc260_adc_nids_alt[1] = {
3621         /* ADC1 */
3622         0x05,
3623 };
3624
3625 static hda_nid_t alc260_hp_adc_nids[2] = {
3626         /* ADC1, 0 */
3627         0x05, 0x04
3628 };
3629
3630 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
3631  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
3632  */
3633 static hda_nid_t alc260_dual_adc_nids[2] = {
3634         /* ADC0, ADC1 */
3635         0x04, 0x05
3636 };
3637
3638 #define ALC260_DIGOUT_NID       0x03
3639 #define ALC260_DIGIN_NID        0x06
3640
3641 static struct hda_input_mux alc260_capture_source = {
3642         .num_items = 4,
3643         .items = {
3644                 { "Mic", 0x0 },
3645                 { "Front Mic", 0x1 },
3646                 { "Line", 0x2 },
3647                 { "CD", 0x4 },
3648         },
3649 };
3650
3651 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
3652  * headphone jack and the internal CD lines since these are the only pins at
3653  * which audio can appear.  For flexibility, also allow the option of
3654  * recording the mixer output on the second ADC (ADC0 doesn't have a
3655  * connection to the mixer output).
3656  */
3657 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
3658         {
3659                 .num_items = 3,
3660                 .items = {
3661                         { "Mic/Line", 0x0 },
3662                         { "CD", 0x4 },
3663                         { "Headphone", 0x2 },
3664                 },
3665         },
3666         {
3667                 .num_items = 4,
3668                 .items = {
3669                         { "Mic/Line", 0x0 },
3670                         { "CD", 0x4 },
3671                         { "Headphone", 0x2 },
3672                         { "Mixer", 0x5 },
3673                 },
3674         },
3675
3676 };
3677
3678 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
3679  * the Fujitsu S702x, but jacks are marked differently.
3680  */
3681 static struct hda_input_mux alc260_acer_capture_sources[2] = {
3682         {
3683                 .num_items = 4,
3684                 .items = {
3685                         { "Mic", 0x0 },
3686                         { "Line", 0x2 },
3687                         { "CD", 0x4 },
3688                         { "Headphone", 0x5 },
3689                 },
3690         },
3691         {
3692                 .num_items = 5,
3693                 .items = {
3694                         { "Mic", 0x0 },
3695                         { "Line", 0x2 },
3696                         { "CD", 0x4 },
3697                         { "Headphone", 0x6 },
3698                         { "Mixer", 0x5 },
3699                 },
3700         },
3701 };
3702 /*
3703  * This is just place-holder, so there's something for alc_build_pcms to look
3704  * at when it calculates the maximum number of channels. ALC260 has no mixer
3705  * element which allows changing the channel mode, so the verb list is
3706  * never used.
3707  */
3708 static struct hda_channel_mode alc260_modes[1] = {
3709         { 2, NULL },
3710 };
3711
3712
3713 /* Mixer combinations
3714  *
3715  * basic: base_output + input + pc_beep + capture
3716  * HP: base_output + input + capture_alt
3717  * HP_3013: hp_3013 + input + capture
3718  * fujitsu: fujitsu + capture
3719  * acer: acer + capture
3720  */
3721
3722 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
3723         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3724         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
3725         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
3726         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
3727         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
3728         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
3729         { } /* end */
3730 };
3731
3732 static struct snd_kcontrol_new alc260_input_mixer[] = {
3733         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3734         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3735         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
3736         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
3737         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
3738         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
3739         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
3740         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
3741         { } /* end */
3742 };
3743
3744 static struct snd_kcontrol_new alc260_pc_beep_mixer[] = {
3745         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT),
3746         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT),
3747         { } /* end */
3748 };
3749
3750 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
3751         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
3752         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
3753         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
3754         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
3755         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3756         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
3757         HDA_CODEC_VOLUME_MONO("iSpeaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
3758         HDA_CODEC_MUTE_MONO("iSpeaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
3759         { } /* end */
3760 };
3761
3762 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12, 
3763  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
3764  */
3765 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
3766         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3767         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
3768         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
3769         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3770         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3771         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
3772         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
3773         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
3774         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
3775         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
3776         HDA_CODEC_VOLUME("Internal Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
3777         HDA_BIND_MUTE("Internal Speaker Playback Switch", 0x09, 2, HDA_INPUT),
3778         { } /* end */
3779 };
3780
3781 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
3782  * versions of the ALC260 don't act on requests to enable mic bias from NID
3783  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
3784  * datasheet doesn't mention this restriction.  At this stage it's not clear
3785  * whether this behaviour is intentional or is a hardware bug in chip
3786  * revisions available in early 2006.  Therefore for now allow the
3787  * "Headphone Jack Mode" control to span all choices, but if it turns out
3788  * that the lack of mic bias for this NID is intentional we could change the
3789  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
3790  *
3791  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
3792  * don't appear to make the mic bias available from the "line" jack, even
3793  * though the NID used for this jack (0x14) can supply it.  The theory is
3794  * that perhaps Acer have included blocking capacitors between the ALC260
3795  * and the output jack.  If this turns out to be the case for all such
3796  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
3797  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
3798  *
3799  * The C20x Tablet series have a mono internal speaker which is controlled
3800  * via the chip's Mono sum widget and pin complex, so include the necessary
3801  * controls for such models.  On models without a "mono speaker" the control
3802  * won't do anything.
3803  */
3804 static struct snd_kcontrol_new alc260_acer_mixer[] = {
3805         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3806         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
3807         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
3808         HDA_CODEC_VOLUME_MONO("Mono Speaker Playback Volume", 0x0a, 1, 0x0,
3809                               HDA_OUTPUT),
3810         HDA_BIND_MUTE_MONO("Mono Speaker Playback Switch", 0x0a, 1, 2,
3811                            HDA_INPUT),
3812         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3813         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3814         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
3815         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
3816         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
3817         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
3818         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
3819         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
3820         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
3821         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
3822         { } /* end */
3823 };
3824
3825 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
3826  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
3827  */
3828 static struct snd_kcontrol_new alc260_will_mixer[] = {
3829         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3830         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
3831         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
3832         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
3833         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
3834         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
3835         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
3836         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
3837         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3838         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3839         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
3840         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
3841         { } /* end */
3842 };
3843
3844 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
3845  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
3846  */
3847 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
3848         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3849         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
3850         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
3851         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
3852         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
3853         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
3854         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
3855         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
3856         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
3857         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
3858         { } /* end */
3859 };
3860
3861 /* capture mixer elements */
3862 static struct snd_kcontrol_new alc260_capture_mixer[] = {
3863         HDA_CODEC_VOLUME("Capture Volume", 0x04, 0x0, HDA_INPUT),
3864         HDA_CODEC_MUTE("Capture Switch", 0x04, 0x0, HDA_INPUT),
3865         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x05, 0x0, HDA_INPUT),
3866         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x05, 0x0, HDA_INPUT),
3867         {
3868                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3869                 /* The multiple "Capture Source" controls confuse alsamixer
3870                  * So call somewhat different..
3871                  * FIXME: the controls appear in the "playback" view!
3872                  */
3873                 /* .name = "Capture Source", */
3874                 .name = "Input Source",
3875                 .count = 2,
3876                 .info = alc_mux_enum_info,
3877                 .get = alc_mux_enum_get,
3878                 .put = alc_mux_enum_put,
3879         },
3880         { } /* end */
3881 };
3882
3883 static struct snd_kcontrol_new alc260_capture_alt_mixer[] = {
3884         HDA_CODEC_VOLUME("Capture Volume", 0x05, 0x0, HDA_INPUT),
3885         HDA_CODEC_MUTE("Capture Switch", 0x05, 0x0, HDA_INPUT),
3886         {
3887                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3888                 /* The multiple "Capture Source" controls confuse alsamixer
3889                  * So call somewhat different..
3890                  * FIXME: the controls appear in the "playback" view!
3891                  */
3892                 /* .name = "Capture Source", */
3893                 .name = "Input Source",
3894                 .count = 1,
3895                 .info = alc_mux_enum_info,
3896                 .get = alc_mux_enum_get,
3897                 .put = alc_mux_enum_put,
3898         },
3899         { } /* end */
3900 };
3901
3902 /*
3903  * initialization verbs
3904  */
3905 static struct hda_verb alc260_init_verbs[] = {
3906         /* Line In pin widget for input */
3907         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3908         /* CD pin widget for input */
3909         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3910         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3911         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3912         /* Mic2 (front panel) pin widget for input and vref at 80% */
3913         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3914         /* LINE-2 is used for line-out in rear */
3915         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3916         /* select line-out */
3917         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
3918         /* LINE-OUT pin */
3919         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3920         /* enable HP */
3921         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3922         /* enable Mono */
3923         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3924         /* mute capture amp left and right */
3925         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3926         /* set connection select to line in (default select for this ADC) */
3927         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
3928         /* mute capture amp left and right */
3929         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3930         /* set connection select to line in (default select for this ADC) */
3931         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
3932         /* set vol=0 Line-Out mixer amp left and right */
3933         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3934         /* unmute pin widget amp left and right (no gain on this amp) */
3935         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3936         /* set vol=0 HP mixer amp left and right */
3937         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3938         /* unmute pin widget amp left and right (no gain on this amp) */
3939         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3940         /* set vol=0 Mono mixer amp left and right */
3941         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3942         /* unmute pin widget amp left and right (no gain on this amp) */
3943         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3944         /* unmute LINE-2 out pin */
3945         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3946         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
3947          * Line In 2 = 0x03
3948          */
3949         /* mute analog inputs */
3950         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3951         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3952         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3953         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3954         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3955         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
3956         /* mute Front out path */
3957         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3958         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3959         /* mute Headphone out path */
3960         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3961         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3962         /* mute Mono out path */
3963         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3964         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3965         { }
3966 };
3967
3968 #if 0 /* should be identical with alc260_init_verbs? */
3969 static struct hda_verb alc260_hp_init_verbs[] = {
3970         /* Headphone and output */
3971         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
3972         /* mono output */
3973         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3974         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3975         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
3976         /* Mic2 (front panel) pin widget for input and vref at 80% */
3977         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
3978         /* Line In pin widget for input */
3979         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3980         /* Line-2 pin widget for output */
3981         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3982         /* CD pin widget for input */
3983         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3984         /* unmute amp left and right */
3985         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
3986         /* set connection select to line in (default select for this ADC) */
3987         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
3988         /* unmute Line-Out mixer amp left and right (volume = 0) */
3989         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
3990         /* mute pin widget amp left and right (no gain on this amp) */
3991         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
3992         /* unmute HP mixer amp left and right (volume = 0) */
3993         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
3994         /* mute pin widget amp left and right (no gain on this amp) */
3995         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
3996         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
3997          * Line In 2 = 0x03
3998          */
3999         /* mute analog inputs */
4000         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4001         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4002         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4003         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4004         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4005         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4006         /* Unmute Front out path */
4007         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4008         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4009         /* Unmute Headphone out path */
4010         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4011         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4012         /* Unmute Mono out path */
4013         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4014         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4015         { }
4016 };
4017 #endif
4018
4019 static struct hda_verb alc260_hp_3013_init_verbs[] = {
4020         /* Line out and output */
4021         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4022         /* mono output */
4023         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4024         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4025         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4026         /* Mic2 (front panel) pin widget for input and vref at 80% */
4027         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4028         /* Line In pin widget for input */
4029         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4030         /* Headphone pin widget for output */
4031         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4032         /* CD pin widget for input */
4033         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4034         /* unmute amp left and right */
4035         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4036         /* set connection select to line in (default select for this ADC) */
4037         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4038         /* unmute Line-Out mixer amp left and right (volume = 0) */
4039         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4040         /* mute pin widget amp left and right (no gain on this amp) */
4041         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4042         /* unmute HP mixer amp left and right (volume = 0) */
4043         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4044         /* mute pin widget amp left and right (no gain on this amp) */
4045         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4046         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4047          * Line In 2 = 0x03
4048          */
4049         /* mute analog inputs */
4050         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4051         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4052         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4053         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4054         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4055         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4056         /* Unmute Front out path */
4057         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4058         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4059         /* Unmute Headphone out path */
4060         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4061         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4062         /* Unmute Mono out path */
4063         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4064         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4065         { }
4066 };
4067
4068 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
4069  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
4070  * audio = 0x16, internal speaker = 0x10.
4071  */
4072 static struct hda_verb alc260_fujitsu_init_verbs[] = {
4073         /* Disable all GPIOs */
4074         {0x01, AC_VERB_SET_GPIO_MASK, 0},
4075         /* Internal speaker is connected to headphone pin */
4076         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4077         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
4078         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4079         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
4080         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4081         /* Ensure all other unused pins are disabled and muted. */
4082         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4083         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4084         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4085         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4086         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4087         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4088         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4089         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4090
4091         /* Disable digital (SPDIF) pins */
4092         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4093         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4094
4095         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus 
4096          * when acting as an output.
4097          */
4098         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4099
4100         /* Start with output sum widgets muted and their output gains at min */
4101         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4102         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4103         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4104         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4105         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4106         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4107         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4108         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4109         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4110
4111         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
4112         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4113         /* Unmute Line1 pin widget output buffer since it starts as an output.
4114          * If the pin mode is changed by the user the pin mode control will
4115          * take care of enabling the pin's input/output buffers as needed.
4116          * Therefore there's no need to enable the input buffer at this
4117          * stage.
4118          */
4119         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4120         /* Unmute input buffer of pin widget used for Line-in (no equiv 
4121          * mixer ctrl)
4122          */
4123         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4124
4125         /* Mute capture amp left and right */
4126         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4127         /* Set ADC connection select to match default mixer setting - line 
4128          * in (on mic1 pin)
4129          */
4130         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4131
4132         /* Do the same for the second ADC: mute capture input amp and
4133          * set ADC connection to line in (on mic1 pin)
4134          */
4135         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4136         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4137
4138         /* Mute all inputs to mixer widget (even unconnected ones) */
4139         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4140         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4141         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4142         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4143         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4144         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4145         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4146         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4147
4148         { }
4149 };
4150
4151 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
4152  * similar laptops (adapted from Fujitsu init verbs).
4153  */
4154 static struct hda_verb alc260_acer_init_verbs[] = {
4155         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
4156          * the headphone jack.  Turn this on and rely on the standard mute
4157          * methods whenever the user wants to turn these outputs off.
4158          */
4159         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
4160         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4161         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
4162         /* Internal speaker/Headphone jack is connected to Line-out pin */
4163         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4164         /* Internal microphone/Mic jack is connected to Mic1 pin */
4165         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
4166         /* Line In jack is connected to Line1 pin */
4167         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4168         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
4169         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4170         /* Ensure all other unused pins are disabled and muted. */
4171         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4172         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4173         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4174         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4175         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4176         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4177         /* Disable digital (SPDIF) pins */
4178         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4179         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4180
4181         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum 
4182          * bus when acting as outputs.
4183          */
4184         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
4185         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4186
4187         /* Start with output sum widgets muted and their output gains at min */
4188         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4189         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4190         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4191         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4192         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4193         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4194         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4195         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4196         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4197
4198         /* Unmute Line-out pin widget amp left and right
4199          * (no equiv mixer ctrl)
4200          */
4201         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4202         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
4203         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4204         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
4205          * inputs. If the pin mode is changed by the user the pin mode control
4206          * will take care of enabling the pin's input/output buffers as needed.
4207          * Therefore there's no need to enable the input buffer at this
4208          * stage.
4209          */
4210         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4211         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4212
4213         /* Mute capture amp left and right */
4214         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4215         /* Set ADC connection select to match default mixer setting - mic
4216          * (on mic1 pin)
4217          */
4218         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4219
4220         /* Do similar with the second ADC: mute capture input amp and
4221          * set ADC connection to mic to match ALSA's default state.
4222          */
4223         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4224         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4225
4226         /* Mute all inputs to mixer widget (even unconnected ones) */
4227         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4228         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4229         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4230         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4231         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4232         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4233         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4234         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4235
4236         { }
4237 };
4238
4239 static struct hda_verb alc260_will_verbs[] = {
4240         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4241         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
4242         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
4243         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4244         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
4245         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
4246         {}
4247 };
4248
4249 static struct hda_verb alc260_replacer_672v_verbs[] = {
4250         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4251         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
4252         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
4253
4254         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
4255         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4256         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4257
4258         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4259         {}
4260 };
4261
4262 /* toggle speaker-output according to the hp-jack state */
4263 static void alc260_replacer_672v_automute(struct hda_codec *codec)
4264 {
4265         unsigned int present;
4266
4267         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
4268         present = snd_hda_codec_read(codec, 0x0f, 0,
4269                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
4270         if (present) {
4271                 snd_hda_codec_write_cache(codec, 0x01, 0,
4272                                           AC_VERB_SET_GPIO_DATA, 1);
4273                 snd_hda_codec_write_cache(codec, 0x0f, 0,
4274                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4275                                           PIN_HP);
4276         } else {
4277                 snd_hda_codec_write_cache(codec, 0x01, 0,
4278                                           AC_VERB_SET_GPIO_DATA, 0);
4279                 snd_hda_codec_write_cache(codec, 0x0f, 0,
4280                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4281                                           PIN_OUT);
4282         }
4283 }
4284
4285 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
4286                                        unsigned int res)
4287 {
4288         if ((res >> 26) == ALC880_HP_EVENT)
4289                 alc260_replacer_672v_automute(codec);
4290 }
4291
4292 /* Test configuration for debugging, modelled after the ALC880 test
4293  * configuration.
4294  */
4295 #ifdef CONFIG_SND_DEBUG
4296 static hda_nid_t alc260_test_dac_nids[1] = {
4297         0x02,
4298 };
4299 static hda_nid_t alc260_test_adc_nids[2] = {
4300         0x04, 0x05,
4301 };
4302 /* For testing the ALC260, each input MUX needs its own definition since
4303  * the signal assignments are different.  This assumes that the first ADC 
4304  * is NID 0x04.
4305  */
4306 static struct hda_input_mux alc260_test_capture_sources[2] = {
4307         {
4308                 .num_items = 7,
4309                 .items = {
4310                         { "MIC1 pin", 0x0 },
4311                         { "MIC2 pin", 0x1 },
4312                         { "LINE1 pin", 0x2 },
4313                         { "LINE2 pin", 0x3 },
4314                         { "CD pin", 0x4 },
4315                         { "LINE-OUT pin", 0x5 },
4316                         { "HP-OUT pin", 0x6 },
4317                 },
4318         },
4319         {
4320                 .num_items = 8,
4321                 .items = {
4322                         { "MIC1 pin", 0x0 },
4323                         { "MIC2 pin", 0x1 },
4324                         { "LINE1 pin", 0x2 },
4325                         { "LINE2 pin", 0x3 },
4326                         { "CD pin", 0x4 },
4327                         { "Mixer", 0x5 },
4328                         { "LINE-OUT pin", 0x6 },
4329                         { "HP-OUT pin", 0x7 },
4330                 },
4331         },
4332 };
4333 static struct snd_kcontrol_new alc260_test_mixer[] = {
4334         /* Output driver widgets */
4335         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4336         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4337         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4338         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
4339         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4340         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
4341
4342         /* Modes for retasking pin widgets
4343          * Note: the ALC260 doesn't seem to act on requests to enable mic
4344          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
4345          * mention this restriction.  At this stage it's not clear whether
4346          * this behaviour is intentional or is a hardware bug in chip
4347          * revisions available at least up until early 2006.  Therefore for
4348          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
4349          * choices, but if it turns out that the lack of mic bias for these
4350          * NIDs is intentional we could change their modes from
4351          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4352          */
4353         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
4354         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
4355         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
4356         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
4357         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
4358         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
4359
4360         /* Loopback mixer controls */
4361         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
4362         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
4363         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
4364         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
4365         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
4366         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
4367         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
4368         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
4369         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4370         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4371         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4372         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4373         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
4374         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
4375         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
4376         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
4377
4378         /* Controls for GPIO pins, assuming they are configured as outputs */
4379         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
4380         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
4381         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
4382         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
4383
4384         /* Switches to allow the digital IO pins to be enabled.  The datasheet
4385          * is ambigious as to which NID is which; testing on laptops which
4386          * make this output available should provide clarification. 
4387          */
4388         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
4389         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
4390
4391         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
4392          * this output to turn on an external amplifier.
4393          */
4394         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
4395         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
4396
4397         { } /* end */
4398 };
4399 static struct hda_verb alc260_test_init_verbs[] = {
4400         /* Enable all GPIOs as outputs with an initial value of 0 */
4401         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
4402         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4403         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
4404
4405         /* Enable retasking pins as output, initially without power amp */
4406         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4407         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4408         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4409         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4410         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4411         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4412
4413         /* Disable digital (SPDIF) pins initially, but users can enable
4414          * them via a mixer switch.  In the case of SPDIF-out, this initverb
4415          * payload also sets the generation to 0, output to be in "consumer"
4416          * PCM format, copyright asserted, no pre-emphasis and no validity
4417          * control.
4418          */
4419         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4420         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4421
4422         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the 
4423          * OUT1 sum bus when acting as an output.
4424          */
4425         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
4426         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
4427         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4428         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
4429
4430         /* Start with output sum widgets muted and their output gains at min */
4431         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4432         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4433         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4434         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4435         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4436         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4437         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4438         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4439         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4440
4441         /* Unmute retasking pin widget output buffers since the default
4442          * state appears to be output.  As the pin mode is changed by the
4443          * user the pin mode control will take care of enabling the pin's
4444          * input/output buffers as needed.
4445          */
4446         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4447         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4448         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4449         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4450         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4451         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4452         /* Also unmute the mono-out pin widget */
4453         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4454
4455         /* Mute capture amp left and right */
4456         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4457         /* Set ADC connection select to match default mixer setting (mic1
4458          * pin)
4459          */
4460         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4461
4462         /* Do the same for the second ADC: mute capture input amp and
4463          * set ADC connection to mic1 pin
4464          */
4465         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4466         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4467
4468         /* Mute all inputs to mixer widget (even unconnected ones) */
4469         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4470         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4471         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4472         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4473         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4474         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4475         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4476         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4477
4478         { }
4479 };
4480 #endif
4481
4482 static struct hda_pcm_stream alc260_pcm_analog_playback = {
4483         .substreams = 1,
4484         .channels_min = 2,
4485         .channels_max = 2,
4486 };
4487
4488 static struct hda_pcm_stream alc260_pcm_analog_capture = {
4489         .substreams = 1,
4490         .channels_min = 2,
4491         .channels_max = 2,
4492 };
4493
4494 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
4495 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
4496
4497 /*
4498  * for BIOS auto-configuration
4499  */
4500
4501 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
4502                                         const char *pfx)
4503 {
4504         hda_nid_t nid_vol;
4505         unsigned long vol_val, sw_val;
4506         char name[32];
4507         int err;
4508
4509         if (nid >= 0x0f && nid < 0x11) {
4510                 nid_vol = nid - 0x7;
4511                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
4512                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
4513         } else if (nid == 0x11) {
4514                 nid_vol = nid - 0x7;
4515                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
4516                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
4517         } else if (nid >= 0x12 && nid <= 0x15) {
4518                 nid_vol = 0x08;
4519                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
4520                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
4521         } else
4522                 return 0; /* N/A */
4523         
4524         snprintf(name, sizeof(name), "%s Playback Volume", pfx);
4525         err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val);
4526         if (err < 0)
4527                 return err;
4528         snprintf(name, sizeof(name), "%s Playback Switch", pfx);
4529         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val);
4530         if (err < 0)
4531                 return err;
4532         return 1;
4533 }
4534
4535 /* add playback controls from the parsed DAC table */
4536 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
4537                                              const struct auto_pin_cfg *cfg)
4538 {
4539         hda_nid_t nid;
4540         int err;
4541
4542         spec->multiout.num_dacs = 1;
4543         spec->multiout.dac_nids = spec->private_dac_nids;
4544         spec->multiout.dac_nids[0] = 0x02;
4545
4546         nid = cfg->line_out_pins[0];
4547         if (nid) {
4548                 err = alc260_add_playback_controls(spec, nid, "Front");
4549                 if (err < 0)
4550                         return err;
4551         }
4552
4553         nid = cfg->speaker_pins[0];
4554         if (nid) {
4555                 err = alc260_add_playback_controls(spec, nid, "Speaker");
4556                 if (err < 0)
4557                         return err;
4558         }
4559
4560         nid = cfg->hp_pins[0];
4561         if (nid) {
4562                 err = alc260_add_playback_controls(spec, nid, "Headphone");
4563                 if (err < 0)
4564                         return err;
4565         }
4566         return 0;
4567 }
4568
4569 /* create playback/capture controls for input pins */
4570 static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec,
4571                                                 const struct auto_pin_cfg *cfg)
4572 {
4573         struct hda_input_mux *imux = &spec->private_imux;
4574         int i, err, idx;
4575
4576         for (i = 0; i < AUTO_PIN_LAST; i++) {
4577                 if (cfg->input_pins[i] >= 0x12) {
4578                         idx = cfg->input_pins[i] - 0x12;
4579                         err = new_analog_input(spec, cfg->input_pins[i],
4580                                                auto_pin_cfg_labels[i], idx,
4581                                                0x07);
4582                         if (err < 0)
4583                                 return err;
4584                         imux->items[imux->num_items].label =
4585                                 auto_pin_cfg_labels[i];
4586                         imux->items[imux->num_items].index = idx;
4587                         imux->num_items++;
4588                 }
4589                 if (cfg->input_pins[i] >= 0x0f && cfg->input_pins[i] <= 0x10){
4590                         idx = cfg->input_pins[i] - 0x09;
4591                         err = new_analog_input(spec, cfg->input_pins[i],
4592                                                auto_pin_cfg_labels[i], idx,
4593                                                0x07);
4594                         if (err < 0)
4595                                 return err;
4596                         imux->items[imux->num_items].label =
4597                                 auto_pin_cfg_labels[i];
4598                         imux->items[imux->num_items].index = idx;
4599                         imux->num_items++;
4600                 }
4601         }
4602         return 0;
4603 }
4604
4605 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
4606                                               hda_nid_t nid, int pin_type,
4607                                               int sel_idx)
4608 {
4609         /* set as output */
4610         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4611                             pin_type);
4612         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4613                             AMP_OUT_UNMUTE);
4614         /* need the manual connection? */
4615         if (nid >= 0x12) {
4616                 int idx = nid - 0x12;
4617                 snd_hda_codec_write(codec, idx + 0x0b, 0,
4618                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
4619         }
4620 }
4621
4622 static void alc260_auto_init_multi_out(struct hda_codec *codec)
4623 {
4624         struct alc_spec *spec = codec->spec;
4625         hda_nid_t nid;
4626
4627         alc_subsystem_id(codec, 0x10, 0x15, 0x0f);
4628         nid = spec->autocfg.line_out_pins[0];
4629         if (nid) {
4630                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
4631                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
4632         }
4633         
4634         nid = spec->autocfg.speaker_pins[0];
4635         if (nid)
4636                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
4637
4638         nid = spec->autocfg.hp_pins[0];
4639         if (nid)
4640                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
4641 }
4642
4643 #define ALC260_PIN_CD_NID               0x16
4644 static void alc260_auto_init_analog_input(struct hda_codec *codec)
4645 {
4646         struct alc_spec *spec = codec->spec;
4647         int i;
4648
4649         for (i = 0; i < AUTO_PIN_LAST; i++) {
4650                 hda_nid_t nid = spec->autocfg.input_pins[i];
4651                 if (nid >= 0x12) {
4652                         snd_hda_codec_write(codec, nid, 0,
4653                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
4654                                             i <= AUTO_PIN_FRONT_MIC ?
4655                                             PIN_VREF80 : PIN_IN);
4656                         if (nid != ALC260_PIN_CD_NID)
4657                                 snd_hda_codec_write(codec, nid, 0,
4658                                                     AC_VERB_SET_AMP_GAIN_MUTE,
4659                                                     AMP_OUT_MUTE);
4660                 }
4661         }
4662 }
4663
4664 /*
4665  * generic initialization of ADC, input mixers and output mixers
4666  */
4667 static struct hda_verb alc260_volume_init_verbs[] = {
4668         /*
4669          * Unmute ADC0-1 and set the default input to mic-in
4670          */
4671         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4672         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4673         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4674         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4675         
4676         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4677          * mixer widget
4678          * Note: PASD motherboards uses the Line In 2 as the input for
4679          * front panel mic (mic 2)
4680          */
4681         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
4682         /* mute analog inputs */
4683         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4684         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4685         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4686         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4687         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4688
4689         /*
4690          * Set up output mixers (0x08 - 0x0a)
4691          */
4692         /* set vol=0 to output mixers */
4693         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4694         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4695         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4696         /* set up input amps for analog loopback */
4697         /* Amp Indices: DAC = 0, mixer = 1 */
4698         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4699         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4700         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4701         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4702         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4703         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4704         
4705         { }
4706 };
4707
4708 static int alc260_parse_auto_config(struct hda_codec *codec)
4709 {
4710         struct alc_spec *spec = codec->spec;
4711         unsigned int wcap;
4712         int err;
4713         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
4714
4715         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
4716                                            alc260_ignore);
4717         if (err < 0)
4718                 return err;
4719         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
4720         if (err < 0)
4721                 return err;
4722         if (!spec->kctl_alloc)
4723                 return 0; /* can't find valid BIOS pin config */
4724         err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg);
4725         if (err < 0)
4726                 return err;
4727
4728         spec->multiout.max_channels = 2;
4729
4730         if (spec->autocfg.dig_out_pin)
4731                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
4732         if (spec->kctl_alloc)
4733                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
4734
4735         spec->init_verbs[spec->num_init_verbs++] = alc260_volume_init_verbs;
4736
4737         spec->num_mux_defs = 1;
4738         spec->input_mux = &spec->private_imux;
4739
4740         /* check whether NID 0x04 is valid */
4741         wcap = get_wcaps(codec, 0x04);
4742         wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */
4743         if (wcap != AC_WID_AUD_IN) {
4744                 spec->adc_nids = alc260_adc_nids_alt;
4745                 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
4746                 spec->mixers[spec->num_mixers] = alc260_capture_alt_mixer;
4747         } else {
4748                 spec->adc_nids = alc260_adc_nids;
4749                 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
4750                 spec->mixers[spec->num_mixers] = alc260_capture_mixer;
4751         }
4752         spec->num_mixers++;
4753
4754         return 1;
4755 }
4756
4757 /* additional initialization for auto-configuration model */
4758 static void alc260_auto_init(struct hda_codec *codec)
4759 {
4760         alc260_auto_init_multi_out(codec);
4761         alc260_auto_init_analog_input(codec);
4762 }
4763
4764 #ifdef CONFIG_SND_HDA_POWER_SAVE
4765 static struct hda_amp_list alc260_loopbacks[] = {
4766         { 0x07, HDA_INPUT, 0 },
4767         { 0x07, HDA_INPUT, 1 },
4768         { 0x07, HDA_INPUT, 2 },
4769         { 0x07, HDA_INPUT, 3 },
4770         { 0x07, HDA_INPUT, 4 },
4771         { } /* end */
4772 };
4773 #endif
4774
4775 /*
4776  * ALC260 configurations
4777  */
4778 static const char *alc260_models[ALC260_MODEL_LAST] = {
4779         [ALC260_BASIC]          = "basic",
4780         [ALC260_HP]             = "hp",
4781         [ALC260_HP_3013]        = "hp-3013",
4782         [ALC260_FUJITSU_S702X]  = "fujitsu",
4783         [ALC260_ACER]           = "acer",
4784         [ALC260_WILL]           = "will",
4785         [ALC260_REPLACER_672V]  = "replacer",
4786 #ifdef CONFIG_SND_DEBUG
4787         [ALC260_TEST]           = "test",
4788 #endif
4789         [ALC260_AUTO]           = "auto",
4790 };
4791
4792 static struct snd_pci_quirk alc260_cfg_tbl[] = {
4793         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
4794         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
4795         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
4796         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013),
4797         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
4798         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP),
4799         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_3013),
4800         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
4801         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
4802         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
4803         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
4804         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
4805         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
4806         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
4807         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
4808         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
4809         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
4810         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
4811         {}
4812 };
4813
4814 static struct alc_config_preset alc260_presets[] = {
4815         [ALC260_BASIC] = {
4816                 .mixers = { alc260_base_output_mixer,
4817                             alc260_input_mixer,
4818                             alc260_pc_beep_mixer,
4819                             alc260_capture_mixer },
4820                 .init_verbs = { alc260_init_verbs },
4821                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4822                 .dac_nids = alc260_dac_nids,
4823                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
4824                 .adc_nids = alc260_adc_nids,
4825                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4826                 .channel_mode = alc260_modes,
4827                 .input_mux = &alc260_capture_source,
4828         },
4829         [ALC260_HP] = {
4830                 .mixers = { alc260_base_output_mixer,
4831                             alc260_input_mixer,
4832                             alc260_capture_alt_mixer },
4833                 .init_verbs = { alc260_init_verbs },
4834                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4835                 .dac_nids = alc260_dac_nids,
4836                 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
4837                 .adc_nids = alc260_hp_adc_nids,
4838                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4839                 .channel_mode = alc260_modes,
4840                 .input_mux = &alc260_capture_source,
4841         },
4842         [ALC260_HP_3013] = {
4843                 .mixers = { alc260_hp_3013_mixer,
4844                             alc260_input_mixer,
4845                             alc260_capture_alt_mixer },
4846                 .init_verbs = { alc260_hp_3013_init_verbs },
4847                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4848                 .dac_nids = alc260_dac_nids,
4849                 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
4850                 .adc_nids = alc260_hp_adc_nids,
4851                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4852                 .channel_mode = alc260_modes,
4853                 .input_mux = &alc260_capture_source,
4854         },
4855         [ALC260_FUJITSU_S702X] = {
4856                 .mixers = { alc260_fujitsu_mixer,
4857                             alc260_capture_mixer },
4858                 .init_verbs = { alc260_fujitsu_init_verbs },
4859                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4860                 .dac_nids = alc260_dac_nids,
4861                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
4862                 .adc_nids = alc260_dual_adc_nids,
4863                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4864                 .channel_mode = alc260_modes,
4865                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
4866                 .input_mux = alc260_fujitsu_capture_sources,
4867         },
4868         [ALC260_ACER] = {
4869                 .mixers = { alc260_acer_mixer,
4870                             alc260_capture_mixer },
4871                 .init_verbs = { alc260_acer_init_verbs },
4872                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4873                 .dac_nids = alc260_dac_nids,
4874                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
4875                 .adc_nids = alc260_dual_adc_nids,
4876                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4877                 .channel_mode = alc260_modes,
4878                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
4879                 .input_mux = alc260_acer_capture_sources,
4880         },
4881         [ALC260_WILL] = {
4882                 .mixers = { alc260_will_mixer,
4883                             alc260_capture_mixer },
4884                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
4885                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4886                 .dac_nids = alc260_dac_nids,
4887                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
4888                 .adc_nids = alc260_adc_nids,
4889                 .dig_out_nid = ALC260_DIGOUT_NID,
4890                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4891                 .channel_mode = alc260_modes,
4892                 .input_mux = &alc260_capture_source,
4893         },
4894         [ALC260_REPLACER_672V] = {
4895                 .mixers = { alc260_replacer_672v_mixer,
4896                             alc260_capture_mixer },
4897                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
4898                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4899                 .dac_nids = alc260_dac_nids,
4900                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
4901                 .adc_nids = alc260_adc_nids,
4902                 .dig_out_nid = ALC260_DIGOUT_NID,
4903                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4904                 .channel_mode = alc260_modes,
4905                 .input_mux = &alc260_capture_source,
4906                 .unsol_event = alc260_replacer_672v_unsol_event,
4907                 .init_hook = alc260_replacer_672v_automute,
4908         },
4909 #ifdef CONFIG_SND_DEBUG
4910         [ALC260_TEST] = {
4911                 .mixers = { alc260_test_mixer,
4912                             alc260_capture_mixer },
4913                 .init_verbs = { alc260_test_init_verbs },
4914                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
4915                 .dac_nids = alc260_test_dac_nids,
4916                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
4917                 .adc_nids = alc260_test_adc_nids,
4918                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4919                 .channel_mode = alc260_modes,
4920                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
4921                 .input_mux = alc260_test_capture_sources,
4922         },
4923 #endif
4924 };
4925
4926 static int patch_alc260(struct hda_codec *codec)
4927 {
4928         struct alc_spec *spec;
4929         int err, board_config;
4930
4931         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4932         if (spec == NULL)
4933                 return -ENOMEM;
4934
4935         codec->spec = spec;
4936
4937         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
4938                                                   alc260_models,
4939                                                   alc260_cfg_tbl);
4940         if (board_config < 0) {
4941                 snd_printd(KERN_INFO "hda_codec: Unknown model for ALC260, "
4942                            "trying auto-probe from BIOS...\n");
4943                 board_config = ALC260_AUTO;
4944         }
4945
4946         if (board_config == ALC260_AUTO) {
4947                 /* automatic parse from the BIOS config */
4948                 err = alc260_parse_auto_config(codec);
4949                 if (err < 0) {
4950                         alc_free(codec);
4951                         return err;
4952                 } else if (!err) {
4953                         printk(KERN_INFO
4954                                "hda_codec: Cannot set up configuration "
4955                                "from BIOS.  Using base mode...\n");
4956                         board_config = ALC260_BASIC;
4957                 }
4958         }
4959
4960         if (board_config != ALC260_AUTO)
4961                 setup_preset(spec, &alc260_presets[board_config]);
4962
4963         spec->stream_name_analog = "ALC260 Analog";
4964         spec->stream_analog_playback = &alc260_pcm_analog_playback;
4965         spec->stream_analog_capture = &alc260_pcm_analog_capture;
4966
4967         spec->stream_name_digital = "ALC260 Digital";
4968         spec->stream_digital_playback = &alc260_pcm_digital_playback;
4969         spec->stream_digital_capture = &alc260_pcm_digital_capture;
4970
4971         codec->patch_ops = alc_patch_ops;
4972         if (board_config == ALC260_AUTO)
4973                 spec->init_hook = alc260_auto_init;
4974 #ifdef CONFIG_SND_HDA_POWER_SAVE
4975         if (!spec->loopback.amplist)
4976                 spec->loopback.amplist = alc260_loopbacks;
4977 #endif
4978
4979         return 0;
4980 }
4981
4982
4983 /*
4984  * ALC882 support
4985  *
4986  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4987  * configuration.  Each pin widget can choose any input DACs and a mixer.
4988  * Each ADC is connected from a mixer of all inputs.  This makes possible
4989  * 6-channel independent captures.
4990  *
4991  * In addition, an independent DAC for the multi-playback (not used in this
4992  * driver yet).
4993  */
4994 #define ALC882_DIGOUT_NID       0x06
4995 #define ALC882_DIGIN_NID        0x0a
4996
4997 static struct hda_channel_mode alc882_ch_modes[1] = {
4998         { 8, NULL }
4999 };
5000
5001 static hda_nid_t alc882_dac_nids[4] = {
5002         /* front, rear, clfe, rear_surr */
5003         0x02, 0x03, 0x04, 0x05
5004 };
5005
5006 /* identical with ALC880 */
5007 #define alc882_adc_nids         alc880_adc_nids
5008 #define alc882_adc_nids_alt     alc880_adc_nids_alt
5009
5010 /* input MUX */
5011 /* FIXME: should be a matrix-type input source selection */
5012
5013 static struct hda_input_mux alc882_capture_source = {
5014         .num_items = 4,
5015         .items = {
5016                 { "Mic", 0x0 },
5017                 { "Front Mic", 0x1 },
5018                 { "Line", 0x2 },
5019                 { "CD", 0x4 },
5020         },
5021 };
5022 #define alc882_mux_enum_info alc_mux_enum_info
5023 #define alc882_mux_enum_get alc_mux_enum_get
5024
5025 static int alc882_mux_enum_put(struct snd_kcontrol *kcontrol,
5026                                struct snd_ctl_elem_value *ucontrol)
5027 {
5028         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5029         struct alc_spec *spec = codec->spec;
5030         const struct hda_input_mux *imux = spec->input_mux;
5031         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
5032         static hda_nid_t capture_mixers[3] = { 0x24, 0x23, 0x22 };
5033         hda_nid_t nid = capture_mixers[adc_idx];
5034         unsigned int *cur_val = &spec->cur_mux[adc_idx];
5035         unsigned int i, idx;
5036
5037         idx = ucontrol->value.enumerated.item[0];
5038         if (idx >= imux->num_items)
5039                 idx = imux->num_items - 1;
5040         if (*cur_val == idx)
5041                 return 0;
5042         for (i = 0; i < imux->num_items; i++) {
5043                 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
5044                 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
5045                                          imux->items[i].index,
5046                                          HDA_AMP_MUTE, v);
5047         }
5048         *cur_val = idx;
5049         return 1;
5050 }
5051
5052 /*
5053  * 2ch mode
5054  */
5055 static struct hda_verb alc882_3ST_ch2_init[] = {
5056         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
5057         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5058         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5059         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5060         { } /* end */
5061 };
5062
5063 /*
5064  * 6ch mode
5065  */
5066 static struct hda_verb alc882_3ST_ch6_init[] = {
5067         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5068         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5069         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
5070         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5071         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5072         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5073         { } /* end */
5074 };
5075
5076 static struct hda_channel_mode alc882_3ST_6ch_modes[2] = {
5077         { 2, alc882_3ST_ch2_init },
5078         { 6, alc882_3ST_ch6_init },
5079 };
5080
5081 /*
5082  * 6ch mode
5083  */
5084 static struct hda_verb alc882_sixstack_ch6_init[] = {
5085         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
5086         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5087         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5088         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5089         { } /* end */
5090 };
5091
5092 /*
5093  * 8ch mode
5094  */
5095 static struct hda_verb alc882_sixstack_ch8_init[] = {
5096         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5097         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5098         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5099         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5100         { } /* end */
5101 };
5102
5103 static struct hda_channel_mode alc882_sixstack_modes[2] = {
5104         { 6, alc882_sixstack_ch6_init },
5105         { 8, alc882_sixstack_ch8_init },
5106 };
5107
5108 /*
5109  * macbook pro ALC885 can switch LineIn to LineOut without loosing Mic
5110  */
5111
5112 /*
5113  * 2ch mode
5114  */
5115 static struct hda_verb alc885_mbp_ch2_init[] = {
5116         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5117         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5118         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5119         { } /* end */
5120 };
5121
5122 /*
5123  * 6ch mode
5124  */
5125 static struct hda_verb alc885_mbp_ch6_init[] = {
5126         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5127         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5128         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5129         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5130         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5131         { } /* end */
5132 };
5133
5134 static struct hda_channel_mode alc885_mbp_6ch_modes[2] = {
5135         { 2, alc885_mbp_ch2_init },
5136         { 6, alc885_mbp_ch6_init },
5137 };
5138
5139
5140 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
5141  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
5142  */
5143 static struct snd_kcontrol_new alc882_base_mixer[] = {
5144         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5145         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5146         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
5147         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
5148         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
5149         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
5150         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
5151         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
5152         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
5153         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
5154         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5155         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5156         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5157         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5158         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5159         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5160         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5161         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5162         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5163         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5164         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5165         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5166         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5167         { } /* end */
5168 };
5169
5170 static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
5171         HDA_CODEC_VOLUME("Master Volume", 0x0c, 0x00, HDA_OUTPUT),
5172         HDA_BIND_MUTE   ("Master Switch", 0x0c, 0x02, HDA_INPUT),
5173         HDA_CODEC_MUTE  ("Speaker Switch", 0x14, 0x00, HDA_OUTPUT),
5174         HDA_CODEC_VOLUME("Line Out Volume", 0x0d,0x00, HDA_OUTPUT),
5175         HDA_CODEC_VOLUME("Line In Playback Volume", 0x0b, 0x02, HDA_INPUT),
5176         HDA_CODEC_MUTE  ("Line In Playback Switch", 0x0b, 0x02, HDA_INPUT),
5177         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
5178         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
5179         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0x00, HDA_INPUT),
5180         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
5181         { } /* end */
5182 };
5183 static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
5184         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5185         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5186         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5187         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5188         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5189         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5190         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5191         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5192         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5193         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5194         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5195         { } /* end */
5196 };
5197
5198 static struct snd_kcontrol_new alc882_targa_mixer[] = {
5199         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5200         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5201         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5202         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5203         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5204         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5205         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5206         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5207         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5208         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5209         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5210         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5211         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5212         { } /* end */
5213 };
5214
5215 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
5216  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
5217  */
5218 static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
5219         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5220         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
5221         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5222         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
5223         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5224         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5225         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5226         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5227         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
5228         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
5229         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5230         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5231         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5232         { } /* end */
5233 };
5234
5235 static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
5236         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5237         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5238         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5239         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5240         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5241         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5242         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5243         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5244         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5245         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5246         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5247         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5248         { } /* end */
5249 };
5250
5251 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
5252         {
5253                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5254                 .name = "Channel Mode",
5255                 .info = alc_ch_mode_info,
5256                 .get = alc_ch_mode_get,
5257                 .put = alc_ch_mode_put,
5258         },
5259         { } /* end */
5260 };
5261
5262 static struct hda_verb alc882_init_verbs[] = {
5263         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5264         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5265         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5266         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5267         /* Rear mixer */
5268         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5269         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5270         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5271         /* CLFE mixer */
5272         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5273         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5274         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5275         /* Side mixer */
5276         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5277         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5278         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5279
5280         /* Front Pin: output 0 (0x0c) */
5281         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5282         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5283         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5284         /* Rear Pin: output 1 (0x0d) */
5285         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5286         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5287         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5288         /* CLFE Pin: output 2 (0x0e) */
5289         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5290         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5291         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
5292         /* Side Pin: output 3 (0x0f) */
5293         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5294         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5295         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
5296         /* Mic (rear) pin: input vref at 80% */
5297         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5298         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5299         /* Front Mic pin: input vref at 80% */
5300         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5301         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5302         /* Line In pin: input */
5303         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5304         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5305         /* Line-2 In: Headphone output (output 0 - 0x0c) */
5306         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5307         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5308         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
5309         /* CD pin widget for input */
5310         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5311
5312         /* FIXME: use matrix-type input source selection */
5313         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5314         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5315         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5316         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5317         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5318         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5319         /* Input mixer2 */
5320         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5321         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5322         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5323         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5324         /* Input mixer3 */
5325         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5326         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5327         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5328         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5329         /* ADC1: mute amp left and right */
5330         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5331         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5332         /* ADC2: mute amp left and right */
5333         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5334         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5335         /* ADC3: mute amp left and right */
5336         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5337         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5338
5339         { }
5340 };
5341
5342 static struct hda_verb alc882_eapd_verbs[] = {
5343         /* change to EAPD mode */
5344         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
5345         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
5346         { }
5347 };
5348
5349 /* Mac Pro test */
5350 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
5351         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5352         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5353         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
5354         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
5355         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
5356         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT),
5357         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT),
5358         { } /* end */
5359 };
5360
5361 static struct hda_verb alc882_macpro_init_verbs[] = {
5362         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5363         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5364         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5365         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5366         /* Front Pin: output 0 (0x0c) */
5367         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5368         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5369         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
5370         /* Front Mic pin: input vref at 80% */
5371         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5372         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5373         /* Speaker:  output */
5374         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5375         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5376         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
5377         /* Headphone output (output 0 - 0x0c) */
5378         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5379         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5380         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
5381
5382         /* FIXME: use matrix-type input source selection */
5383         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5384         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5385         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5386         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5387         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5388         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5389         /* Input mixer2 */
5390         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5391         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5392         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5393         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5394         /* Input mixer3 */
5395         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5396         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5397         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5398         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5399         /* ADC1: mute amp left and right */
5400         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5401         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5402         /* ADC2: mute amp left and right */
5403         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5404         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5405         /* ADC3: mute amp left and right */
5406         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5407         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5408
5409         { }
5410 };
5411
5412 /* Macbook Pro rev3 */
5413 static struct hda_verb alc885_mbp3_init_verbs[] = {
5414         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5415         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5416         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5417         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5418         /* Rear mixer */
5419         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5420         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5421         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5422         /* Front Pin: output 0 (0x0c) */
5423         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5424         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5425         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5426         /* HP Pin: output 0 (0x0d) */
5427         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
5428         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5429         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
5430         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5431         /* Mic (rear) pin: input vref at 80% */
5432         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5433         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5434         /* Front Mic pin: input vref at 80% */
5435         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5436         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5437         /* Line In pin: use output 1 when in LineOut mode */
5438         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5439         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5440         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
5441
5442         /* FIXME: use matrix-type input source selection */
5443         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5444         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5445         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5446         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5447         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5448         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5449         /* Input mixer2 */
5450         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5451         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5452         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5453         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5454         /* Input mixer3 */
5455         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5456         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5457         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5458         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5459         /* ADC1: mute amp left and right */
5460         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5461         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5462         /* ADC2: mute amp left and right */
5463         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5464         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5465         /* ADC3: mute amp left and right */
5466         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5467         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5468
5469         { }
5470 };
5471
5472 /* iMac 24 mixer. */
5473 static struct snd_kcontrol_new alc885_imac24_mixer[] = {
5474         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
5475         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
5476         { } /* end */
5477 };
5478
5479 /* iMac 24 init verbs. */
5480 static struct hda_verb alc885_imac24_init_verbs[] = {
5481         /* Internal speakers: output 0 (0x0c) */
5482         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5483         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5484         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
5485         /* Internal speakers: output 0 (0x0c) */
5486         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5487         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5488         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
5489         /* Headphone: output 0 (0x0c) */
5490         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5491         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5492         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5493         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5494         /* Front Mic: input vref at 80% */
5495         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5496         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5497         { }
5498 };
5499
5500 /* Toggle speaker-output according to the hp-jack state */
5501 static void alc885_imac24_automute(struct hda_codec *codec)
5502 {
5503         unsigned int present;
5504
5505         present = snd_hda_codec_read(codec, 0x14, 0,
5506                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5507         snd_hda_codec_amp_stereo(codec, 0x18, HDA_OUTPUT, 0,
5508                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5509         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
5510                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5511 }
5512
5513 /* Processes unsolicited events. */
5514 static void alc885_imac24_unsol_event(struct hda_codec *codec,
5515                                       unsigned int res)
5516 {
5517         /* Headphone insertion or removal. */
5518         if ((res >> 26) == ALC880_HP_EVENT)
5519                 alc885_imac24_automute(codec);
5520 }
5521
5522 static void alc885_mbp3_automute(struct hda_codec *codec)
5523 {
5524         unsigned int present;
5525
5526         present = snd_hda_codec_read(codec, 0x15, 0,
5527                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5528         snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
5529                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5530         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
5531                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
5532
5533 }
5534 static void alc885_mbp3_unsol_event(struct hda_codec *codec,
5535                                     unsigned int res)
5536 {
5537         /* Headphone insertion or removal. */
5538         if ((res >> 26) == ALC880_HP_EVENT)
5539                 alc885_mbp3_automute(codec);
5540 }
5541
5542
5543 static struct hda_verb alc882_targa_verbs[] = {
5544         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5545         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5546
5547         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5548         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5549         
5550         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
5551         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
5552         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5553
5554         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5555         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5556         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
5557         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
5558         { } /* end */
5559 };
5560
5561 /* toggle speaker-output according to the hp-jack state */
5562 static void alc882_targa_automute(struct hda_codec *codec)
5563 {
5564         unsigned int present;
5565  
5566         present = snd_hda_codec_read(codec, 0x14, 0,
5567                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5568         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
5569                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5570         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
5571                                   present ? 1 : 3);
5572 }
5573
5574 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
5575 {
5576         /* Looks like the unsol event is incompatible with the standard
5577          * definition.  4bit tag is placed at 26 bit!
5578          */
5579         if (((res >> 26) == ALC880_HP_EVENT)) {
5580                 alc882_targa_automute(codec);
5581         }
5582 }
5583
5584 static struct hda_verb alc882_asus_a7j_verbs[] = {
5585         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5586         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5587
5588         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5589         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5590         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5591         
5592         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5593         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5594         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5595
5596         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
5597         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
5598         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5599         { } /* end */
5600 };
5601
5602 static struct hda_verb alc882_asus_a7m_verbs[] = {
5603         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5604         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5605
5606         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5607         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5608         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5609         
5610         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5611         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5612         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5613
5614         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
5615         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
5616         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5617         { } /* end */
5618 };
5619
5620 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5621 {
5622         unsigned int gpiostate, gpiomask, gpiodir;
5623
5624         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5625                                        AC_VERB_GET_GPIO_DATA, 0);
5626
5627         if (!muted)
5628                 gpiostate |= (1 << pin);
5629         else
5630                 gpiostate &= ~(1 << pin);
5631
5632         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5633                                       AC_VERB_GET_GPIO_MASK, 0);
5634         gpiomask |= (1 << pin);
5635
5636         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5637                                      AC_VERB_GET_GPIO_DIRECTION, 0);
5638         gpiodir |= (1 << pin);
5639
5640
5641         snd_hda_codec_write(codec, codec->afg, 0,
5642                             AC_VERB_SET_GPIO_MASK, gpiomask);
5643         snd_hda_codec_write(codec, codec->afg, 0,
5644                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5645
5646         msleep(1);
5647
5648         snd_hda_codec_write(codec, codec->afg, 0,
5649                             AC_VERB_SET_GPIO_DATA, gpiostate);
5650 }
5651
5652 /* set up GPIO at initialization */
5653 static void alc885_macpro_init_hook(struct hda_codec *codec)
5654 {
5655         alc882_gpio_mute(codec, 0, 0);
5656         alc882_gpio_mute(codec, 1, 0);
5657 }
5658
5659 /* set up GPIO and update auto-muting at initialization */
5660 static void alc885_imac24_init_hook(struct hda_codec *codec)
5661 {
5662         alc885_macpro_init_hook(codec);
5663         alc885_imac24_automute(codec);
5664 }
5665
5666 /*
5667  * generic initialization of ADC, input mixers and output mixers
5668  */
5669 static struct hda_verb alc882_auto_init_verbs[] = {
5670         /*
5671          * Unmute ADC0-2 and set the default input to mic-in
5672          */
5673         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5674         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5675         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5676         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5677         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5678         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5679
5680         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5681          * mixer widget
5682          * Note: PASD motherboards uses the Line In 2 as the input for
5683          * front panel mic (mic 2)
5684          */
5685         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
5686         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5687         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5688         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5689         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5690         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5691
5692         /*
5693          * Set up output mixers (0x0c - 0x0f)
5694          */
5695         /* set vol=0 to output mixers */
5696         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5697         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5698         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5699         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5700         /* set up input amps for analog loopback */
5701         /* Amp Indices: DAC = 0, mixer = 1 */
5702         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5703         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5704         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5705         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5706         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5707         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5708         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5709         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5710         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5711         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5712
5713         /* FIXME: use matrix-type input source selection */
5714         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5715         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5716         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5717         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
5718         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
5719         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
5720         /* Input mixer2 */
5721         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5722         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
5723         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
5724         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
5725         /* Input mixer3 */
5726         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5727         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
5728         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
5729         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
5730
5731         { }
5732 };
5733
5734 /* capture mixer elements */
5735 static struct snd_kcontrol_new alc882_capture_alt_mixer[] = {
5736         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
5737         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
5738         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
5739         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
5740         {
5741                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5742                 /* The multiple "Capture Source" controls confuse alsamixer
5743                  * So call somewhat different..
5744                  * FIXME: the controls appear in the "playback" view!
5745                  */
5746                 /* .name = "Capture Source", */
5747                 .name = "Input Source",
5748                 .count = 2,
5749                 .info = alc882_mux_enum_info,
5750                 .get = alc882_mux_enum_get,
5751                 .put = alc882_mux_enum_put,
5752         },
5753         { } /* end */
5754 };
5755
5756 static struct snd_kcontrol_new alc882_capture_mixer[] = {
5757         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
5758         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
5759         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
5760         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
5761         HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
5762         HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
5763         {
5764                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5765                 /* The multiple "Capture Source" controls confuse alsamixer
5766                  * So call somewhat different..
5767                  * FIXME: the controls appear in the "playback" view!
5768                  */
5769                 /* .name = "Capture Source", */
5770                 .name = "Input Source",
5771                 .count = 3,
5772                 .info = alc882_mux_enum_info,
5773                 .get = alc882_mux_enum_get,
5774                 .put = alc882_mux_enum_put,
5775         },
5776         { } /* end */
5777 };
5778
5779 #ifdef CONFIG_SND_HDA_POWER_SAVE
5780 #define alc882_loopbacks        alc880_loopbacks
5781 #endif
5782
5783 /* pcm configuration: identiacal with ALC880 */
5784 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
5785 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
5786 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
5787 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
5788
5789 /*
5790  * configuration and preset
5791  */
5792 static const char *alc882_models[ALC882_MODEL_LAST] = {
5793         [ALC882_3ST_DIG]        = "3stack-dig",
5794         [ALC882_6ST_DIG]        = "6stack-dig",
5795         [ALC882_ARIMA]          = "arima",
5796         [ALC882_W2JC]           = "w2jc",
5797         [ALC882_TARGA]          = "targa",
5798         [ALC882_ASUS_A7J]       = "asus-a7j",
5799         [ALC882_ASUS_A7M]       = "asus-a7m",
5800         [ALC885_MACPRO]         = "macpro",
5801         [ALC885_MBP3]           = "mbp3",
5802         [ALC885_IMAC24]         = "imac24",
5803         [ALC882_AUTO]           = "auto",
5804 };
5805
5806 static struct snd_pci_quirk alc882_cfg_tbl[] = {
5807         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
5808         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
5809         SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
5810         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
5811         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
5812         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
5813         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
5814         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
5815         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
5816         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
5817         SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA),
5818         {}
5819 };
5820
5821 static struct alc_config_preset alc882_presets[] = {
5822         [ALC882_3ST_DIG] = {
5823                 .mixers = { alc882_base_mixer },
5824                 .init_verbs = { alc882_init_verbs },
5825                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5826                 .dac_nids = alc882_dac_nids,
5827                 .dig_out_nid = ALC882_DIGOUT_NID,
5828                 .dig_in_nid = ALC882_DIGIN_NID,
5829                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
5830                 .channel_mode = alc882_ch_modes,
5831                 .need_dac_fix = 1,
5832                 .input_mux = &alc882_capture_source,
5833         },
5834         [ALC882_6ST_DIG] = {
5835                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
5836                 .init_verbs = { alc882_init_verbs },
5837                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5838                 .dac_nids = alc882_dac_nids,
5839                 .dig_out_nid = ALC882_DIGOUT_NID,
5840                 .dig_in_nid = ALC882_DIGIN_NID,
5841                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
5842                 .channel_mode = alc882_sixstack_modes,
5843                 .input_mux = &alc882_capture_source,
5844         },
5845         [ALC882_ARIMA] = {
5846                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
5847                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs },
5848                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5849                 .dac_nids = alc882_dac_nids,
5850                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
5851                 .channel_mode = alc882_sixstack_modes,
5852                 .input_mux = &alc882_capture_source,
5853         },
5854         [ALC882_W2JC] = {
5855                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
5856                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
5857                                 alc880_gpio1_init_verbs },
5858                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5859                 .dac_nids = alc882_dac_nids,
5860                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
5861                 .channel_mode = alc880_threestack_modes,
5862                 .need_dac_fix = 1,
5863                 .input_mux = &alc882_capture_source,
5864                 .dig_out_nid = ALC882_DIGOUT_NID,
5865         },
5866         [ALC885_MBP3] = {
5867                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
5868                 .init_verbs = { alc885_mbp3_init_verbs,
5869                                 alc880_gpio1_init_verbs },
5870                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5871                 .dac_nids = alc882_dac_nids,
5872                 .channel_mode = alc885_mbp_6ch_modes,
5873                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_6ch_modes),
5874                 .input_mux = &alc882_capture_source,
5875                 .dig_out_nid = ALC882_DIGOUT_NID,
5876                 .dig_in_nid = ALC882_DIGIN_NID,
5877                 .unsol_event = alc885_mbp3_unsol_event,
5878                 .init_hook = alc885_mbp3_automute,
5879         },
5880         [ALC885_MACPRO] = {
5881                 .mixers = { alc882_macpro_mixer },
5882                 .init_verbs = { alc882_macpro_init_verbs },
5883                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5884                 .dac_nids = alc882_dac_nids,
5885                 .dig_out_nid = ALC882_DIGOUT_NID,
5886                 .dig_in_nid = ALC882_DIGIN_NID,
5887                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
5888                 .channel_mode = alc882_ch_modes,
5889                 .input_mux = &alc882_capture_source,
5890                 .init_hook = alc885_macpro_init_hook,
5891         },
5892         [ALC885_IMAC24] = {
5893                 .mixers = { alc885_imac24_mixer },
5894                 .init_verbs = { alc885_imac24_init_verbs },
5895                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5896                 .dac_nids = alc882_dac_nids,
5897                 .dig_out_nid = ALC882_DIGOUT_NID,
5898                 .dig_in_nid = ALC882_DIGIN_NID,
5899                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
5900                 .channel_mode = alc882_ch_modes,
5901                 .input_mux = &alc882_capture_source,
5902                 .unsol_event = alc885_imac24_unsol_event,
5903                 .init_hook = alc885_imac24_init_hook,
5904         },
5905         [ALC882_TARGA] = {
5906                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer,
5907                             alc882_capture_mixer },
5908                 .init_verbs = { alc882_init_verbs, alc882_targa_verbs},
5909                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5910                 .dac_nids = alc882_dac_nids,
5911                 .dig_out_nid = ALC882_DIGOUT_NID,
5912                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
5913                 .adc_nids = alc882_adc_nids,
5914                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
5915                 .channel_mode = alc882_3ST_6ch_modes,
5916                 .need_dac_fix = 1,
5917                 .input_mux = &alc882_capture_source,
5918                 .unsol_event = alc882_targa_unsol_event,
5919                 .init_hook = alc882_targa_automute,
5920         },
5921         [ALC882_ASUS_A7J] = {
5922                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer,
5923                             alc882_capture_mixer },
5924                 .init_verbs = { alc882_init_verbs, alc882_asus_a7j_verbs},
5925                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5926                 .dac_nids = alc882_dac_nids,
5927                 .dig_out_nid = ALC882_DIGOUT_NID,
5928                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
5929                 .adc_nids = alc882_adc_nids,
5930                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
5931                 .channel_mode = alc882_3ST_6ch_modes,
5932                 .need_dac_fix = 1,
5933                 .input_mux = &alc882_capture_source,
5934         },      
5935         [ALC882_ASUS_A7M] = {
5936                 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
5937                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
5938                                 alc880_gpio1_init_verbs,
5939                                 alc882_asus_a7m_verbs },
5940                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5941                 .dac_nids = alc882_dac_nids,
5942                 .dig_out_nid = ALC882_DIGOUT_NID,
5943                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
5944                 .channel_mode = alc880_threestack_modes,
5945                 .need_dac_fix = 1,
5946                 .input_mux = &alc882_capture_source,
5947         },      
5948 };
5949
5950
5951 /*
5952  * Pin config fixes
5953  */
5954 enum { 
5955         PINFIX_ABIT_AW9D_MAX
5956 };
5957
5958 static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
5959         { 0x15, 0x01080104 }, /* side */
5960         { 0x16, 0x01011012 }, /* rear */
5961         { 0x17, 0x01016011 }, /* clfe */
5962         { }
5963 };
5964
5965 static const struct alc_pincfg *alc882_pin_fixes[] = {
5966         [PINFIX_ABIT_AW9D_MAX] = alc882_abit_aw9d_pinfix,
5967 };
5968
5969 static struct snd_pci_quirk alc882_pinfix_tbl[] = {
5970         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
5971         {}
5972 };
5973
5974 /*
5975  * BIOS auto configuration
5976  */
5977 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
5978                                               hda_nid_t nid, int pin_type,
5979                                               int dac_idx)
5980 {
5981         /* set as output */
5982         struct alc_spec *spec = codec->spec;
5983         int idx;
5984
5985         if (spec->multiout.dac_nids[dac_idx] == 0x25)
5986                 idx = 4;
5987         else
5988                 idx = spec->multiout.dac_nids[dac_idx] - 2;
5989
5990         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5991                             pin_type);
5992         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
5993                             AMP_OUT_UNMUTE);
5994         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
5995
5996 }
5997
5998 static void alc882_auto_init_multi_out(struct hda_codec *codec)
5999 {
6000         struct alc_spec *spec = codec->spec;
6001         int i;
6002
6003         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
6004         for (i = 0; i <= HDA_SIDE; i++) {
6005                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
6006                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
6007                 if (nid)
6008                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
6009                                                           i);
6010         }
6011 }
6012
6013 static void alc882_auto_init_hp_out(struct hda_codec *codec)
6014 {
6015         struct alc_spec *spec = codec->spec;
6016         hda_nid_t pin;
6017
6018         pin = spec->autocfg.hp_pins[0];
6019         if (pin) /* connect to front */
6020                 /* use dac 0 */
6021                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
6022 }
6023
6024 #define alc882_is_input_pin(nid)        alc880_is_input_pin(nid)
6025 #define ALC882_PIN_CD_NID               ALC880_PIN_CD_NID
6026
6027 static void alc882_auto_init_analog_input(struct hda_codec *codec)
6028 {
6029         struct alc_spec *spec = codec->spec;
6030         int i;
6031
6032         for (i = 0; i < AUTO_PIN_LAST; i++) {
6033                 hda_nid_t nid = spec->autocfg.input_pins[i];
6034                 if (alc882_is_input_pin(nid)) {
6035                         snd_hda_codec_write(codec, nid, 0,
6036                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
6037                                             i <= AUTO_PIN_FRONT_MIC ?
6038                                             PIN_VREF80 : PIN_IN);
6039                         if (nid != ALC882_PIN_CD_NID)
6040                                 snd_hda_codec_write(codec, nid, 0,
6041                                                     AC_VERB_SET_AMP_GAIN_MUTE,
6042                                                     AMP_OUT_MUTE);
6043                 }
6044         }
6045 }
6046
6047 /* add mic boosts if needed */
6048 static int alc_auto_add_mic_boost(struct hda_codec *codec)
6049 {
6050         struct alc_spec *spec = codec->spec;
6051         int err;
6052         hda_nid_t nid;
6053
6054         nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
6055         if (nid) {
6056                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6057                                   "Mic Boost",
6058                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6059                 if (err < 0)
6060                         return err;
6061         }
6062         nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
6063         if (nid) {
6064                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6065                                   "Front Mic Boost",
6066                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6067                 if (err < 0)
6068                         return err;
6069         }
6070         return 0;
6071 }
6072
6073 /* almost identical with ALC880 parser... */
6074 static int alc882_parse_auto_config(struct hda_codec *codec)
6075 {
6076         struct alc_spec *spec = codec->spec;
6077         int err = alc880_parse_auto_config(codec);
6078
6079         if (err < 0)
6080                 return err;
6081         else if (!err)
6082                 return 0; /* no config found */
6083
6084         err = alc_auto_add_mic_boost(codec);
6085         if (err < 0)
6086                 return err;
6087
6088         /* hack - override the init verbs */
6089         spec->init_verbs[0] = alc882_auto_init_verbs;
6090
6091         return 1; /* config found */
6092 }
6093
6094 /* additional initialization for auto-configuration model */
6095 static void alc882_auto_init(struct hda_codec *codec)
6096 {
6097         alc882_auto_init_multi_out(codec);
6098         alc882_auto_init_hp_out(codec);
6099         alc882_auto_init_analog_input(codec);
6100 }
6101
6102 static int patch_alc882(struct hda_codec *codec)
6103 {
6104         struct alc_spec *spec;
6105         int err, board_config;
6106
6107         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6108         if (spec == NULL)
6109                 return -ENOMEM;
6110
6111         codec->spec = spec;
6112
6113         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
6114                                                   alc882_models,
6115                                                   alc882_cfg_tbl);
6116
6117         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
6118                 /* Pick up systems that don't supply PCI SSID */
6119                 switch (codec->subsystem_id) {
6120                 case 0x106b0c00: /* Mac Pro */
6121                         board_config = ALC885_MACPRO;
6122                         break;
6123                 case 0x106b1000: /* iMac 24 */
6124                         board_config = ALC885_IMAC24;
6125                         break;
6126                 case 0x106b2c00: /* Macbook Pro rev3 */
6127                         board_config = ALC885_MBP3;
6128                         break;
6129                 default:
6130                         printk(KERN_INFO "hda_codec: Unknown model for ALC882, "
6131                                          "trying auto-probe from BIOS...\n");
6132                         board_config = ALC882_AUTO;
6133                 }
6134         }
6135
6136         alc_fix_pincfg(codec, alc882_pinfix_tbl, alc882_pin_fixes);
6137
6138         if (board_config == ALC882_AUTO) {
6139                 /* automatic parse from the BIOS config */
6140                 err = alc882_parse_auto_config(codec);
6141                 if (err < 0) {
6142                         alc_free(codec);
6143                         return err;
6144                 } else if (!err) {
6145                         printk(KERN_INFO
6146                                "hda_codec: Cannot set up configuration "
6147                                "from BIOS.  Using base mode...\n");
6148                         board_config = ALC882_3ST_DIG;
6149                 }
6150         }
6151
6152         if (board_config != ALC882_AUTO)
6153                 setup_preset(spec, &alc882_presets[board_config]);
6154
6155         spec->stream_name_analog = "ALC882 Analog";
6156         spec->stream_analog_playback = &alc882_pcm_analog_playback;
6157         spec->stream_analog_capture = &alc882_pcm_analog_capture;
6158
6159         spec->stream_name_digital = "ALC882 Digital";
6160         spec->stream_digital_playback = &alc882_pcm_digital_playback;
6161         spec->stream_digital_capture = &alc882_pcm_digital_capture;
6162
6163         if (!spec->adc_nids && spec->input_mux) {
6164                 /* check whether NID 0x07 is valid */
6165                 unsigned int wcap = get_wcaps(codec, 0x07);
6166                 /* get type */
6167                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
6168                 if (wcap != AC_WID_AUD_IN) {
6169                         spec->adc_nids = alc882_adc_nids_alt;
6170                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
6171                         spec->mixers[spec->num_mixers] =
6172                                 alc882_capture_alt_mixer;
6173                         spec->num_mixers++;
6174                 } else {
6175                         spec->adc_nids = alc882_adc_nids;
6176                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
6177                         spec->mixers[spec->num_mixers] = alc882_capture_mixer;
6178                         spec->num_mixers++;
6179                 }
6180         }
6181
6182         codec->patch_ops = alc_patch_ops;
6183         if (board_config == ALC882_AUTO)
6184                 spec->init_hook = alc882_auto_init;
6185 #ifdef CONFIG_SND_HDA_POWER_SAVE
6186         if (!spec->loopback.amplist)
6187                 spec->loopback.amplist = alc882_loopbacks;
6188 #endif
6189
6190         return 0;
6191 }
6192
6193 /*
6194  * ALC883 support
6195  *
6196  * ALC883 is almost identical with ALC880 but has cleaner and more flexible
6197  * configuration.  Each pin widget can choose any input DACs and a mixer.
6198  * Each ADC is connected from a mixer of all inputs.  This makes possible
6199  * 6-channel independent captures.
6200  *
6201  * In addition, an independent DAC for the multi-playback (not used in this
6202  * driver yet).
6203  */
6204 #define ALC883_DIGOUT_NID       0x06
6205 #define ALC883_DIGIN_NID        0x0a
6206
6207 static hda_nid_t alc883_dac_nids[4] = {
6208         /* front, rear, clfe, rear_surr */
6209         0x02, 0x04, 0x03, 0x05
6210 };
6211
6212 static hda_nid_t alc883_adc_nids[2] = {
6213         /* ADC1-2 */
6214         0x08, 0x09,
6215 };
6216
6217 /* input MUX */
6218 /* FIXME: should be a matrix-type input source selection */
6219
6220 static struct hda_input_mux alc883_capture_source = {
6221         .num_items = 4,
6222         .items = {
6223                 { "Mic", 0x0 },
6224                 { "Front Mic", 0x1 },
6225                 { "Line", 0x2 },
6226                 { "CD", 0x4 },
6227         },
6228 };
6229
6230 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
6231         .num_items = 2,
6232         .items = {
6233                 { "Mic", 0x1 },
6234                 { "Line", 0x2 },
6235         },
6236 };
6237
6238 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
6239         .num_items = 4,
6240         .items = {
6241                 { "Mic", 0x0 },
6242                 { "iMic", 0x1 },
6243                 { "Line", 0x2 },
6244                 { "CD", 0x4 },
6245         },
6246 };
6247
6248 #define alc883_mux_enum_info alc_mux_enum_info
6249 #define alc883_mux_enum_get alc_mux_enum_get
6250
6251 static int alc883_mux_enum_put(struct snd_kcontrol *kcontrol,
6252                                struct snd_ctl_elem_value *ucontrol)
6253 {
6254         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6255         struct alc_spec *spec = codec->spec;
6256         const struct hda_input_mux *imux = spec->input_mux;
6257         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
6258         static hda_nid_t capture_mixers[3] = { 0x24, 0x23, 0x22 };
6259         hda_nid_t nid = capture_mixers[adc_idx];
6260         unsigned int *cur_val = &spec->cur_mux[adc_idx];
6261         unsigned int i, idx;
6262
6263         idx = ucontrol->value.enumerated.item[0];
6264         if (idx >= imux->num_items)
6265                 idx = imux->num_items - 1;
6266         if (*cur_val == idx)
6267                 return 0;
6268         for (i = 0; i < imux->num_items; i++) {
6269                 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
6270                 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
6271                                          imux->items[i].index,
6272                                          HDA_AMP_MUTE, v);
6273         }
6274         *cur_val = idx;
6275         return 1;
6276 }
6277
6278 /*
6279  * 2ch mode
6280  */
6281 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
6282         { 2, NULL }
6283 };
6284
6285 /*
6286  * 2ch mode
6287  */
6288 static struct hda_verb alc883_3ST_ch2_init[] = {
6289         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6290         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6291         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6292         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6293         { } /* end */
6294 };
6295
6296 /*
6297  * 4ch mode
6298  */
6299 static struct hda_verb alc883_3ST_ch4_init[] = {
6300         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6301         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6302         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6303         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6304         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6305         { } /* end */
6306 };
6307
6308 /*
6309  * 6ch mode
6310  */
6311 static struct hda_verb alc883_3ST_ch6_init[] = {
6312         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6313         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6314         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6315         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6316         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6317         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6318         { } /* end */
6319 };
6320
6321 static struct hda_channel_mode alc883_3ST_6ch_modes[3] = {
6322         { 2, alc883_3ST_ch2_init },
6323         { 4, alc883_3ST_ch4_init },
6324         { 6, alc883_3ST_ch6_init },
6325 };
6326
6327 /*
6328  * 6ch mode
6329  */
6330 static struct hda_verb alc883_sixstack_ch6_init[] = {
6331         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6332         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6333         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6334         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6335         { } /* end */
6336 };
6337
6338 /*
6339  * 8ch mode
6340  */
6341 static struct hda_verb alc883_sixstack_ch8_init[] = {
6342         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6343         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6344         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6345         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6346         { } /* end */
6347 };
6348
6349 static struct hda_channel_mode alc883_sixstack_modes[2] = {
6350         { 6, alc883_sixstack_ch6_init },
6351         { 8, alc883_sixstack_ch8_init },
6352 };
6353
6354 static struct hda_verb alc883_medion_eapd_verbs[] = {
6355         /* eanable EAPD on medion laptop */
6356         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
6357         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
6358         { }
6359 };
6360
6361 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
6362  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
6363  */
6364
6365 static struct snd_kcontrol_new alc883_base_mixer[] = {
6366         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6367         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6368         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6369         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6370         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6371         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6372         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6373         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6374         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6375         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6376         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6377         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6378         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6379         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6380         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6381         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6382         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6383         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6384         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6385         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6386         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6387         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6388         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6389         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6390         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6391         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6392         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6393         {
6394                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6395                 /* .name = "Capture Source", */
6396                 .name = "Input Source",
6397                 .count = 2,
6398                 .info = alc883_mux_enum_info,
6399                 .get = alc883_mux_enum_get,
6400                 .put = alc883_mux_enum_put,
6401         },
6402         { } /* end */
6403 };
6404
6405 static struct snd_kcontrol_new alc883_mitac_mixer[] = {
6406         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6407         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6408         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6409         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6410         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6411         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6412         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6413         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6414         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6415         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6416         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6417         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6418         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6419         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6420         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6421         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6422         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6423         {
6424                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6425                 /* .name = "Capture Source", */
6426                 .name = "Input Source",
6427                 .count = 2,
6428                 .info = alc883_mux_enum_info,
6429                 .get = alc883_mux_enum_get,
6430                 .put = alc883_mux_enum_put,
6431         },
6432         { } /* end */
6433 };
6434
6435 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
6436         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6437         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6438         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6439         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6440         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6441         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6442         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6443         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6444         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6445         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6446         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6447         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6448         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6449         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6450         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6451         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6452         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6453         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6454         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6455         {
6456                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6457                 /* .name = "Capture Source", */
6458                 .name = "Input Source",
6459                 .count = 2,
6460                 .info = alc883_mux_enum_info,
6461                 .get = alc883_mux_enum_get,
6462                 .put = alc883_mux_enum_put,
6463         },
6464         { } /* end */
6465 };
6466
6467 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
6468         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6469         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6470         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6471         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6472         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6473         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6474         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6475         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6476         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6477         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6478         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6479         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6480         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6481         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6482         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6483         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6484         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6485         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6486         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6487         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6488         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6489         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6490         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6491         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6492         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6493         {
6494                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6495                 /* .name = "Capture Source", */
6496                 .name = "Input Source",
6497                 .count = 2,
6498                 .info = alc883_mux_enum_info,
6499                 .get = alc883_mux_enum_get,
6500                 .put = alc883_mux_enum_put,
6501         },
6502         { } /* end */
6503 };
6504
6505 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
6506         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6507         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6508         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6509         HDA_CODEC_MUTE("Surround Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6510         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6511         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6512         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x16, 1, 0x0, HDA_OUTPUT),
6513         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
6514         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6515         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6516         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6517         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6518         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6519         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6520         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6521         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6522         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6523         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6524         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6525         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6526         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6527         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6528         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6529
6530         {
6531                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6532                 /* .name = "Capture Source", */
6533                 .name = "Input Source",
6534                 .count = 1,
6535                 .info = alc883_mux_enum_info,
6536                 .get = alc883_mux_enum_get,
6537                 .put = alc883_mux_enum_put,
6538         },
6539         { } /* end */
6540 };
6541
6542 static struct snd_kcontrol_new alc883_tagra_mixer[] = {
6543         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6544         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6545         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6546         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6547         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6548         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6549         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6550         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6551         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6552         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6553         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6554         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6555         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6556         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6557         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6558         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6559         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6560         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6561         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6562         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6563         {
6564                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6565                 /* .name = "Capture Source", */
6566                 .name = "Input Source",
6567                 .count = 2,
6568                 .info = alc883_mux_enum_info,
6569                 .get = alc883_mux_enum_get,
6570                 .put = alc883_mux_enum_put,
6571         },
6572         { } /* end */
6573 };
6574
6575 static struct snd_kcontrol_new alc883_tagra_2ch_mixer[] = {
6576         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6577         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6578         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6579         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6580         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6581         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6582         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6583         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6584         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6585         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6586         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6587         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6588         {
6589                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6590                 /* .name = "Capture Source", */
6591                 .name = "Input Source",
6592                 .count = 2,
6593                 .info = alc883_mux_enum_info,
6594                 .get = alc883_mux_enum_get,
6595                 .put = alc883_mux_enum_put,
6596         },
6597         { } /* end */
6598 };
6599
6600 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
6601         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6602         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6603         HDA_CODEC_VOLUME("iSpeaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6604         HDA_BIND_MUTE("iSpeaker Playback Switch", 0x0d, 2, HDA_INPUT),
6605         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6606         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6607         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6608         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6609         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6610         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6611         {
6612                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6613                 /* .name = "Capture Source", */
6614                 .name = "Input Source",
6615                 .count = 1,
6616                 .info = alc883_mux_enum_info,
6617                 .get = alc883_mux_enum_get,
6618                 .put = alc883_mux_enum_put,
6619         },
6620         { } /* end */
6621 };
6622
6623 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
6624         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6625         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
6626         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6627         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6628         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6629         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6630         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6631         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6632         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6633         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6634         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6635         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6636         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6637         {
6638                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6639                 /* .name = "Capture Source", */
6640                 .name = "Input Source",
6641                 .count = 2,
6642                 .info = alc883_mux_enum_info,
6643                 .get = alc883_mux_enum_get,
6644                 .put = alc883_mux_enum_put,
6645         },
6646         { } /* end */
6647 };
6648
6649 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
6650         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6651         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6652         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6653         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6654         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6655         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6656         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6657         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6658         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6659         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6660         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6661         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6662         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6663         {
6664                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6665                 /* .name = "Capture Source", */
6666                 .name = "Input Source",
6667                 .count = 2,
6668                 .info = alc883_mux_enum_info,
6669                 .get = alc883_mux_enum_get,
6670                 .put = alc883_mux_enum_put,
6671         },
6672         { } /* end */
6673 };      
6674
6675 static struct snd_kcontrol_new alc888_6st_hp_mixer[] = {
6676         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6677         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6678         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
6679         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
6680         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
6681         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
6682         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
6683         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
6684         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6685         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6686         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6687         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6688         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6689         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6690         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6691         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6692         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6693         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6694         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6695         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6696         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6697         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6698         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6699         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6700         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6701         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6702         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6703         {
6704                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6705                 /* .name = "Capture Source", */
6706                 .name = "Input Source",
6707                 .count = 2,
6708                 .info = alc883_mux_enum_info,
6709                 .get = alc883_mux_enum_get,
6710                 .put = alc883_mux_enum_put,
6711         },
6712         { } /* end */
6713 };
6714
6715 static struct snd_kcontrol_new alc888_3st_hp_mixer[] = {
6716         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6717         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6718         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
6719         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
6720         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
6721         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
6722         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
6723         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
6724         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6725         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6726         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6727         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6728         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6729         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6730         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6731         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6732         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6733         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6734         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6735         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6736         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6737         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6738         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6739         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6740         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6741         {
6742                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6743                 /* .name = "Capture Source", */
6744                 .name = "Input Source",
6745                 .count = 2,
6746                 .info = alc883_mux_enum_info,
6747                 .get = alc883_mux_enum_get,
6748                 .put = alc883_mux_enum_put,
6749         },
6750         { } /* end */
6751 };
6752
6753 static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
6754         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6755         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6756         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6757         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6758         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6759         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6760         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6761         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6762         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6763         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6764         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6765         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6766         {
6767                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6768                 /* .name = "Capture Source", */
6769                 .name = "Input Source",
6770                 .count = 2,
6771                 .info = alc883_mux_enum_info,
6772                 .get = alc883_mux_enum_get,
6773                 .put = alc883_mux_enum_put,
6774         },
6775         { } /* end */
6776 };
6777
6778 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
6779         {
6780                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6781                 .name = "Channel Mode",
6782                 .info = alc_ch_mode_info,
6783                 .get = alc_ch_mode_get,
6784                 .put = alc_ch_mode_put,
6785         },
6786         { } /* end */
6787 };
6788
6789 static struct hda_verb alc883_init_verbs[] = {
6790         /* ADC1: mute amp left and right */
6791         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6792         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6793         /* ADC2: mute amp left and right */
6794         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6795         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6796         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6797         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6798         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6799         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6800         /* Rear mixer */
6801         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6802         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6803         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6804         /* CLFE mixer */
6805         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6806         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6807         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6808         /* Side mixer */
6809         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6810         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6811         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6812
6813         /* mute analog input loopbacks */
6814         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6815         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6816         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6817         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6818         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6819
6820         /* Front Pin: output 0 (0x0c) */
6821         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6822         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6823         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6824         /* Rear Pin: output 1 (0x0d) */
6825         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6826         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6827         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
6828         /* CLFE Pin: output 2 (0x0e) */
6829         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6830         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6831         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
6832         /* Side Pin: output 3 (0x0f) */
6833         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6834         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6835         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
6836         /* Mic (rear) pin: input vref at 80% */
6837         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6838         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6839         /* Front Mic pin: input vref at 80% */
6840         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6841         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6842         /* Line In pin: input */
6843         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6844         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6845         /* Line-2 In: Headphone output (output 0 - 0x0c) */
6846         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6847         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6848         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
6849         /* CD pin widget for input */
6850         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6851
6852         /* FIXME: use matrix-type input source selection */
6853         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6854         /* Input mixer2 */
6855         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6856         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6857         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6858         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
6859         /* Input mixer3 */
6860         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6861         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6862         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6863         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
6864         { }
6865 };
6866
6867 /* toggle speaker-output according to the hp-jack state */
6868 static void alc883_mitac_hp_automute(struct hda_codec *codec)
6869 {
6870         unsigned int present;
6871
6872         present = snd_hda_codec_read(codec, 0x15, 0,
6873                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6874         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
6875                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6876         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
6877                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6878 }
6879
6880 /* auto-toggle front mic */
6881 /*
6882 static void alc883_mitac_mic_automute(struct hda_codec *codec)
6883 {
6884         unsigned int present;
6885         unsigned char bits;
6886
6887         present = snd_hda_codec_read(codec, 0x18, 0,
6888                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6889         bits = present ? HDA_AMP_MUTE : 0;
6890         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
6891 }
6892 */
6893
6894 static void alc883_mitac_automute(struct hda_codec *codec)
6895 {
6896         alc883_mitac_hp_automute(codec);
6897         /* alc883_mitac_mic_automute(codec); */
6898 }
6899
6900 static void alc883_mitac_unsol_event(struct hda_codec *codec,
6901                                            unsigned int res)
6902 {
6903         switch (res >> 26) {
6904         case ALC880_HP_EVENT:
6905                 alc883_mitac_hp_automute(codec);
6906                 break;
6907         case ALC880_MIC_EVENT:
6908                 /* alc883_mitac_mic_automute(codec); */
6909                 break;
6910         }
6911 }
6912
6913 static struct hda_verb alc883_mitac_verbs[] = {
6914         /* HP */
6915         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6916         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6917         /* Subwoofer */
6918         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
6919         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6920
6921         /* enable unsolicited event */
6922         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6923         /* {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN}, */
6924
6925         { } /* end */
6926 };
6927
6928 static struct hda_verb alc883_tagra_verbs[] = {
6929         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6930         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6931
6932         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6933         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6934         
6935         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6936         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6937         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6938
6939         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6940         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6941         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
6942         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
6943
6944         { } /* end */
6945 };
6946
6947 static struct hda_verb alc883_lenovo_101e_verbs[] = {
6948         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6949         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
6950         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
6951         { } /* end */
6952 };
6953
6954 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
6955         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6956         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6957         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6958         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6959         { } /* end */
6960 };
6961
6962 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
6963         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6964         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6965         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6966         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
6967         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
6968         { } /* end */
6969 };
6970
6971 static struct hda_verb alc883_haier_w66_verbs[] = {
6972         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6973         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6974
6975         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6976
6977         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
6978         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6979         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6980         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6981         { } /* end */
6982 };
6983
6984 static struct hda_verb alc888_6st_hp_verbs[] = {
6985         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
6986         {0x15, AC_VERB_SET_CONNECT_SEL, 0x02},  /* Rear : output 2 (0x0e) */
6987         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* CLFE : output 1 (0x0d) */
6988         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},  /* Side : output 3 (0x0f) */
6989         { }
6990 };
6991
6992 static struct hda_verb alc888_3st_hp_verbs[] = {
6993         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
6994         {0x18, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
6995         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
6996         { }
6997 };
6998
6999 static struct hda_verb alc888_3st_hp_2ch_init[] = {
7000         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7001         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7002         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7003         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7004         { }
7005 };
7006
7007 static struct hda_verb alc888_3st_hp_6ch_init[] = {
7008         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7009         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7010         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7011         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7012         { }
7013 };
7014
7015 static struct hda_channel_mode alc888_3st_hp_modes[2] = {
7016         { 2, alc888_3st_hp_2ch_init },
7017         { 6, alc888_3st_hp_6ch_init },
7018 };
7019
7020 /* toggle front-jack and RCA according to the hp-jack state */
7021 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
7022 {
7023         unsigned int present;
7024  
7025         present = snd_hda_codec_read(codec, 0x1b, 0,
7026                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7027         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7028                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7029         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7030                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7031 }
7032
7033 /* toggle RCA according to the front-jack state */
7034 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
7035 {
7036         unsigned int present;
7037  
7038         present = snd_hda_codec_read(codec, 0x14, 0,
7039                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7040         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7041                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7042 }
7043
7044 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
7045                                              unsigned int res)
7046 {
7047         if ((res >> 26) == ALC880_HP_EVENT)
7048                 alc888_lenovo_ms7195_front_automute(codec);
7049         if ((res >> 26) == ALC880_FRONT_EVENT)
7050                 alc888_lenovo_ms7195_rca_automute(codec);
7051 }
7052
7053 static struct hda_verb alc883_medion_md2_verbs[] = {
7054         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7055         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7056
7057         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7058
7059         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7060         { } /* end */
7061 };
7062
7063 /* toggle speaker-output according to the hp-jack state */
7064 static void alc883_medion_md2_automute(struct hda_codec *codec)
7065 {
7066         unsigned int present;
7067  
7068         present = snd_hda_codec_read(codec, 0x14, 0,
7069                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7070         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7071                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7072 }
7073
7074 static void alc883_medion_md2_unsol_event(struct hda_codec *codec,
7075                                           unsigned int res)
7076 {
7077         if ((res >> 26) == ALC880_HP_EVENT)
7078                 alc883_medion_md2_automute(codec);
7079 }
7080
7081 /* toggle speaker-output according to the hp-jack state */
7082 static void alc883_tagra_automute(struct hda_codec *codec)
7083 {
7084         unsigned int present;
7085         unsigned char bits;
7086
7087         present = snd_hda_codec_read(codec, 0x14, 0,
7088                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7089         bits = present ? HDA_AMP_MUTE : 0;
7090         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
7091                                  HDA_AMP_MUTE, bits);
7092         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
7093                                   present ? 1 : 3);
7094 }
7095
7096 static void alc883_tagra_unsol_event(struct hda_codec *codec, unsigned int res)
7097 {
7098         if ((res >> 26) == ALC880_HP_EVENT)
7099                 alc883_tagra_automute(codec);
7100 }
7101
7102 static void alc883_haier_w66_automute(struct hda_codec *codec)
7103 {
7104         unsigned int present;
7105         unsigned char bits;
7106
7107         present = snd_hda_codec_read(codec, 0x1b, 0,
7108                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7109         bits = present ? 0x80 : 0;
7110         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7111                                  0x80, bits);
7112 }
7113
7114 static void alc883_haier_w66_unsol_event(struct hda_codec *codec,
7115                                          unsigned int res)
7116 {
7117         if ((res >> 26) == ALC880_HP_EVENT)
7118                 alc883_haier_w66_automute(codec);
7119 }
7120
7121 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
7122 {
7123         unsigned int present;
7124         unsigned char bits;
7125
7126         present = snd_hda_codec_read(codec, 0x14, 0,
7127                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7128         bits = present ? HDA_AMP_MUTE : 0;
7129         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7130                                  HDA_AMP_MUTE, bits);
7131 }
7132
7133 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
7134 {
7135         unsigned int present;
7136         unsigned char bits;
7137
7138         present = snd_hda_codec_read(codec, 0x1b, 0,
7139                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7140         bits = present ? HDA_AMP_MUTE : 0;
7141         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7142                                  HDA_AMP_MUTE, bits);
7143         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7144                                  HDA_AMP_MUTE, bits);
7145 }
7146
7147 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
7148                                            unsigned int res)
7149 {
7150         if ((res >> 26) == ALC880_HP_EVENT)
7151                 alc883_lenovo_101e_all_automute(codec);
7152         if ((res >> 26) == ALC880_FRONT_EVENT)
7153                 alc883_lenovo_101e_ispeaker_automute(codec);
7154 }
7155
7156 /* toggle speaker-output according to the hp-jack state */
7157 static void alc883_acer_aspire_automute(struct hda_codec *codec)
7158 {
7159         unsigned int present;
7160  
7161         present = snd_hda_codec_read(codec, 0x14, 0,
7162                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7163         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7164                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7165         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
7166                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7167 }
7168
7169 static void alc883_acer_aspire_unsol_event(struct hda_codec *codec,
7170                                            unsigned int res)
7171 {
7172         if ((res >> 26) == ALC880_HP_EVENT)
7173                 alc883_acer_aspire_automute(codec);
7174 }
7175
7176 static struct hda_verb alc883_acer_eapd_verbs[] = {
7177         /* HP Pin: output 0 (0x0c) */
7178         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7179         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7180         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7181         /* Front Pin: output 0 (0x0c) */
7182         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7183         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7184         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7185         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
7186         /* eanable EAPD on medion laptop */
7187         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7188         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
7189         /* enable unsolicited event */
7190         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7191         { }
7192 };
7193
7194 /*
7195  * generic initialization of ADC, input mixers and output mixers
7196  */
7197 static struct hda_verb alc883_auto_init_verbs[] = {
7198         /*
7199          * Unmute ADC0-2 and set the default input to mic-in
7200          */
7201         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7202         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7203         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7204         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7205
7206         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
7207          * mixer widget
7208          * Note: PASD motherboards uses the Line In 2 as the input for
7209          * front panel mic (mic 2)
7210          */
7211         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
7212         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7213         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7214         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7215         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7216         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7217
7218         /*
7219          * Set up output mixers (0x0c - 0x0f)
7220          */
7221         /* set vol=0 to output mixers */
7222         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7223         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7224         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7225         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7226         /* set up input amps for analog loopback */
7227         /* Amp Indices: DAC = 0, mixer = 1 */
7228         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7229         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7230         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7231         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7232         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7233         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7234         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7235         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7236         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7237         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7238
7239         /* FIXME: use matrix-type input source selection */
7240         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7241         /* Input mixer1 */
7242         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7243         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7244         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7245         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
7246         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7247         /* Input mixer2 */
7248         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7249         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7250         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7251         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
7252         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7253
7254         { }
7255 };
7256
7257 /* capture mixer elements */
7258 static struct snd_kcontrol_new alc883_capture_mixer[] = {
7259         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7260         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7261         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7262         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7263         {
7264                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7265                 /* The multiple "Capture Source" controls confuse alsamixer
7266                  * So call somewhat different..
7267                  * FIXME: the controls appear in the "playback" view!
7268                  */
7269                 /* .name = "Capture Source", */
7270                 .name = "Input Source",
7271                 .count = 2,
7272                 .info = alc882_mux_enum_info,
7273                 .get = alc882_mux_enum_get,
7274                 .put = alc882_mux_enum_put,
7275         },
7276         { } /* end */
7277 };
7278
7279 #ifdef CONFIG_SND_HDA_POWER_SAVE
7280 #define alc883_loopbacks        alc880_loopbacks
7281 #endif
7282
7283 /* pcm configuration: identiacal with ALC880 */
7284 #define alc883_pcm_analog_playback      alc880_pcm_analog_playback
7285 #define alc883_pcm_analog_capture       alc880_pcm_analog_capture
7286 #define alc883_pcm_digital_playback     alc880_pcm_digital_playback
7287 #define alc883_pcm_digital_capture      alc880_pcm_digital_capture
7288
7289 /*
7290  * configuration and preset
7291  */
7292 static const char *alc883_models[ALC883_MODEL_LAST] = {
7293         [ALC883_3ST_2ch_DIG]    = "3stack-dig",
7294         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
7295         [ALC883_3ST_6ch]        = "3stack-6ch",
7296         [ALC883_6ST_DIG]        = "6stack-dig",
7297         [ALC883_TARGA_DIG]      = "targa-dig",
7298         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
7299         [ALC883_ACER]           = "acer",
7300         [ALC883_ACER_ASPIRE]    = "acer-aspire",
7301         [ALC883_MEDION]         = "medion",
7302         [ALC883_MEDION_MD2]     = "medion-md2",
7303         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
7304         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
7305         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
7306         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
7307         [ALC883_HAIER_W66]      = "haier-w66",
7308         [ALC888_6ST_HP]         = "6stack-hp",
7309         [ALC888_3ST_HP]         = "3stack-hp",
7310         [ALC883_MITAC]          = "mitac",
7311         [ALC883_AUTO]           = "auto",
7312 };
7313
7314 static struct snd_pci_quirk alc883_cfg_tbl[] = {
7315         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG),
7316         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
7317         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
7318         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
7319         SND_PCI_QUIRK(0x1025, 0, "Acer laptop", ALC883_ACER), /* default Acer */
7320         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
7321         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
7322         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
7323         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC888_6ST_HP),
7324         SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
7325         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
7326         SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
7327         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
7328         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
7329         SND_PCI_QUIRK(0x1458, 0xa002, "MSI", ALC883_6ST_DIG),
7330         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
7331         SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
7332         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
7333         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
7334         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
7335         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
7336         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
7337         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
7338         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
7339         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
7340         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
7341         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
7342         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
7343         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
7344         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
7345         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
7346         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
7347         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
7348         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
7349         SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
7350         SND_PCI_QUIRK(0x1558, 0, "Clevo laptop", ALC883_LAPTOP_EAPD),
7351         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
7352         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
7353         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
7354         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
7355         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
7356         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
7357         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
7358         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
7359         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
7360         {}
7361 };
7362
7363 static struct alc_config_preset alc883_presets[] = {
7364         [ALC883_3ST_2ch_DIG] = {
7365                 .mixers = { alc883_3ST_2ch_mixer },
7366                 .init_verbs = { alc883_init_verbs },
7367                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7368                 .dac_nids = alc883_dac_nids,
7369                 .dig_out_nid = ALC883_DIGOUT_NID,
7370                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7371                 .adc_nids = alc883_adc_nids,
7372                 .dig_in_nid = ALC883_DIGIN_NID,
7373                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7374                 .channel_mode = alc883_3ST_2ch_modes,
7375                 .input_mux = &alc883_capture_source,
7376         },
7377         [ALC883_3ST_6ch_DIG] = {
7378                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
7379                 .init_verbs = { alc883_init_verbs },
7380                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7381                 .dac_nids = alc883_dac_nids,
7382                 .dig_out_nid = ALC883_DIGOUT_NID,
7383                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7384                 .adc_nids = alc883_adc_nids,
7385                 .dig_in_nid = ALC883_DIGIN_NID,
7386                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7387                 .channel_mode = alc883_3ST_6ch_modes,
7388                 .need_dac_fix = 1,
7389                 .input_mux = &alc883_capture_source,
7390         },
7391         [ALC883_3ST_6ch] = {
7392                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
7393                 .init_verbs = { alc883_init_verbs },
7394                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7395                 .dac_nids = alc883_dac_nids,
7396                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7397                 .adc_nids = alc883_adc_nids,
7398                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7399                 .channel_mode = alc883_3ST_6ch_modes,
7400                 .need_dac_fix = 1,
7401                 .input_mux = &alc883_capture_source,
7402         },
7403         [ALC883_6ST_DIG] = {
7404                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
7405                 .init_verbs = { alc883_init_verbs },
7406                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7407                 .dac_nids = alc883_dac_nids,
7408                 .dig_out_nid = ALC883_DIGOUT_NID,
7409                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7410                 .adc_nids = alc883_adc_nids,
7411                 .dig_in_nid = ALC883_DIGIN_NID,
7412                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7413                 .channel_mode = alc883_sixstack_modes,
7414                 .input_mux = &alc883_capture_source,
7415         },
7416         [ALC883_TARGA_DIG] = {
7417                 .mixers = { alc883_tagra_mixer, alc883_chmode_mixer },
7418                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
7419                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7420                 .dac_nids = alc883_dac_nids,
7421                 .dig_out_nid = ALC883_DIGOUT_NID,
7422                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7423                 .adc_nids = alc883_adc_nids,
7424                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7425                 .channel_mode = alc883_3ST_6ch_modes,
7426                 .need_dac_fix = 1,
7427                 .input_mux = &alc883_capture_source,
7428                 .unsol_event = alc883_tagra_unsol_event,
7429                 .init_hook = alc883_tagra_automute,
7430         },
7431         [ALC883_TARGA_2ch_DIG] = {
7432                 .mixers = { alc883_tagra_2ch_mixer},
7433                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
7434                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7435                 .dac_nids = alc883_dac_nids,
7436                 .dig_out_nid = ALC883_DIGOUT_NID,
7437                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7438                 .adc_nids = alc883_adc_nids,
7439                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7440                 .channel_mode = alc883_3ST_2ch_modes,
7441                 .input_mux = &alc883_capture_source,
7442                 .unsol_event = alc883_tagra_unsol_event,
7443                 .init_hook = alc883_tagra_automute,
7444         },
7445         [ALC883_ACER] = {
7446                 .mixers = { alc883_base_mixer },
7447                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
7448                  * and the headphone jack.  Turn this on and rely on the
7449                  * standard mute methods whenever the user wants to turn
7450                  * these outputs off.
7451                  */
7452                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
7453                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7454                 .dac_nids = alc883_dac_nids,
7455                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7456                 .adc_nids = alc883_adc_nids,
7457                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7458                 .channel_mode = alc883_3ST_2ch_modes,
7459                 .input_mux = &alc883_capture_source,
7460         },
7461         [ALC883_ACER_ASPIRE] = {
7462                 .mixers = { alc883_acer_aspire_mixer },
7463                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
7464                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7465                 .dac_nids = alc883_dac_nids,
7466                 .dig_out_nid = ALC883_DIGOUT_NID,
7467                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7468                 .adc_nids = alc883_adc_nids,
7469                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7470                 .channel_mode = alc883_3ST_2ch_modes,
7471                 .input_mux = &alc883_capture_source,
7472                 .unsol_event = alc883_acer_aspire_unsol_event,
7473                 .init_hook = alc883_acer_aspire_automute,
7474         },
7475         [ALC883_MEDION] = {
7476                 .mixers = { alc883_fivestack_mixer,
7477                             alc883_chmode_mixer },
7478                 .init_verbs = { alc883_init_verbs,
7479                                 alc883_medion_eapd_verbs },
7480                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7481                 .dac_nids = alc883_dac_nids,
7482                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7483                 .adc_nids = alc883_adc_nids,
7484                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7485                 .channel_mode = alc883_sixstack_modes,
7486                 .input_mux = &alc883_capture_source,
7487         },
7488         [ALC883_MEDION_MD2] = {
7489                 .mixers = { alc883_medion_md2_mixer},
7490                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
7491                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7492                 .dac_nids = alc883_dac_nids,
7493                 .dig_out_nid = ALC883_DIGOUT_NID,
7494                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7495                 .adc_nids = alc883_adc_nids,
7496                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7497                 .channel_mode = alc883_3ST_2ch_modes,
7498                 .input_mux = &alc883_capture_source,
7499                 .unsol_event = alc883_medion_md2_unsol_event,
7500                 .init_hook = alc883_medion_md2_automute,
7501         },      
7502         [ALC883_LAPTOP_EAPD] = {
7503                 .mixers = { alc883_base_mixer },
7504                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
7505                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7506                 .dac_nids = alc883_dac_nids,
7507                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7508                 .adc_nids = alc883_adc_nids,
7509                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7510                 .channel_mode = alc883_3ST_2ch_modes,
7511                 .input_mux = &alc883_capture_source,
7512         },
7513         [ALC883_LENOVO_101E_2ch] = {
7514                 .mixers = { alc883_lenovo_101e_2ch_mixer},
7515                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
7516                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7517                 .dac_nids = alc883_dac_nids,
7518                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7519                 .adc_nids = alc883_adc_nids,
7520                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7521                 .channel_mode = alc883_3ST_2ch_modes,
7522                 .input_mux = &alc883_lenovo_101e_capture_source,
7523                 .unsol_event = alc883_lenovo_101e_unsol_event,
7524                 .init_hook = alc883_lenovo_101e_all_automute,
7525         },
7526         [ALC883_LENOVO_NB0763] = {
7527                 .mixers = { alc883_lenovo_nb0763_mixer },
7528                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
7529                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7530                 .dac_nids = alc883_dac_nids,
7531                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7532                 .adc_nids = alc883_adc_nids,
7533                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7534                 .channel_mode = alc883_3ST_2ch_modes,
7535                 .need_dac_fix = 1,
7536                 .input_mux = &alc883_lenovo_nb0763_capture_source,
7537                 .unsol_event = alc883_medion_md2_unsol_event,
7538                 .init_hook = alc883_medion_md2_automute,
7539         },
7540         [ALC888_LENOVO_MS7195_DIG] = {
7541                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
7542                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
7543                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7544                 .dac_nids = alc883_dac_nids,
7545                 .dig_out_nid = ALC883_DIGOUT_NID,
7546                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7547                 .adc_nids = alc883_adc_nids,
7548                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7549                 .channel_mode = alc883_3ST_6ch_modes,
7550                 .need_dac_fix = 1,
7551                 .input_mux = &alc883_capture_source,
7552                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
7553                 .init_hook = alc888_lenovo_ms7195_front_automute,
7554         },
7555         [ALC883_HAIER_W66] = {
7556                 .mixers = { alc883_tagra_2ch_mixer},
7557                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
7558                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7559                 .dac_nids = alc883_dac_nids,
7560                 .dig_out_nid = ALC883_DIGOUT_NID,
7561                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7562                 .adc_nids = alc883_adc_nids,
7563                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7564                 .channel_mode = alc883_3ST_2ch_modes,
7565                 .input_mux = &alc883_capture_source,
7566                 .unsol_event = alc883_haier_w66_unsol_event,
7567                 .init_hook = alc883_haier_w66_automute,
7568         },      
7569         [ALC888_6ST_HP] = {
7570                 .mixers = { alc888_6st_hp_mixer, alc883_chmode_mixer },
7571                 .init_verbs = { alc883_init_verbs, alc888_6st_hp_verbs },
7572                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7573                 .dac_nids = alc883_dac_nids,
7574                 .dig_out_nid = ALC883_DIGOUT_NID,
7575                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7576                 .adc_nids = alc883_adc_nids,
7577                 .dig_in_nid = ALC883_DIGIN_NID,
7578                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7579                 .channel_mode = alc883_sixstack_modes,
7580                 .input_mux = &alc883_capture_source,
7581         },
7582         [ALC888_3ST_HP] = {
7583                 .mixers = { alc888_3st_hp_mixer, alc883_chmode_mixer },
7584                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
7585                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7586                 .dac_nids = alc883_dac_nids,
7587                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7588                 .adc_nids = alc883_adc_nids,
7589                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
7590                 .channel_mode = alc888_3st_hp_modes,
7591                 .need_dac_fix = 1,
7592                 .input_mux = &alc883_capture_source,
7593         },
7594         [ALC883_MITAC] = {
7595                 .mixers = { alc883_mitac_mixer },
7596                 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
7597                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7598                 .dac_nids = alc883_dac_nids,
7599                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7600                 .adc_nids = alc883_adc_nids,
7601                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7602                 .channel_mode = alc883_3ST_2ch_modes,
7603                 .input_mux = &alc883_capture_source,
7604                 .unsol_event = alc883_mitac_unsol_event,
7605                 .init_hook = alc883_mitac_automute,
7606         },
7607 };
7608
7609
7610 /*
7611  * BIOS auto configuration
7612  */
7613 static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
7614                                               hda_nid_t nid, int pin_type,
7615                                               int dac_idx)
7616 {
7617         /* set as output */
7618         struct alc_spec *spec = codec->spec;
7619         int idx;
7620
7621         if (spec->multiout.dac_nids[dac_idx] == 0x25)
7622                 idx = 4;
7623         else
7624                 idx = spec->multiout.dac_nids[dac_idx] - 2;
7625
7626         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
7627                             pin_type);
7628         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
7629                             AMP_OUT_UNMUTE);
7630         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
7631
7632 }
7633
7634 static void alc883_auto_init_multi_out(struct hda_codec *codec)
7635 {
7636         struct alc_spec *spec = codec->spec;
7637         int i;
7638
7639         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
7640         for (i = 0; i <= HDA_SIDE; i++) {
7641                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
7642                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
7643                 if (nid)
7644                         alc883_auto_set_output_and_unmute(codec, nid, pin_type,
7645                                                           i);
7646         }
7647 }
7648
7649 static void alc883_auto_init_hp_out(struct hda_codec *codec)
7650 {
7651         struct alc_spec *spec = codec->spec;
7652         hda_nid_t pin;
7653
7654         pin = spec->autocfg.hp_pins[0];
7655         if (pin) /* connect to front */
7656                 /* use dac 0 */
7657                 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
7658 }
7659
7660 #define alc883_is_input_pin(nid)        alc880_is_input_pin(nid)
7661 #define ALC883_PIN_CD_NID               ALC880_PIN_CD_NID
7662
7663 static void alc883_auto_init_analog_input(struct hda_codec *codec)
7664 {
7665         struct alc_spec *spec = codec->spec;
7666         int i;
7667
7668         for (i = 0; i < AUTO_PIN_LAST; i++) {
7669                 hda_nid_t nid = spec->autocfg.input_pins[i];
7670                 if (alc883_is_input_pin(nid)) {
7671                         snd_hda_codec_write(codec, nid, 0,
7672                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
7673                                             (i <= AUTO_PIN_FRONT_MIC ?
7674                                              PIN_VREF80 : PIN_IN));
7675                         if (nid != ALC883_PIN_CD_NID)
7676                                 snd_hda_codec_write(codec, nid, 0,
7677                                                     AC_VERB_SET_AMP_GAIN_MUTE,
7678                                                     AMP_OUT_MUTE);
7679                 }
7680         }
7681 }
7682
7683 /* almost identical with ALC880 parser... */
7684 static int alc883_parse_auto_config(struct hda_codec *codec)
7685 {
7686         struct alc_spec *spec = codec->spec;
7687         int err = alc880_parse_auto_config(codec);
7688
7689         if (err < 0)
7690                 return err;
7691         else if (!err)
7692                 return 0; /* no config found */
7693
7694         err = alc_auto_add_mic_boost(codec);
7695         if (err < 0)
7696                 return err;
7697
7698         /* hack - override the init verbs */
7699         spec->init_verbs[0] = alc883_auto_init_verbs;
7700         spec->mixers[spec->num_mixers] = alc883_capture_mixer;
7701         spec->num_mixers++;
7702
7703         return 1; /* config found */
7704 }
7705
7706 /* additional initialization for auto-configuration model */
7707 static void alc883_auto_init(struct hda_codec *codec)
7708 {
7709         alc883_auto_init_multi_out(codec);
7710         alc883_auto_init_hp_out(codec);
7711         alc883_auto_init_analog_input(codec);
7712 }
7713
7714 static int patch_alc883(struct hda_codec *codec)
7715 {
7716         struct alc_spec *spec;
7717         int err, board_config;
7718
7719         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
7720         if (spec == NULL)
7721                 return -ENOMEM;
7722
7723         codec->spec = spec;
7724
7725         board_config = snd_hda_check_board_config(codec, ALC883_MODEL_LAST,
7726                                                   alc883_models,
7727                                                   alc883_cfg_tbl);
7728         if (board_config < 0) {
7729                 printk(KERN_INFO "hda_codec: Unknown model for ALC883, "
7730                        "trying auto-probe from BIOS...\n");
7731                 board_config = ALC883_AUTO;
7732         }
7733
7734         if (board_config == ALC883_AUTO) {
7735                 /* automatic parse from the BIOS config */
7736                 err = alc883_parse_auto_config(codec);
7737                 if (err < 0) {
7738                         alc_free(codec);
7739                         return err;
7740                 } else if (!err) {
7741                         printk(KERN_INFO
7742                                "hda_codec: Cannot set up configuration "
7743                                "from BIOS.  Using base mode...\n");
7744                         board_config = ALC883_3ST_2ch_DIG;
7745                 }
7746         }
7747
7748         if (board_config != ALC883_AUTO)
7749                 setup_preset(spec, &alc883_presets[board_config]);
7750
7751         spec->stream_name_analog = "ALC883 Analog";
7752         spec->stream_analog_playback = &alc883_pcm_analog_playback;
7753         spec->stream_analog_capture = &alc883_pcm_analog_capture;
7754
7755         spec->stream_name_digital = "ALC883 Digital";
7756         spec->stream_digital_playback = &alc883_pcm_digital_playback;
7757         spec->stream_digital_capture = &alc883_pcm_digital_capture;
7758
7759         if (!spec->adc_nids && spec->input_mux) {
7760                 spec->adc_nids = alc883_adc_nids;
7761                 spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
7762         }
7763
7764         codec->patch_ops = alc_patch_ops;
7765         if (board_config == ALC883_AUTO)
7766                 spec->init_hook = alc883_auto_init;
7767 #ifdef CONFIG_SND_HDA_POWER_SAVE
7768         if (!spec->loopback.amplist)
7769                 spec->loopback.amplist = alc883_loopbacks;
7770 #endif
7771
7772         return 0;
7773 }
7774
7775 /*
7776  * ALC262 support
7777  */
7778
7779 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
7780 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
7781
7782 #define alc262_dac_nids         alc260_dac_nids
7783 #define alc262_adc_nids         alc882_adc_nids
7784 #define alc262_adc_nids_alt     alc882_adc_nids_alt
7785
7786 #define alc262_modes            alc260_modes
7787 #define alc262_capture_source   alc882_capture_source
7788
7789 static struct snd_kcontrol_new alc262_base_mixer[] = {
7790         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7791         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7792         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7793         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7794         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7795         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7796         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7797         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7798         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7799         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
7800         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
7801         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7802         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
7803            HDA_CODEC_MUTE("PC Beelp Playback Switch", 0x0b, 0x05, HDA_INPUT), */
7804         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
7805         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7806         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7807         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
7808         { } /* end */
7809 };
7810
7811 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
7812         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7813         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7814         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7815         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7816         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7817         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7818         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7819         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7820         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7821         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
7822         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
7823         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7824         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
7825            HDA_CODEC_MUTE("PC Beelp Playback Switch", 0x0b, 0x05, HDA_INPUT), */
7826         /*HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),*/
7827         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7828         { } /* end */
7829 };
7830
7831 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
7832         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7833         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7834         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7835         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7836         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
7837
7838         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7839         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7840         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7841         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
7842         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
7843         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7844         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7845         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7846         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7847         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7848         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
7849         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
7850         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
7851         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
7852         { } /* end */
7853 };
7854
7855 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
7856         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7857         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7858         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7859         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7860         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7861         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
7862         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
7863         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
7864         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
7865         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
7866         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
7867         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7868         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7869         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
7870         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
7871         { } /* end */
7872 };
7873
7874 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
7875         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7876         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7877         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
7878         { } /* end */
7879 };
7880
7881 static struct hda_bind_ctls alc262_hp_t5735_bind_front_vol = {
7882         .ops = &snd_hda_bind_vol,
7883         .values = {
7884                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
7885                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
7886                 0
7887         },
7888 };
7889
7890 static struct hda_bind_ctls alc262_hp_t5735_bind_front_sw = {
7891         .ops = &snd_hda_bind_sw,
7892         .values = {
7893                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
7894                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
7895                 0
7896         },
7897 };
7898
7899 /* mute/unmute internal speaker according to the hp jack and mute state */
7900 static void alc262_hp_t5735_automute(struct hda_codec *codec, int force)
7901 {
7902         struct alc_spec *spec = codec->spec;
7903         unsigned int mute;
7904
7905         if (force || !spec->sense_updated) {
7906                 unsigned int present;
7907                 present = snd_hda_codec_read(codec, 0x15, 0,
7908                                              AC_VERB_GET_PIN_SENSE, 0);
7909                 spec->jack_present = (present & 0x80000000) != 0;
7910                 spec->sense_updated = 1;
7911         }
7912         if (spec->jack_present)
7913                 mute = (0x7080 | ((0)<<8));  /* mute internal speaker */
7914         else    /* unmute internal speaker if necessary */
7915                 mute = (0x7000 | ((0)<<8));
7916         snd_hda_codec_write(codec, 0x0c, 0,
7917                             AC_VERB_SET_AMP_GAIN_MUTE, mute );
7918 }
7919
7920 static void alc262_hp_t5735_unsol_event(struct hda_codec *codec,
7921                                         unsigned int res)
7922 {
7923         if ((res >> 26) != ALC880_HP_EVENT)
7924                 return;
7925         alc262_hp_t5735_automute(codec, 1);
7926 }
7927
7928 static void alc262_hp_t5735_init_hook(struct hda_codec *codec)
7929 {
7930         alc262_hp_t5735_automute(codec, 1);
7931 }
7932
7933 static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
7934         HDA_BIND_VOL("PCM Playback Volume", &alc262_hp_t5735_bind_front_vol),
7935         HDA_BIND_SW("PCM Playback Switch",&alc262_hp_t5735_bind_front_sw),
7936         HDA_CODEC_VOLUME("LineOut Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7937         HDA_CODEC_MUTE("LineOut Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7938         HDA_CODEC_VOLUME("iSpeaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7939         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7940         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7941         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7942         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7943         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7944         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7945         { } /* end */
7946 };
7947
7948 static struct hda_verb alc262_hp_t5735_verbs[] = {
7949         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7950         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7951
7952         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7953         { }
7954 };
7955
7956 /* bind hp and internal speaker mute (with plug check) */
7957 static int alc262_sony_master_sw_put(struct snd_kcontrol *kcontrol,
7958                                      struct snd_ctl_elem_value *ucontrol)
7959 {
7960         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
7961         long *valp = ucontrol->value.integer.value;
7962         int change;
7963
7964         /* change hp mute */
7965         change = snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
7966                                           HDA_AMP_MUTE,
7967                                           valp[0] ? 0 : HDA_AMP_MUTE);
7968         change |= snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
7969                                            HDA_AMP_MUTE,
7970                                            valp[1] ? 0 : HDA_AMP_MUTE);
7971         if (change) {
7972                 /* change speaker according to HP jack state */
7973                 struct alc_spec *spec = codec->spec;
7974                 unsigned int mute;
7975                 if (spec->jack_present)
7976                         mute = HDA_AMP_MUTE;
7977                 else
7978                         mute = snd_hda_codec_amp_read(codec, 0x15, 0,
7979                                                       HDA_OUTPUT, 0);
7980                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7981                                          HDA_AMP_MUTE, mute);
7982         }
7983         return change;
7984 }
7985
7986 static struct snd_kcontrol_new alc262_sony_mixer[] = {
7987         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7988         {
7989                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7990                 .name = "Master Playback Switch",
7991                 .info = snd_hda_mixer_amp_switch_info,
7992                 .get = snd_hda_mixer_amp_switch_get,
7993                 .put = alc262_sony_master_sw_put,
7994                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
7995         },
7996         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7997         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7998         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
7999         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8000         { } /* end */
8001 };
8002
8003 static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
8004         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8005         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8006         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8007         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8008         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8009         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8010         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8011         { } /* end */
8012 };
8013
8014 #define alc262_capture_mixer            alc882_capture_mixer
8015 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
8016
8017 /*
8018  * generic initialization of ADC, input mixers and output mixers
8019  */
8020 static struct hda_verb alc262_init_verbs[] = {
8021         /*
8022          * Unmute ADC0-2 and set the default input to mic-in
8023          */
8024         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
8025         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8026         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8027         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8028         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8029         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8030
8031         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8032          * mixer widget
8033          * Note: PASD motherboards uses the Line In 2 as the input for
8034          * front panel mic (mic 2)
8035          */
8036         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8037         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8038         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8039         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8040         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8041         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8042
8043         /*
8044          * Set up output mixers (0x0c - 0x0e)
8045          */
8046         /* set vol=0 to output mixers */
8047         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8048         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8049         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8050         /* set up input amps for analog loopback */
8051         /* Amp Indices: DAC = 0, mixer = 1 */
8052         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8053         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8054         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8055         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8056         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8057         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8058
8059         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
8060         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8061         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
8062         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8063         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8064         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8065
8066         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8067         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8068         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8069         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8070         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8071         
8072         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8073         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
8074         
8075         /* FIXME: use matrix-type input source selection */
8076         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8077         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
8078         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8079         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8080         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8081         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8082         /* Input mixer2 */
8083         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8084         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8085         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8086         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8087         /* Input mixer3 */
8088         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8089         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8090         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8091         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8092
8093         { }
8094 };
8095
8096 static struct hda_verb alc262_hippo_unsol_verbs[] = {
8097         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8098         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8099         {}
8100 };
8101
8102 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
8103         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8104         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8105         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8106
8107         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8108         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8109         {}
8110 };
8111
8112 static struct hda_verb alc262_sony_unsol_verbs[] = {
8113         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8114         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8115         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
8116
8117         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8118         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8119 };
8120
8121 /* mute/unmute internal speaker according to the hp jack and mute state */
8122 static void alc262_hippo_automute(struct hda_codec *codec)
8123 {
8124         struct alc_spec *spec = codec->spec;
8125         unsigned int mute;
8126         unsigned int present;
8127
8128         /* need to execute and sync at first */
8129         snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
8130         present = snd_hda_codec_read(codec, 0x15, 0,
8131                                      AC_VERB_GET_PIN_SENSE, 0);
8132         spec->jack_present = (present & 0x80000000) != 0;
8133         if (spec->jack_present) {
8134                 /* mute internal speaker */
8135                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8136                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8137         } else {
8138                 /* unmute internal speaker if necessary */
8139                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
8140                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8141                                          HDA_AMP_MUTE, mute);
8142         }
8143 }
8144
8145 /* unsolicited event for HP jack sensing */
8146 static void alc262_hippo_unsol_event(struct hda_codec *codec,
8147                                        unsigned int res)
8148 {
8149         if ((res >> 26) != ALC880_HP_EVENT)
8150                 return;
8151         alc262_hippo_automute(codec);
8152 }
8153
8154 static void alc262_hippo1_automute(struct hda_codec *codec)
8155 {
8156         unsigned int mute;
8157         unsigned int present;
8158
8159         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
8160         present = snd_hda_codec_read(codec, 0x1b, 0,
8161                                      AC_VERB_GET_PIN_SENSE, 0);
8162         present = (present & 0x80000000) != 0;
8163         if (present) {
8164                 /* mute internal speaker */
8165                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8166                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8167         } else {
8168                 /* unmute internal speaker if necessary */
8169                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
8170                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8171                                          HDA_AMP_MUTE, mute);
8172         }
8173 }
8174
8175 /* unsolicited event for HP jack sensing */
8176 static void alc262_hippo1_unsol_event(struct hda_codec *codec,
8177                                        unsigned int res)
8178 {
8179         if ((res >> 26) != ALC880_HP_EVENT)
8180                 return;
8181         alc262_hippo1_automute(codec);
8182 }
8183
8184 /*
8185  * fujitsu model
8186  *  0x14 = headphone/spdif-out, 0x15 = internal speaker
8187  */
8188
8189 #define ALC_HP_EVENT    0x37
8190
8191 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
8192         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
8193         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8194         {}
8195 };
8196
8197 static struct hda_input_mux alc262_fujitsu_capture_source = {
8198         .num_items = 3,
8199         .items = {
8200                 { "Mic", 0x0 },
8201                 { "Int Mic", 0x1 },
8202                 { "CD", 0x4 },
8203         },
8204 };
8205
8206 static struct hda_input_mux alc262_HP_capture_source = {
8207         .num_items = 5,
8208         .items = {
8209                 { "Mic", 0x0 },
8210                 { "Front Mic", 0x1 },
8211                 { "Line", 0x2 },
8212                 { "CD", 0x4 },
8213                 { "AUX IN", 0x6 },
8214         },
8215 };
8216
8217 static struct hda_input_mux alc262_HP_D7000_capture_source = {
8218         .num_items = 4,
8219         .items = {
8220                 { "Mic", 0x0 },
8221                 { "Front Mic", 0x2 },
8222                 { "Line", 0x1 },
8223                 { "CD", 0x4 },
8224         },
8225 };
8226
8227 /* mute/unmute internal speaker according to the hp jack and mute state */
8228 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
8229 {
8230         struct alc_spec *spec = codec->spec;
8231         unsigned int mute;
8232
8233         if (force || !spec->sense_updated) {
8234                 unsigned int present;
8235                 /* need to execute and sync at first */
8236                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
8237                 present = snd_hda_codec_read(codec, 0x14, 0,
8238                                          AC_VERB_GET_PIN_SENSE, 0);
8239                 spec->jack_present = (present & 0x80000000) != 0;
8240                 spec->sense_updated = 1;
8241         }
8242         if (spec->jack_present) {
8243                 /* mute internal speaker */
8244                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8245                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8246         } else {
8247                 /* unmute internal speaker if necessary */
8248                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
8249                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8250                                          HDA_AMP_MUTE, mute);
8251         }
8252 }
8253
8254 /* unsolicited event for HP jack sensing */
8255 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
8256                                        unsigned int res)
8257 {
8258         if ((res >> 26) != ALC_HP_EVENT)
8259                 return;
8260         alc262_fujitsu_automute(codec, 1);
8261 }
8262
8263 /* bind volumes of both NID 0x0c and 0x0d */
8264 static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
8265         .ops = &snd_hda_bind_vol,
8266         .values = {
8267                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
8268                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
8269                 0
8270         },
8271 };
8272
8273 /* bind hp and internal speaker mute (with plug check) */
8274 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
8275                                          struct snd_ctl_elem_value *ucontrol)
8276 {
8277         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8278         long *valp = ucontrol->value.integer.value;
8279         int change;
8280
8281         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
8282                                           HDA_AMP_MUTE,
8283                                           valp[0] ? 0 : HDA_AMP_MUTE);
8284         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
8285                                            HDA_AMP_MUTE,
8286                                            valp[1] ? 0 : HDA_AMP_MUTE);
8287         if (change)
8288                 alc262_fujitsu_automute(codec, 0);
8289         return change;
8290 }
8291
8292 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
8293         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
8294         {
8295                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8296                 .name = "Master Playback Switch",
8297                 .info = snd_hda_mixer_amp_switch_info,
8298                 .get = snd_hda_mixer_amp_switch_get,
8299                 .put = alc262_fujitsu_master_sw_put,
8300                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
8301         },
8302         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8303         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8304         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8305         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8306         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8307         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
8308         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8309         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8310         { } /* end */
8311 };
8312
8313 /* additional init verbs for Benq laptops */
8314 static struct hda_verb alc262_EAPD_verbs[] = {
8315         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
8316         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
8317         {}
8318 };
8319
8320 static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
8321         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8322         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8323
8324         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
8325         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
8326         {}
8327 };
8328
8329 /* Samsung Q1 Ultra Vista model setup */
8330 static struct snd_kcontrol_new alc262_ultra_mixer[] = {
8331         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8332         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8333         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8334         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8335         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8336         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
8337         { } /* end */
8338 };
8339
8340 static struct hda_verb alc262_ultra_verbs[] = {
8341         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8342         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8343         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
8344         /* Mic is on Node 0x19 */
8345         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8346         {0x22, AC_VERB_SET_CONNECT_SEL, 0x01},
8347         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8348         {0x23, AC_VERB_SET_CONNECT_SEL, 0x01},
8349         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8350         {0x24, AC_VERB_SET_CONNECT_SEL, 0x01},
8351         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8352         {}
8353 };
8354
8355 static struct hda_input_mux alc262_ultra_capture_source = {
8356         .num_items = 1,
8357         .items = {
8358                 { "Mic", 0x1 },
8359         },
8360 };
8361
8362 /* mute/unmute internal speaker according to the hp jack and mute state */
8363 static void alc262_ultra_automute(struct hda_codec *codec)
8364 {
8365         struct alc_spec *spec = codec->spec;
8366         unsigned int mute;
8367         unsigned int present;
8368
8369         /* need to execute and sync at first */
8370         snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
8371         present = snd_hda_codec_read(codec, 0x15, 0,
8372                                      AC_VERB_GET_PIN_SENSE, 0);
8373         spec->jack_present = (present & 0x80000000) != 0;
8374         if (spec->jack_present) {
8375                 /* mute internal speaker */
8376                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8377                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8378         } else {
8379                 /* unmute internal speaker if necessary */
8380                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
8381                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8382                                          HDA_AMP_MUTE, mute);
8383         }
8384 }
8385
8386 /* unsolicited event for HP jack sensing */
8387 static void alc262_ultra_unsol_event(struct hda_codec *codec,
8388                                        unsigned int res)
8389 {
8390         if ((res >> 26) != ALC880_HP_EVENT)
8391                 return;
8392         alc262_ultra_automute(codec);
8393 }
8394
8395 /* add playback controls from the parsed DAC table */
8396 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
8397                                              const struct auto_pin_cfg *cfg)
8398 {
8399         hda_nid_t nid;
8400         int err;
8401
8402         spec->multiout.num_dacs = 1;    /* only use one dac */
8403         spec->multiout.dac_nids = spec->private_dac_nids;
8404         spec->multiout.dac_nids[0] = 2;
8405
8406         nid = cfg->line_out_pins[0];
8407         if (nid) {
8408                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
8409                                   "Front Playback Volume",
8410                                   HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT));
8411                 if (err < 0)
8412                         return err;
8413                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
8414                                   "Front Playback Switch",
8415                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
8416                 if (err < 0)
8417                         return err;
8418         }
8419
8420         nid = cfg->speaker_pins[0];
8421         if (nid) {
8422                 if (nid == 0x16) {
8423                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
8424                                           "Speaker Playback Volume",
8425                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
8426                                                               HDA_OUTPUT));
8427                         if (err < 0)
8428                                 return err;
8429                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
8430                                           "Speaker Playback Switch",
8431                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
8432                                                               HDA_OUTPUT));
8433                         if (err < 0)
8434                                 return err;
8435                 } else {
8436                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
8437                                           "Speaker Playback Switch",
8438                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
8439                                                               HDA_OUTPUT));
8440                         if (err < 0)
8441                                 return err;
8442                 }
8443         }
8444         nid = cfg->hp_pins[0];
8445         if (nid) {
8446                 /* spec->multiout.hp_nid = 2; */
8447                 if (nid == 0x16) {
8448                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
8449                                           "Headphone Playback Volume",
8450                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
8451                                                               HDA_OUTPUT));
8452                         if (err < 0)
8453                                 return err;
8454                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
8455                                           "Headphone Playback Switch",
8456                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
8457                                                               HDA_OUTPUT));
8458                         if (err < 0)
8459                                 return err;
8460                 } else {
8461                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
8462                                           "Headphone Playback Switch",
8463                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
8464                                                               HDA_OUTPUT));
8465                         if (err < 0)
8466                                 return err;
8467                 }
8468         }
8469         return 0;
8470 }
8471
8472 /* identical with ALC880 */
8473 #define alc262_auto_create_analog_input_ctls \
8474         alc880_auto_create_analog_input_ctls
8475
8476 /*
8477  * generic initialization of ADC, input mixers and output mixers
8478  */
8479 static struct hda_verb alc262_volume_init_verbs[] = {
8480         /*
8481          * Unmute ADC0-2 and set the default input to mic-in
8482          */
8483         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
8484         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8485         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8486         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8487         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8488         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8489
8490         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8491          * mixer widget
8492          * Note: PASD motherboards uses the Line In 2 as the input for
8493          * front panel mic (mic 2)
8494          */
8495         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8496         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8497         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8498         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8499         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8500         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8501
8502         /*
8503          * Set up output mixers (0x0c - 0x0f)
8504          */
8505         /* set vol=0 to output mixers */
8506         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8507         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8508         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8509         
8510         /* set up input amps for analog loopback */
8511         /* Amp Indices: DAC = 0, mixer = 1 */
8512         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8513         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8514         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8515         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8516         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8517         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8518
8519         /* FIXME: use matrix-type input source selection */
8520         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8521         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
8522         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8523         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8524         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8525         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8526         /* Input mixer2 */
8527         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8528         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8529         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8530         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8531         /* Input mixer3 */
8532         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8533         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8534         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8535         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8536
8537         { }
8538 };
8539
8540 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
8541         /*
8542          * Unmute ADC0-2 and set the default input to mic-in
8543          */
8544         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
8545         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8546         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8547         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8548         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8549         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8550
8551         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8552          * mixer widget
8553          * Note: PASD motherboards uses the Line In 2 as the input for
8554          * front panel mic (mic 2)
8555          */
8556         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8557         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8558         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8559         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8560         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8561         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8562         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
8563         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
8564         
8565         /*
8566          * Set up output mixers (0x0c - 0x0e)
8567          */
8568         /* set vol=0 to output mixers */
8569         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8570         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8571         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8572
8573         /* set up input amps for analog loopback */
8574         /* Amp Indices: DAC = 0, mixer = 1 */
8575         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8576         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8577         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8578         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8579         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8580         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8581
8582         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8583         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8584         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8585
8586         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8587         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8588
8589         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8590         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8591
8592         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8593         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8594         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8595         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8596         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8597
8598         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
8599         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8600         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8601         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
8602         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8603         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8604
8605
8606         /* FIXME: use matrix-type input source selection */
8607         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8608         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
8609         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8610         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
8611         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
8612         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
8613         /* Input mixer2 */
8614         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8615         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
8616         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
8617         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
8618         /* Input mixer3 */
8619         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8620         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
8621         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
8622         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
8623
8624         { }
8625 };
8626
8627 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
8628         /*
8629          * Unmute ADC0-2 and set the default input to mic-in
8630          */
8631         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
8632         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8633         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8634         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8635         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8636         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8637
8638         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8639          * mixer widget
8640          * Note: PASD motherboards uses the Line In 2 as the input for front
8641          * panel mic (mic 2)
8642          */
8643         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8644         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8645         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8646         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8647         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8648         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8649         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
8650         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
8651         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
8652         /*
8653          * Set up output mixers (0x0c - 0x0e)
8654          */
8655         /* set vol=0 to output mixers */
8656         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8657         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8658         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8659
8660         /* set up input amps for analog loopback */
8661         /* Amp Indices: DAC = 0, mixer = 1 */
8662         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8663         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8664         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8665         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8666         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8667         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8668
8669
8670         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
8671         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
8672         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
8673         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
8674         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
8675         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
8676         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
8677
8678         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8679         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8680
8681         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8682         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
8683
8684         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
8685         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8686         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8687         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
8688         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8689         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8690
8691         /* FIXME: use matrix-type input source selection */
8692         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8693         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
8694         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
8695         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
8696         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
8697         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
8698         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
8699         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
8700         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
8701         /* Input mixer2 */
8702         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8703         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8704         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
8705         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
8706         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
8707         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
8708         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
8709         /* Input mixer3 */
8710         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8711         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8712         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
8713         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
8714         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
8715         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
8716         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
8717
8718         { }
8719 };
8720
8721 #ifdef CONFIG_SND_HDA_POWER_SAVE
8722 #define alc262_loopbacks        alc880_loopbacks
8723 #endif
8724
8725 /* pcm configuration: identiacal with ALC880 */
8726 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
8727 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
8728 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
8729 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
8730
8731 /*
8732  * BIOS auto configuration
8733  */
8734 static int alc262_parse_auto_config(struct hda_codec *codec)
8735 {
8736         struct alc_spec *spec = codec->spec;
8737         int err;
8738         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
8739
8740         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
8741                                            alc262_ignore);
8742         if (err < 0)
8743                 return err;
8744         if (!spec->autocfg.line_outs)
8745                 return 0; /* can't find valid BIOS pin config */
8746         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
8747         if (err < 0)
8748                 return err;
8749         err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg);
8750         if (err < 0)
8751                 return err;
8752
8753         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
8754
8755         if (spec->autocfg.dig_out_pin)
8756                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
8757         if (spec->autocfg.dig_in_pin)
8758                 spec->dig_in_nid = ALC262_DIGIN_NID;
8759
8760         if (spec->kctl_alloc)
8761                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
8762
8763         spec->init_verbs[spec->num_init_verbs++] = alc262_volume_init_verbs;
8764         spec->num_mux_defs = 1;
8765         spec->input_mux = &spec->private_imux;
8766
8767         err = alc_auto_add_mic_boost(codec);
8768         if (err < 0)
8769                 return err;
8770
8771         return 1;
8772 }
8773
8774 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
8775 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
8776 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
8777
8778
8779 /* init callback for auto-configuration model -- overriding the default init */
8780 static void alc262_auto_init(struct hda_codec *codec)
8781 {
8782         alc262_auto_init_multi_out(codec);
8783         alc262_auto_init_hp_out(codec);
8784         alc262_auto_init_analog_input(codec);
8785 }
8786
8787 /*
8788  * configuration and preset
8789  */
8790 static const char *alc262_models[ALC262_MODEL_LAST] = {
8791         [ALC262_BASIC]          = "basic",
8792         [ALC262_HIPPO]          = "hippo",
8793         [ALC262_HIPPO_1]        = "hippo_1",
8794         [ALC262_FUJITSU]        = "fujitsu",
8795         [ALC262_HP_BPC]         = "hp-bpc",
8796         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
8797         [ALC262_HP_TC_T5735]    = "hp-tc-t5735",
8798         [ALC262_BENQ_ED8]       = "benq",
8799         [ALC262_BENQ_T31]       = "benq-t31",
8800         [ALC262_SONY_ASSAMD]    = "sony-assamd",
8801         [ALC262_ULTRA]          = "ultra",
8802         [ALC262_AUTO]           = "auto",
8803 };
8804
8805 static struct snd_pci_quirk alc262_cfg_tbl[] = {
8806         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
8807         SND_PCI_QUIRK(0x103c, 0x12fe, "HP xw9400", ALC262_HP_BPC),
8808         SND_PCI_QUIRK(0x103c, 0x12ff, "HP xw4550", ALC262_HP_BPC),
8809         SND_PCI_QUIRK(0x103c, 0x1306, "HP xw8600", ALC262_HP_BPC),
8810         SND_PCI_QUIRK(0x103c, 0x1307, "HP xw6600", ALC262_HP_BPC),
8811         SND_PCI_QUIRK(0x103c, 0x1308, "HP xw4600", ALC262_HP_BPC),
8812         SND_PCI_QUIRK(0x103c, 0x1309, "HP xw4*00", ALC262_HP_BPC),
8813         SND_PCI_QUIRK(0x103c, 0x130a, "HP xw6*00", ALC262_HP_BPC),
8814         SND_PCI_QUIRK(0x103c, 0x130b, "HP xw8*00", ALC262_HP_BPC),
8815         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
8816         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
8817         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
8818         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
8819         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
8820         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
8821         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
8822         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
8823         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
8824         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
8825         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
8826         SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
8827                       ALC262_HP_TC_T5735),
8828         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
8829         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
8830         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
8831         SND_PCI_QUIRK(0x104d, 0x900e, "Sony ASSAMD", ALC262_SONY_ASSAMD),
8832         SND_PCI_QUIRK(0x104d, 0x9015, "Sony 0x9015", ALC262_SONY_ASSAMD),
8833         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
8834         SND_PCI_QUIRK(0x144d, 0xc032, "Samsung Q1 Ultra", ALC262_ULTRA),
8835         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
8836         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
8837         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
8838         {}
8839 };
8840
8841 static struct alc_config_preset alc262_presets[] = {
8842         [ALC262_BASIC] = {
8843                 .mixers = { alc262_base_mixer },
8844                 .init_verbs = { alc262_init_verbs },
8845                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8846                 .dac_nids = alc262_dac_nids,
8847                 .hp_nid = 0x03,
8848                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8849                 .channel_mode = alc262_modes,
8850                 .input_mux = &alc262_capture_source,
8851         },
8852         [ALC262_HIPPO] = {
8853                 .mixers = { alc262_base_mixer },
8854                 .init_verbs = { alc262_init_verbs, alc262_hippo_unsol_verbs},
8855                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8856                 .dac_nids = alc262_dac_nids,
8857                 .hp_nid = 0x03,
8858                 .dig_out_nid = ALC262_DIGOUT_NID,
8859                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8860                 .channel_mode = alc262_modes,
8861                 .input_mux = &alc262_capture_source,
8862                 .unsol_event = alc262_hippo_unsol_event,
8863                 .init_hook = alc262_hippo_automute,
8864         },
8865         [ALC262_HIPPO_1] = {
8866                 .mixers = { alc262_hippo1_mixer },
8867                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
8868                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8869                 .dac_nids = alc262_dac_nids,
8870                 .hp_nid = 0x02,
8871                 .dig_out_nid = ALC262_DIGOUT_NID,
8872                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8873                 .channel_mode = alc262_modes,
8874                 .input_mux = &alc262_capture_source,
8875                 .unsol_event = alc262_hippo1_unsol_event,
8876                 .init_hook = alc262_hippo1_automute,
8877         },
8878         [ALC262_FUJITSU] = {
8879                 .mixers = { alc262_fujitsu_mixer },
8880                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
8881                                 alc262_fujitsu_unsol_verbs },
8882                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8883                 .dac_nids = alc262_dac_nids,
8884                 .hp_nid = 0x03,
8885                 .dig_out_nid = ALC262_DIGOUT_NID,
8886                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8887                 .channel_mode = alc262_modes,
8888                 .input_mux = &alc262_fujitsu_capture_source,
8889                 .unsol_event = alc262_fujitsu_unsol_event,
8890         },
8891         [ALC262_HP_BPC] = {
8892                 .mixers = { alc262_HP_BPC_mixer },
8893                 .init_verbs = { alc262_HP_BPC_init_verbs },
8894                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8895                 .dac_nids = alc262_dac_nids,
8896                 .hp_nid = 0x03,
8897                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8898                 .channel_mode = alc262_modes,
8899                 .input_mux = &alc262_HP_capture_source,
8900         },
8901         [ALC262_HP_BPC_D7000_WF] = {
8902                 .mixers = { alc262_HP_BPC_WildWest_mixer },
8903                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
8904                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8905                 .dac_nids = alc262_dac_nids,
8906                 .hp_nid = 0x03,
8907                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8908                 .channel_mode = alc262_modes,
8909                 .input_mux = &alc262_HP_D7000_capture_source,
8910         },
8911         [ALC262_HP_BPC_D7000_WL] = {
8912                 .mixers = { alc262_HP_BPC_WildWest_mixer,
8913                             alc262_HP_BPC_WildWest_option_mixer },
8914                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
8915                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8916                 .dac_nids = alc262_dac_nids,
8917                 .hp_nid = 0x03,
8918                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8919                 .channel_mode = alc262_modes,
8920                 .input_mux = &alc262_HP_D7000_capture_source,
8921         },
8922         [ALC262_HP_TC_T5735] = {
8923                 .mixers = { alc262_hp_t5735_mixer },
8924                 .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
8925                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8926                 .dac_nids = alc262_dac_nids,
8927                 .hp_nid = 0x03,
8928                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8929                 .channel_mode = alc262_modes,
8930                 .input_mux = &alc262_capture_source,
8931                 .unsol_event = alc262_hp_t5735_unsol_event,
8932                 .init_hook = alc262_hp_t5735_init_hook,
8933         },
8934         [ALC262_BENQ_ED8] = {
8935                 .mixers = { alc262_base_mixer },
8936                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
8937                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8938                 .dac_nids = alc262_dac_nids,
8939                 .hp_nid = 0x03,
8940                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8941                 .channel_mode = alc262_modes,
8942                 .input_mux = &alc262_capture_source,
8943         },
8944         [ALC262_SONY_ASSAMD] = {
8945                 .mixers = { alc262_sony_mixer },
8946                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
8947                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8948                 .dac_nids = alc262_dac_nids,
8949                 .hp_nid = 0x02,
8950                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8951                 .channel_mode = alc262_modes,
8952                 .input_mux = &alc262_capture_source,
8953                 .unsol_event = alc262_hippo_unsol_event,
8954                 .init_hook = alc262_hippo_automute,
8955         },
8956         [ALC262_BENQ_T31] = {
8957                 .mixers = { alc262_benq_t31_mixer },
8958                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs, alc262_hippo_unsol_verbs },
8959                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8960                 .dac_nids = alc262_dac_nids,
8961                 .hp_nid = 0x03,
8962                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8963                 .channel_mode = alc262_modes,
8964                 .input_mux = &alc262_capture_source,
8965                 .unsol_event = alc262_hippo_unsol_event,
8966                 .init_hook = alc262_hippo_automute,
8967         },      
8968         [ALC262_ULTRA] = {
8969                 .mixers = { alc262_ultra_mixer },
8970                 .init_verbs = { alc262_init_verbs, alc262_ultra_verbs },
8971                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8972                 .dac_nids = alc262_dac_nids,
8973                 .hp_nid = 0x03,
8974                 .dig_out_nid = ALC262_DIGOUT_NID,
8975                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8976                 .channel_mode = alc262_modes,
8977                 .input_mux = &alc262_ultra_capture_source,
8978                 .unsol_event = alc262_ultra_unsol_event,
8979                 .init_hook = alc262_ultra_automute,
8980         },
8981 };
8982
8983 static int patch_alc262(struct hda_codec *codec)
8984 {
8985         struct alc_spec *spec;
8986         int board_config;
8987         int err;
8988
8989         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
8990         if (spec == NULL)
8991                 return -ENOMEM;
8992
8993         codec->spec = spec;
8994 #if 0
8995         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
8996          * under-run
8997          */
8998         {
8999         int tmp;
9000         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
9001         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
9002         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
9003         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
9004         }
9005 #endif
9006
9007         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
9008                                                   alc262_models,
9009                                                   alc262_cfg_tbl);
9010
9011         if (board_config < 0) {
9012                 printk(KERN_INFO "hda_codec: Unknown model for ALC262, "
9013                        "trying auto-probe from BIOS...\n");
9014                 board_config = ALC262_AUTO;
9015         }
9016
9017         if (board_config == ALC262_AUTO) {
9018                 /* automatic parse from the BIOS config */
9019                 err = alc262_parse_auto_config(codec);
9020                 if (err < 0) {
9021                         alc_free(codec);
9022                         return err;
9023                 } else if (!err) {
9024                         printk(KERN_INFO
9025                                "hda_codec: Cannot set up configuration "
9026                                "from BIOS.  Using base mode...\n");
9027                         board_config = ALC262_BASIC;
9028                 }
9029         }
9030
9031         if (board_config != ALC262_AUTO)
9032                 setup_preset(spec, &alc262_presets[board_config]);
9033
9034         spec->stream_name_analog = "ALC262 Analog";
9035         spec->stream_analog_playback = &alc262_pcm_analog_playback;
9036         spec->stream_analog_capture = &alc262_pcm_analog_capture;
9037                 
9038         spec->stream_name_digital = "ALC262 Digital";
9039         spec->stream_digital_playback = &alc262_pcm_digital_playback;
9040         spec->stream_digital_capture = &alc262_pcm_digital_capture;
9041
9042         if (!spec->adc_nids && spec->input_mux) {
9043                 /* check whether NID 0x07 is valid */
9044                 unsigned int wcap = get_wcaps(codec, 0x07);
9045
9046                 /* get type */
9047                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
9048                 if (wcap != AC_WID_AUD_IN) {
9049                         spec->adc_nids = alc262_adc_nids_alt;
9050                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
9051                         spec->mixers[spec->num_mixers] =
9052                                 alc262_capture_alt_mixer;
9053                         spec->num_mixers++;
9054                 } else {
9055                         spec->adc_nids = alc262_adc_nids;
9056                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
9057                         spec->mixers[spec->num_mixers] = alc262_capture_mixer;
9058                         spec->num_mixers++;
9059                 }
9060         }
9061
9062         codec->patch_ops = alc_patch_ops;
9063         if (board_config == ALC262_AUTO)
9064                 spec->init_hook = alc262_auto_init;
9065 #ifdef CONFIG_SND_HDA_POWER_SAVE
9066         if (!spec->loopback.amplist)
9067                 spec->loopback.amplist = alc262_loopbacks;
9068 #endif
9069                 
9070         return 0;
9071 }
9072
9073 /*
9074  *  ALC268 channel source setting (2 channel)
9075  */
9076 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
9077 #define alc268_modes            alc260_modes
9078         
9079 static hda_nid_t alc268_dac_nids[2] = {
9080         /* front, hp */
9081         0x02, 0x03
9082 };
9083
9084 static hda_nid_t alc268_adc_nids[2] = {
9085         /* ADC0-1 */
9086         0x08, 0x07
9087 };
9088
9089 static hda_nid_t alc268_adc_nids_alt[1] = {
9090         /* ADC0 */
9091         0x08
9092 };
9093
9094 static struct snd_kcontrol_new alc268_base_mixer[] = {
9095         /* output mixer control */
9096         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
9097         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9098         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
9099         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9100         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9101         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9102         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
9103         { }
9104 };
9105
9106 static struct hda_verb alc268_eapd_verbs[] = {
9107         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
9108         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
9109         { }
9110 };
9111
9112 /* Toshiba specific */
9113 #define alc268_toshiba_automute alc262_hippo_automute
9114
9115 static struct hda_verb alc268_toshiba_verbs[] = {
9116         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9117         { } /* end */
9118 };
9119
9120 /* Acer specific */
9121 /* bind volumes of both NID 0x02 and 0x03 */
9122 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
9123         .ops = &snd_hda_bind_vol,
9124         .values = {
9125                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
9126                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
9127                 0
9128         },
9129 };
9130
9131 /* mute/unmute internal speaker according to the hp jack and mute state */
9132 static void alc268_acer_automute(struct hda_codec *codec, int force)
9133 {
9134         struct alc_spec *spec = codec->spec;
9135         unsigned int mute;
9136
9137         if (force || !spec->sense_updated) {
9138                 unsigned int present;
9139                 present = snd_hda_codec_read(codec, 0x14, 0,
9140                                          AC_VERB_GET_PIN_SENSE, 0);
9141                 spec->jack_present = (present & 0x80000000) != 0;
9142                 spec->sense_updated = 1;
9143         }
9144         if (spec->jack_present)
9145                 mute = HDA_AMP_MUTE; /* mute internal speaker */
9146         else /* unmute internal speaker if necessary */
9147                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
9148         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9149                                  HDA_AMP_MUTE, mute);
9150 }
9151
9152
9153 /* bind hp and internal speaker mute (with plug check) */
9154 static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
9155                                      struct snd_ctl_elem_value *ucontrol)
9156 {
9157         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9158         long *valp = ucontrol->value.integer.value;
9159         int change;
9160
9161         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
9162                                           HDA_AMP_MUTE,
9163                                           valp[0] ? 0 : HDA_AMP_MUTE);
9164         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
9165                                            HDA_AMP_MUTE,
9166                                            valp[1] ? 0 : HDA_AMP_MUTE);
9167         if (change)
9168                 alc268_acer_automute(codec, 0);
9169         return change;
9170 }
9171
9172 static struct snd_kcontrol_new alc268_acer_mixer[] = {
9173         /* output mixer control */
9174         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
9175         {
9176                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9177                 .name = "Master Playback Switch",
9178                 .info = snd_hda_mixer_amp_switch_info,
9179                 .get = snd_hda_mixer_amp_switch_get,
9180                 .put = alc268_acer_master_sw_put,
9181                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
9182         },
9183         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9184         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
9185         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
9186         { }
9187 };
9188
9189 static struct hda_verb alc268_acer_verbs[] = {
9190         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9191         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9192
9193         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9194         { }
9195 };
9196
9197 /* unsolicited event for HP jack sensing */
9198 static void alc268_toshiba_unsol_event(struct hda_codec *codec,
9199                                        unsigned int res)
9200 {
9201         if ((res >> 26) != ALC880_HP_EVENT)
9202                 return;
9203         alc268_toshiba_automute(codec);
9204 }
9205
9206 static void alc268_acer_unsol_event(struct hda_codec *codec,
9207                                        unsigned int res)
9208 {
9209         if ((res >> 26) != ALC880_HP_EVENT)
9210                 return;
9211         alc268_acer_automute(codec, 1);
9212 }
9213
9214 static void alc268_acer_init_hook(struct hda_codec *codec)
9215 {
9216         alc268_acer_automute(codec, 1);
9217 }
9218
9219 /*
9220  * generic initialization of ADC, input mixers and output mixers
9221  */
9222 static struct hda_verb alc268_base_init_verbs[] = {
9223         /* Unmute DAC0-1 and set vol = 0 */
9224         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9225         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9226         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9227         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9228         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9229         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9230
9231         /*
9232          * Set up output mixers (0x0c - 0x0e)
9233          */
9234         /* set vol=0 to output mixers */
9235         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9236         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9237         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9238         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
9239
9240         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9241         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9242
9243         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9244         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9245         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9246         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9247         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9248         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9249         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9250         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9251
9252         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9253         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9254         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9255         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9256         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9257         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9258         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9259         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9260
9261         /* Unmute Selector 23h,24h and set the default input to mic-in */
9262         
9263         {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
9264         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9265         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
9266         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9267
9268         { }
9269 };
9270
9271 /*
9272  * generic initialization of ADC, input mixers and output mixers
9273  */
9274 static struct hda_verb alc268_volume_init_verbs[] = {
9275         /* set output DAC */
9276         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9277         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9278         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9279         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9280
9281         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9282         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9283         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9284         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9285         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9286
9287         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9288         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9289         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9290         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9291         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9292
9293         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9294         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9295         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9296         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9297
9298         /* set PCBEEP vol = 0 */
9299         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, (0xb000 | (0x00 << 8))},
9300
9301         { }
9302 };
9303
9304 #define alc268_mux_enum_info alc_mux_enum_info
9305 #define alc268_mux_enum_get alc_mux_enum_get
9306
9307 static int alc268_mux_enum_put(struct snd_kcontrol *kcontrol,
9308                                struct snd_ctl_elem_value *ucontrol)
9309 {
9310         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9311         struct alc_spec *spec = codec->spec;
9312
9313         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
9314         static hda_nid_t capture_mixers[3] = { 0x23, 0x24 };
9315         hda_nid_t nid = capture_mixers[adc_idx];
9316
9317         return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
9318                                      nid,
9319                                      &spec->cur_mux[adc_idx]);
9320 }
9321
9322 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
9323         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
9324         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
9325         {
9326                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9327                 /* The multiple "Capture Source" controls confuse alsamixer
9328                  * So call somewhat different..
9329                  * FIXME: the controls appear in the "playback" view!
9330                  */
9331                 /* .name = "Capture Source", */
9332                 .name = "Input Source",
9333                 .count = 1,
9334                 .info = alc268_mux_enum_info,
9335                 .get = alc268_mux_enum_get,
9336                 .put = alc268_mux_enum_put,
9337         },
9338         { } /* end */
9339 };
9340
9341 static struct snd_kcontrol_new alc268_capture_mixer[] = {
9342         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
9343         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
9344         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
9345         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
9346         {
9347                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9348                 /* The multiple "Capture Source" controls confuse alsamixer
9349                  * So call somewhat different..
9350                  * FIXME: the controls appear in the "playback" view!
9351                  */
9352                 /* .name = "Capture Source", */
9353                 .name = "Input Source",
9354                 .count = 2,
9355                 .info = alc268_mux_enum_info,
9356                 .get = alc268_mux_enum_get,
9357                 .put = alc268_mux_enum_put,
9358         },
9359         { } /* end */
9360 };
9361
9362 static struct hda_input_mux alc268_capture_source = {
9363         .num_items = 4,
9364         .items = {
9365                 { "Mic", 0x0 },
9366                 { "Front Mic", 0x1 },
9367                 { "Line", 0x2 },
9368                 { "CD", 0x3 },
9369         },
9370 };
9371
9372 #ifdef CONFIG_SND_DEBUG
9373 static struct snd_kcontrol_new alc268_test_mixer[] = {
9374         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
9375         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9376         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
9377         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9378
9379         /* Volume widgets */
9380         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
9381         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
9382         HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
9383         HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
9384         HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
9385         HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
9386         HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
9387         HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
9388         HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
9389         HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
9390         HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
9391         HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
9392         HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
9393         HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),
9394         HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
9395         HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
9396         HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
9397         HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),
9398
9399         /* Modes for retasking pin widgets */
9400         ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
9401         ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
9402         ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
9403         ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),
9404
9405         /* Controls for GPIO pins, assuming they are configured as outputs */
9406         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
9407         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
9408         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
9409         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
9410
9411         /* Switches to allow the digital SPDIF output pin to be enabled.
9412          * The ALC268 does not have an SPDIF input.
9413          */
9414         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),
9415
9416         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
9417          * this output to turn on an external amplifier.
9418          */
9419         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
9420         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
9421
9422         { } /* end */
9423 };
9424 #endif
9425
9426 /* create input playback/capture controls for the given pin */
9427 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
9428                                     const char *ctlname, int idx)
9429 {
9430         char name[32];
9431         int err;
9432
9433         sprintf(name, "%s Playback Volume", ctlname);
9434         if (nid == 0x14) {
9435                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
9436                                   HDA_COMPOSE_AMP_VAL(0x02, 3, idx,
9437                                                       HDA_OUTPUT));
9438                 if (err < 0)
9439                         return err;
9440         } else if (nid == 0x15) {
9441                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
9442                                   HDA_COMPOSE_AMP_VAL(0x03, 3, idx,
9443                                                       HDA_OUTPUT));
9444                 if (err < 0)
9445                         return err;
9446         } else
9447                 return -1;
9448         sprintf(name, "%s Playback Switch", ctlname);
9449         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
9450                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
9451         if (err < 0)
9452                 return err;
9453         return 0;
9454 }
9455
9456 /* add playback controls from the parsed DAC table */
9457 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
9458                                              const struct auto_pin_cfg *cfg)
9459 {
9460         hda_nid_t nid;
9461         int err;
9462
9463         spec->multiout.num_dacs = 2;    /* only use one dac */
9464         spec->multiout.dac_nids = spec->private_dac_nids;
9465         spec->multiout.dac_nids[0] = 2;
9466         spec->multiout.dac_nids[1] = 3;
9467
9468         nid = cfg->line_out_pins[0];
9469         if (nid)
9470                 alc268_new_analog_output(spec, nid, "Front", 0);        
9471
9472         nid = cfg->speaker_pins[0];
9473         if (nid == 0x1d) {
9474                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
9475                                   "Speaker Playback Volume",
9476                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
9477                 if (err < 0)
9478                         return err;
9479         }
9480         nid = cfg->hp_pins[0];
9481         if (nid)
9482                 alc268_new_analog_output(spec, nid, "Headphone", 0);
9483
9484         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
9485         if (nid == 0x16) {
9486                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9487                                   "Mono Playback Switch",
9488                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_INPUT));
9489                 if (err < 0)
9490                         return err;
9491         }
9492         return 0;       
9493 }
9494
9495 /* create playback/capture controls for input pins */
9496 static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
9497                                                 const struct auto_pin_cfg *cfg)
9498 {
9499         struct hda_input_mux *imux = &spec->private_imux;
9500         int i, idx1;
9501
9502         for (i = 0; i < AUTO_PIN_LAST; i++) {
9503                 switch(cfg->input_pins[i]) {
9504                 case 0x18:
9505                         idx1 = 0;       /* Mic 1 */
9506                         break;
9507                 case 0x19:
9508                         idx1 = 1;       /* Mic 2 */
9509                         break;
9510                 case 0x1a:
9511                         idx1 = 2;       /* Line In */
9512                         break;
9513                 case 0x1c:      
9514                         idx1 = 3;       /* CD */
9515                         break;
9516                 default:
9517                         continue;
9518                 }
9519                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
9520                 imux->items[imux->num_items].index = idx1;
9521                 imux->num_items++;      
9522         }
9523         return 0;
9524 }
9525
9526 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
9527 {
9528         struct alc_spec *spec = codec->spec;
9529         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
9530         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
9531         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
9532         unsigned int    dac_vol1, dac_vol2;
9533
9534         if (speaker_nid) {
9535                 snd_hda_codec_write(codec, speaker_nid, 0,
9536                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
9537                 snd_hda_codec_write(codec, 0x0f, 0,
9538                                     AC_VERB_SET_AMP_GAIN_MUTE,
9539                                     AMP_IN_UNMUTE(1));
9540                 snd_hda_codec_write(codec, 0x10, 0,
9541                                     AC_VERB_SET_AMP_GAIN_MUTE,
9542                                     AMP_IN_UNMUTE(1));
9543         } else {
9544                 snd_hda_codec_write(codec, 0x0f, 0,
9545                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
9546                 snd_hda_codec_write(codec, 0x10, 0,
9547                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
9548         }
9549
9550         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
9551         if (line_nid == 0x14)   
9552                 dac_vol2 = AMP_OUT_ZERO;
9553         else if (line_nid == 0x15)
9554                 dac_vol1 = AMP_OUT_ZERO;
9555         if (hp_nid == 0x14)     
9556                 dac_vol2 = AMP_OUT_ZERO;
9557         else if (hp_nid == 0x15)
9558                 dac_vol1 = AMP_OUT_ZERO;
9559         if (line_nid != 0x16 || hp_nid != 0x16 ||
9560             spec->autocfg.line_out_pins[1] != 0x16 ||
9561             spec->autocfg.line_out_pins[2] != 0x16)
9562                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
9563
9564         snd_hda_codec_write(codec, 0x02, 0,
9565                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
9566         snd_hda_codec_write(codec, 0x03, 0,
9567                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
9568 }
9569
9570 /* pcm configuration: identiacal with ALC880 */
9571 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
9572 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
9573 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
9574
9575 /*
9576  * BIOS auto configuration
9577  */
9578 static int alc268_parse_auto_config(struct hda_codec *codec)
9579 {
9580         struct alc_spec *spec = codec->spec;
9581         int err;
9582         static hda_nid_t alc268_ignore[] = { 0 };
9583
9584         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
9585                                            alc268_ignore);
9586         if (err < 0)
9587                 return err;
9588         if (!spec->autocfg.line_outs)
9589                 return 0; /* can't find valid BIOS pin config */
9590
9591         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
9592         if (err < 0)
9593                 return err;
9594         err = alc268_auto_create_analog_input_ctls(spec, &spec->autocfg);
9595         if (err < 0)
9596                 return err;
9597
9598         spec->multiout.max_channels = 2;
9599
9600         /* digital only support output */
9601         if (spec->autocfg.dig_out_pin)
9602                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
9603
9604         if (spec->kctl_alloc)
9605                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
9606
9607         spec->init_verbs[spec->num_init_verbs++] = alc268_volume_init_verbs;
9608         spec->num_mux_defs = 1;
9609         spec->input_mux = &spec->private_imux;
9610
9611         err = alc_auto_add_mic_boost(codec);
9612         if (err < 0)
9613                 return err;
9614
9615         return 1;
9616 }
9617
9618 #define alc268_auto_init_multi_out      alc882_auto_init_multi_out
9619 #define alc268_auto_init_hp_out         alc882_auto_init_hp_out
9620 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
9621
9622 /* init callback for auto-configuration model -- overriding the default init */
9623 static void alc268_auto_init(struct hda_codec *codec)
9624 {
9625         alc268_auto_init_multi_out(codec);
9626         alc268_auto_init_hp_out(codec);
9627         alc268_auto_init_mono_speaker_out(codec);
9628         alc268_auto_init_analog_input(codec);
9629 }
9630
9631 /*
9632  * configuration and preset
9633  */
9634 static const char *alc268_models[ALC268_MODEL_LAST] = {
9635         [ALC268_3ST]            = "3stack",
9636         [ALC268_TOSHIBA]        = "toshiba",
9637         [ALC268_ACER]           = "acer",
9638 #ifdef CONFIG_SND_DEBUG
9639         [ALC268_TEST]           = "test",
9640 #endif
9641         [ALC268_AUTO]           = "auto",
9642 };
9643
9644 static struct snd_pci_quirk alc268_cfg_tbl[] = {
9645         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
9646         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
9647         SND_PCI_QUIRK(0x103c, 0x30cc, "TOSHIBA", ALC268_TOSHIBA),
9648         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
9649         SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA),
9650         SND_PCI_QUIRK(0x1179, 0xff50, "TOSHIBA A305", ALC268_TOSHIBA),
9651         SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
9652         {}
9653 };
9654
9655 static struct alc_config_preset alc268_presets[] = {
9656         [ALC268_3ST] = {
9657                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer },
9658                 .init_verbs = { alc268_base_init_verbs },
9659                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
9660                 .dac_nids = alc268_dac_nids,
9661                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
9662                 .adc_nids = alc268_adc_nids_alt,
9663                 .hp_nid = 0x03,
9664                 .dig_out_nid = ALC268_DIGOUT_NID,
9665                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
9666                 .channel_mode = alc268_modes,
9667                 .input_mux = &alc268_capture_source,
9668         },
9669         [ALC268_TOSHIBA] = {
9670                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer },
9671                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
9672                                 alc268_toshiba_verbs },
9673                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
9674                 .dac_nids = alc268_dac_nids,
9675                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
9676                 .adc_nids = alc268_adc_nids_alt,
9677                 .hp_nid = 0x03,
9678                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
9679                 .channel_mode = alc268_modes,
9680                 .input_mux = &alc268_capture_source,
9681                 .unsol_event = alc268_toshiba_unsol_event,
9682                 .init_hook = alc268_toshiba_automute,
9683         },
9684         [ALC268_ACER] = {
9685                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer },
9686                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
9687                                 alc268_acer_verbs },
9688                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
9689                 .dac_nids = alc268_dac_nids,
9690                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
9691                 .adc_nids = alc268_adc_nids_alt,
9692                 .hp_nid = 0x02,
9693                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
9694                 .channel_mode = alc268_modes,
9695                 .input_mux = &alc268_capture_source,
9696                 .unsol_event = alc268_acer_unsol_event,
9697                 .init_hook = alc268_acer_init_hook,
9698         },
9699 #ifdef CONFIG_SND_DEBUG
9700         [ALC268_TEST] = {
9701                 .mixers = { alc268_test_mixer, alc268_capture_mixer },
9702                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
9703                                 alc268_volume_init_verbs },
9704                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
9705                 .dac_nids = alc268_dac_nids,
9706                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
9707                 .adc_nids = alc268_adc_nids_alt,
9708                 .hp_nid = 0x03,
9709                 .dig_out_nid = ALC268_DIGOUT_NID,
9710                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
9711                 .channel_mode = alc268_modes,
9712                 .input_mux = &alc268_capture_source,
9713         },
9714 #endif
9715 };
9716
9717 static int patch_alc268(struct hda_codec *codec)
9718 {
9719         struct alc_spec *spec;
9720         int board_config;
9721         int err;
9722
9723         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
9724         if (spec == NULL)
9725                 return -ENOMEM;
9726
9727         codec->spec = spec;
9728
9729         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
9730                                                   alc268_models,
9731                                                   alc268_cfg_tbl);
9732
9733         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
9734                 printk(KERN_INFO "hda_codec: Unknown model for ALC268, "
9735                        "trying auto-probe from BIOS...\n");
9736                 board_config = ALC268_AUTO;
9737         }
9738
9739         if (board_config == ALC268_AUTO) {
9740                 /* automatic parse from the BIOS config */
9741                 err = alc268_parse_auto_config(codec);
9742                 if (err < 0) {
9743                         alc_free(codec);
9744                         return err;
9745                 } else if (!err) {
9746                         printk(KERN_INFO
9747                                "hda_codec: Cannot set up configuration "
9748                                "from BIOS.  Using base mode...\n");
9749                         board_config = ALC268_3ST;
9750                 }
9751         }
9752
9753         if (board_config != ALC268_AUTO)
9754                 setup_preset(spec, &alc268_presets[board_config]);
9755
9756         spec->stream_name_analog = "ALC268 Analog";
9757         spec->stream_analog_playback = &alc268_pcm_analog_playback;
9758         spec->stream_analog_capture = &alc268_pcm_analog_capture;
9759
9760         spec->stream_name_digital = "ALC268 Digital";
9761         spec->stream_digital_playback = &alc268_pcm_digital_playback;
9762
9763         if (board_config == ALC268_AUTO) {
9764                 if (!spec->adc_nids && spec->input_mux) {
9765                         /* check whether NID 0x07 is valid */
9766                         unsigned int wcap = get_wcaps(codec, 0x07);
9767
9768                         /* get type */
9769                         wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
9770                         if (wcap != AC_WID_AUD_IN) {
9771                                 spec->adc_nids = alc268_adc_nids_alt;
9772                                 spec->num_adc_nids =
9773                                         ARRAY_SIZE(alc268_adc_nids_alt);
9774                                 spec->mixers[spec->num_mixers] =
9775                                         alc268_capture_alt_mixer;
9776                                 spec->num_mixers++;
9777                         } else {
9778                                 spec->adc_nids = alc268_adc_nids;
9779                                 spec->num_adc_nids =
9780                                         ARRAY_SIZE(alc268_adc_nids);
9781                                 spec->mixers[spec->num_mixers] =
9782                                         alc268_capture_mixer;
9783                                 spec->num_mixers++;
9784                         }
9785                 }
9786         }
9787         codec->patch_ops = alc_patch_ops;
9788         if (board_config == ALC268_AUTO)
9789                 spec->init_hook = alc268_auto_init;
9790                 
9791         return 0;
9792 }
9793
9794 /*
9795  *  ALC269 channel source setting (2 channel)
9796  */
9797 #define ALC269_DIGOUT_NID       ALC880_DIGOUT_NID
9798
9799 #define alc269_dac_nids         alc260_dac_nids
9800
9801 static hda_nid_t alc269_adc_nids[1] = {
9802         /* ADC1 */
9803         0x07,
9804 };
9805
9806 #define alc269_modes            alc260_modes
9807 #define alc269_capture_source   alc880_lg_lw_capture_source
9808
9809 static struct snd_kcontrol_new alc269_base_mixer[] = {
9810         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
9811         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9812         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9813         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9814         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9815         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9816         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9817         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9818         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9819         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9820         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9821         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
9822         { } /* end */
9823 };
9824
9825 /* capture mixer elements */
9826 static struct snd_kcontrol_new alc269_capture_mixer[] = {
9827         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
9828         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
9829         {
9830                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9831                 /* The multiple "Capture Source" controls confuse alsamixer
9832                  * So call somewhat different..
9833                  * FIXME: the controls appear in the "playback" view!
9834                  */
9835                 /* .name = "Capture Source", */
9836                 .name = "Input Source",
9837                 .count = 1,
9838                 .info = alc_mux_enum_info,
9839                 .get = alc_mux_enum_get,
9840                 .put = alc_mux_enum_put,
9841         },
9842         { } /* end */
9843 };
9844
9845 /*
9846  * generic initialization of ADC, input mixers and output mixers
9847  */
9848 static struct hda_verb alc269_init_verbs[] = {
9849         /*
9850          * Unmute ADC0 and set the default input to mic-in
9851          */
9852         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9853
9854         /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the
9855          * analog-loopback mixer widget
9856          * Note: PASD motherboards uses the Line In 2 as the input for
9857          * front panel mic (mic 2)
9858          */
9859         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9860         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9861         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9862         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9863         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9864         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9865
9866         /*
9867          * Set up output mixers (0x0c - 0x0e)
9868          */
9869         /* set vol=0 to output mixers */
9870         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9871         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9872
9873         /* set up input amps for analog loopback */
9874         /* Amp Indices: DAC = 0, mixer = 1 */
9875         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9876         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9877         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9878         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9879         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9880         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9881
9882         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9883         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9884         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9885         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
9886         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
9887         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9888         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9889
9890         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9891         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9892         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9893         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9894         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9895         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9896         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9897
9898         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
9899         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9900
9901         /* FIXME: use matrix-type input source selection */
9902         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
9903         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9904         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9905         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9906         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9907         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9908
9909         /* set EAPD */
9910         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
9911         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
9912         { }
9913 };
9914
9915 /* add playback controls from the parsed DAC table */
9916 static int alc269_auto_create_multi_out_ctls(struct alc_spec *spec,
9917                                              const struct auto_pin_cfg *cfg)
9918 {
9919         hda_nid_t nid;
9920         int err;
9921
9922         spec->multiout.num_dacs = 1;    /* only use one dac */
9923         spec->multiout.dac_nids = spec->private_dac_nids;
9924         spec->multiout.dac_nids[0] = 2;
9925
9926         nid = cfg->line_out_pins[0];
9927         if (nid) {
9928                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
9929                                   "Front Playback Volume",
9930                                   HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT));
9931                 if (err < 0)
9932                         return err;
9933                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9934                                   "Front Playback Switch",
9935                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
9936                 if (err < 0)
9937                         return err;
9938         }
9939
9940         nid = cfg->speaker_pins[0];
9941         if (nid) {
9942                 if (!cfg->line_out_pins[0]) {
9943                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
9944                                           "Speaker Playback Volume",
9945                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
9946                                                               HDA_OUTPUT));
9947                         if (err < 0)
9948                                 return err;
9949                 }
9950                 if (nid == 0x16) {
9951                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9952                                           "Speaker Playback Switch",
9953                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
9954                                                               HDA_OUTPUT));
9955                         if (err < 0)
9956                                 return err;
9957                 } else {
9958                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9959                                           "Speaker Playback Switch",
9960                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
9961                                                               HDA_OUTPUT));
9962                         if (err < 0)
9963                                 return err;
9964                 }
9965         }
9966         nid = cfg->hp_pins[0];
9967         if (nid) {
9968                 /* spec->multiout.hp_nid = 2; */
9969                 if (!cfg->line_out_pins[0] && !cfg->speaker_pins[0]) {
9970                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
9971                                           "Headphone Playback Volume",
9972                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
9973                                                               HDA_OUTPUT));
9974                         if (err < 0)
9975                                 return err;
9976                 }
9977                 if (nid == 0x16) {
9978                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9979                                           "Headphone Playback Switch",
9980                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
9981                                                               HDA_OUTPUT));
9982                         if (err < 0)
9983                                 return err;
9984                 } else {
9985                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9986                                           "Headphone Playback Switch",
9987                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
9988                                                               HDA_OUTPUT));
9989                         if (err < 0)
9990                                 return err;
9991                 }
9992         }
9993         return 0;
9994 }
9995
9996 #define alc269_auto_create_analog_input_ctls \
9997         alc880_auto_create_analog_input_ctls
9998
9999 #ifdef CONFIG_SND_HDA_POWER_SAVE
10000 #define alc269_loopbacks        alc880_loopbacks
10001 #endif
10002
10003 /* pcm configuration: identiacal with ALC880 */
10004 #define alc269_pcm_analog_playback      alc880_pcm_analog_playback
10005 #define alc269_pcm_analog_capture       alc880_pcm_analog_capture
10006 #define alc269_pcm_digital_playback     alc880_pcm_digital_playback
10007 #define alc269_pcm_digital_capture      alc880_pcm_digital_capture
10008
10009 /*
10010  * BIOS auto configuration
10011  */
10012 static int alc269_parse_auto_config(struct hda_codec *codec)
10013 {
10014         struct alc_spec *spec = codec->spec;
10015         int err;
10016         static hda_nid_t alc269_ignore[] = { 0x1d, 0 };
10017
10018         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
10019                                            alc269_ignore);
10020         if (err < 0)
10021                 return err;
10022
10023         err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
10024         if (err < 0)
10025                 return err;
10026         err = alc269_auto_create_analog_input_ctls(spec, &spec->autocfg);
10027         if (err < 0)
10028                 return err;
10029
10030         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
10031
10032         if (spec->autocfg.dig_out_pin)
10033                 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;
10034
10035         if (spec->kctl_alloc)
10036                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
10037
10038         spec->init_verbs[spec->num_init_verbs++] = alc269_init_verbs;
10039         spec->num_mux_defs = 1;
10040         spec->input_mux = &spec->private_imux;
10041
10042         err = alc_auto_add_mic_boost(codec);
10043         if (err < 0)
10044                 return err;
10045
10046         return 1;
10047 }
10048
10049 #define alc269_auto_init_multi_out      alc882_auto_init_multi_out
10050 #define alc269_auto_init_hp_out         alc882_auto_init_hp_out
10051 #define alc269_auto_init_analog_input   alc882_auto_init_analog_input
10052
10053
10054 /* init callback for auto-configuration model -- overriding the default init */
10055 static void alc269_auto_init(struct hda_codec *codec)
10056 {
10057         alc269_auto_init_multi_out(codec);
10058         alc269_auto_init_hp_out(codec);
10059         alc269_auto_init_analog_input(codec);
10060 }
10061
10062 /*
10063  * configuration and preset
10064  */
10065 static const char *alc269_models[ALC269_MODEL_LAST] = {
10066         [ALC269_BASIC]          = "basic",
10067 };
10068
10069 static struct snd_pci_quirk alc269_cfg_tbl[] = {
10070         {}
10071 };
10072
10073 static struct alc_config_preset alc269_presets[] = {
10074         [ALC269_BASIC] = {
10075                 .mixers = { alc269_base_mixer },
10076                 .init_verbs = { alc269_init_verbs },
10077                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
10078                 .dac_nids = alc269_dac_nids,
10079                 .hp_nid = 0x03,
10080                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
10081                 .channel_mode = alc269_modes,
10082                 .input_mux = &alc269_capture_source,
10083         },
10084 };
10085
10086 static int patch_alc269(struct hda_codec *codec)
10087 {
10088         struct alc_spec *spec;
10089         int board_config;
10090         int err;
10091
10092         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
10093         if (spec == NULL)
10094                 return -ENOMEM;
10095
10096         codec->spec = spec;
10097
10098         board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
10099                                                   alc269_models,
10100                                                   alc269_cfg_tbl);
10101
10102         if (board_config < 0) {
10103                 printk(KERN_INFO "hda_codec: Unknown model for ALC269, "
10104                        "trying auto-probe from BIOS...\n");
10105                 board_config = ALC269_AUTO;
10106         }
10107
10108         if (board_config == ALC269_AUTO) {
10109                 /* automatic parse from the BIOS config */
10110                 err = alc269_parse_auto_config(codec);
10111                 if (err < 0) {
10112                         alc_free(codec);
10113                         return err;
10114                 } else if (!err) {
10115                         printk(KERN_INFO
10116                                "hda_codec: Cannot set up configuration "
10117                                "from BIOS.  Using base mode...\n");
10118                         board_config = ALC269_BASIC;
10119                 }
10120         }
10121
10122         if (board_config != ALC269_AUTO)
10123                 setup_preset(spec, &alc269_presets[board_config]);
10124
10125         spec->stream_name_analog = "ALC269 Analog";
10126         spec->stream_analog_playback = &alc269_pcm_analog_playback;
10127         spec->stream_analog_capture = &alc269_pcm_analog_capture;
10128
10129         spec->stream_name_digital = "ALC269 Digital";
10130         spec->stream_digital_playback = &alc269_pcm_digital_playback;
10131         spec->stream_digital_capture = &alc269_pcm_digital_capture;
10132
10133         spec->adc_nids = alc269_adc_nids;
10134         spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
10135         spec->mixers[spec->num_mixers] = alc269_capture_mixer;
10136         spec->num_mixers++;
10137
10138         codec->patch_ops = alc_patch_ops;
10139         if (board_config == ALC269_AUTO)
10140                 spec->init_hook = alc269_auto_init;
10141 #ifdef CONFIG_SND_HDA_POWER_SAVE
10142         if (!spec->loopback.amplist)
10143                 spec->loopback.amplist = alc269_loopbacks;
10144 #endif
10145
10146         return 0;
10147 }
10148
10149 /*
10150  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
10151  */
10152
10153 /*
10154  * set the path ways for 2 channel output
10155  * need to set the codec line out and mic 1 pin widgets to inputs
10156  */
10157 static struct hda_verb alc861_threestack_ch2_init[] = {
10158         /* set pin widget 1Ah (line in) for input */
10159         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
10160         /* set pin widget 18h (mic1/2) for input, for mic also enable
10161          * the vref
10162          */
10163         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10164
10165         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
10166 #if 0
10167         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
10168         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
10169 #endif
10170         { } /* end */
10171 };
10172 /*
10173  * 6ch mode
10174  * need to set the codec line out and mic 1 pin widgets to outputs
10175  */
10176 static struct hda_verb alc861_threestack_ch6_init[] = {
10177         /* set pin widget 1Ah (line in) for output (Back Surround)*/
10178         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10179         /* set pin widget 18h (mic1) for output (CLFE)*/
10180         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10181
10182         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
10183         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
10184
10185         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
10186 #if 0
10187         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
10188         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
10189 #endif
10190         { } /* end */
10191 };
10192
10193 static struct hda_channel_mode alc861_threestack_modes[2] = {
10194         { 2, alc861_threestack_ch2_init },
10195         { 6, alc861_threestack_ch6_init },
10196 };
10197 /* Set mic1 as input and unmute the mixer */
10198 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
10199         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10200         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
10201         { } /* end */
10202 };
10203 /* Set mic1 as output and mute mixer */
10204 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
10205         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10206         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
10207         { } /* end */
10208 };
10209
10210 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
10211         { 2, alc861_uniwill_m31_ch2_init },
10212         { 4, alc861_uniwill_m31_ch4_init },
10213 };
10214
10215 /* Set mic1 and line-in as input and unmute the mixer */
10216 static struct hda_verb alc861_asus_ch2_init[] = {
10217         /* set pin widget 1Ah (line in) for input */
10218         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
10219         /* set pin widget 18h (mic1/2) for input, for mic also enable
10220          * the vref
10221          */
10222         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10223
10224         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
10225 #if 0
10226         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
10227         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
10228 #endif
10229         { } /* end */
10230 };
10231 /* Set mic1 nad line-in as output and mute mixer */
10232 static struct hda_verb alc861_asus_ch6_init[] = {
10233         /* set pin widget 1Ah (line in) for output (Back Surround)*/
10234         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10235         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
10236         /* set pin widget 18h (mic1) for output (CLFE)*/
10237         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10238         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
10239         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
10240         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
10241
10242         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
10243 #if 0
10244         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
10245         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
10246 #endif
10247         { } /* end */
10248 };
10249
10250 static struct hda_channel_mode alc861_asus_modes[2] = {
10251         { 2, alc861_asus_ch2_init },
10252         { 6, alc861_asus_ch6_init },
10253 };
10254
10255 /* patch-ALC861 */
10256
10257 static struct snd_kcontrol_new alc861_base_mixer[] = {
10258         /* output mixer control */
10259         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
10260         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
10261         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
10262         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
10263         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
10264
10265         /*Input mixer control */
10266         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
10267            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
10268         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
10269         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
10270         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
10271         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
10272         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
10273         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
10274         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
10275         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
10276
10277         /* Capture mixer control */
10278         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
10279         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
10280         {
10281                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10282                 .name = "Capture Source",
10283                 .count = 1,
10284                 .info = alc_mux_enum_info,
10285                 .get = alc_mux_enum_get,
10286                 .put = alc_mux_enum_put,
10287         },
10288         { } /* end */
10289 };
10290
10291 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
10292         /* output mixer control */
10293         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
10294         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
10295         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
10296         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
10297         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
10298
10299         /* Input mixer control */
10300         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
10301            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
10302         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
10303         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
10304         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
10305         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
10306         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
10307         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
10308         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
10309         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
10310
10311         /* Capture mixer control */
10312         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
10313         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
10314         {
10315                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10316                 .name = "Capture Source",
10317                 .count = 1,
10318                 .info = alc_mux_enum_info,
10319                 .get = alc_mux_enum_get,
10320                 .put = alc_mux_enum_put,
10321         },
10322         {
10323                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10324                 .name = "Channel Mode",
10325                 .info = alc_ch_mode_info,
10326                 .get = alc_ch_mode_get,
10327                 .put = alc_ch_mode_put,
10328                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
10329         },
10330         { } /* end */
10331 };
10332
10333 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
10334         /* output mixer control */
10335         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
10336         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
10337         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
10338         
10339         /*Capture mixer control */
10340         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
10341         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
10342         {
10343                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10344                 .name = "Capture Source",
10345                 .count = 1,
10346                 .info = alc_mux_enum_info,
10347                 .get = alc_mux_enum_get,
10348                 .put = alc_mux_enum_put,
10349         },
10350
10351         { } /* end */
10352 };
10353
10354 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
10355         /* output mixer control */
10356         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
10357         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
10358         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
10359         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
10360         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
10361
10362         /* Input mixer control */
10363         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
10364            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
10365         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
10366         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
10367         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
10368         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
10369         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
10370         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
10371         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
10372         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
10373
10374         /* Capture mixer control */
10375         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
10376         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
10377         {
10378                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10379                 .name = "Capture Source",
10380                 .count = 1,
10381                 .info = alc_mux_enum_info,
10382                 .get = alc_mux_enum_get,
10383                 .put = alc_mux_enum_put,
10384         },
10385         {
10386                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10387                 .name = "Channel Mode",
10388                 .info = alc_ch_mode_info,
10389                 .get = alc_ch_mode_get,
10390                 .put = alc_ch_mode_put,
10391                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
10392         },
10393         { } /* end */
10394 };
10395
10396 static struct snd_kcontrol_new alc861_asus_mixer[] = {
10397         /* output mixer control */
10398         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
10399         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
10400         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
10401         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
10402         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
10403
10404         /* Input mixer control */
10405         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
10406         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10407         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
10408         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
10409         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
10410         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
10411         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
10412         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
10413         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
10414         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
10415
10416         /* Capture mixer control */
10417         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
10418         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
10419         {
10420                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10421                 .name = "Capture Source",
10422                 .count = 1,
10423                 .info = alc_mux_enum_info,
10424                 .get = alc_mux_enum_get,
10425                 .put = alc_mux_enum_put,
10426         },
10427         {
10428                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10429                 .name = "Channel Mode",
10430                 .info = alc_ch_mode_info,
10431                 .get = alc_ch_mode_get,
10432                 .put = alc_ch_mode_put,
10433                 .private_value = ARRAY_SIZE(alc861_asus_modes),
10434         },
10435         { }
10436 };
10437
10438 /* additional mixer */
10439 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
10440         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
10441         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
10442         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x23, 0x0, HDA_OUTPUT),
10443         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x23, 0x0, HDA_OUTPUT),
10444         { }
10445 };
10446
10447 /*
10448  * generic initialization of ADC, input mixers and output mixers
10449  */
10450 static struct hda_verb alc861_base_init_verbs[] = {
10451         /*
10452          * Unmute ADC0 and set the default input to mic-in
10453          */
10454         /* port-A for surround (rear panel) */
10455         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10456         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
10457         /* port-B for mic-in (rear panel) with vref */
10458         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10459         /* port-C for line-in (rear panel) */
10460         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
10461         /* port-D for Front */
10462         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10463         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
10464         /* port-E for HP out (front panel) */
10465         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
10466         /* route front PCM to HP */
10467         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
10468         /* port-F for mic-in (front panel) with vref */
10469         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10470         /* port-G for CLFE (rear panel) */
10471         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10472         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
10473         /* port-H for side (rear panel) */
10474         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10475         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
10476         /* CD-in */
10477         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
10478         /* route front mic to ADC1*/
10479         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10480         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10481         
10482         /* Unmute DAC0~3 & spdif out*/
10483         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10484         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10485         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10486         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10487         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10488         
10489         /* Unmute Mixer 14 (mic) 1c (Line in)*/
10490         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10491         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10492         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10493         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10494         
10495         /* Unmute Stereo Mixer 15 */
10496         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10497         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10498         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10499         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
10500
10501         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10502         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10503         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10504         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10505         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10506         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10507         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10508         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10509         /* hp used DAC 3 (Front) */
10510         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
10511         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10512
10513         { }
10514 };
10515
10516 static struct hda_verb alc861_threestack_init_verbs[] = {
10517         /*
10518          * Unmute ADC0 and set the default input to mic-in
10519          */
10520         /* port-A for surround (rear panel) */
10521         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
10522         /* port-B for mic-in (rear panel) with vref */
10523         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10524         /* port-C for line-in (rear panel) */
10525         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
10526         /* port-D for Front */
10527         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10528         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
10529         /* port-E for HP out (front panel) */
10530         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
10531         /* route front PCM to HP */
10532         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
10533         /* port-F for mic-in (front panel) with vref */
10534         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10535         /* port-G for CLFE (rear panel) */
10536         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
10537         /* port-H for side (rear panel) */
10538         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
10539         /* CD-in */
10540         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
10541         /* route front mic to ADC1*/
10542         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10543         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10544         /* Unmute DAC0~3 & spdif out*/
10545         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10546         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10547         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10548         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10549         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10550         
10551         /* Unmute Mixer 14 (mic) 1c (Line in)*/
10552         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10553         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10554         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10555         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10556         
10557         /* Unmute Stereo Mixer 15 */
10558         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10559         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10560         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10561         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
10562
10563         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10564         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10565         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10566         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10567         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10568         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10569         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10570         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10571         /* hp used DAC 3 (Front) */
10572         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
10573         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10574         { }
10575 };
10576
10577 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
10578         /*
10579          * Unmute ADC0 and set the default input to mic-in
10580          */
10581         /* port-A for surround (rear panel) */
10582         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
10583         /* port-B for mic-in (rear panel) with vref */
10584         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10585         /* port-C for line-in (rear panel) */
10586         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
10587         /* port-D for Front */
10588         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10589         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
10590         /* port-E for HP out (front panel) */
10591         /* this has to be set to VREF80 */
10592         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10593         /* route front PCM to HP */
10594         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
10595         /* port-F for mic-in (front panel) with vref */
10596         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10597         /* port-G for CLFE (rear panel) */
10598         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
10599         /* port-H for side (rear panel) */
10600         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
10601         /* CD-in */
10602         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
10603         /* route front mic to ADC1*/
10604         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10605         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10606         /* Unmute DAC0~3 & spdif out*/
10607         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10608         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10609         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10610         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10611         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10612         
10613         /* Unmute Mixer 14 (mic) 1c (Line in)*/
10614         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10615         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10616         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10617         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10618         
10619         /* Unmute Stereo Mixer 15 */
10620         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10621         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10622         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10623         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
10624
10625         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10626         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10627         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10628         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10629         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10630         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10631         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10632         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10633         /* hp used DAC 3 (Front) */
10634         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
10635         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10636         { }
10637 };
10638
10639 static struct hda_verb alc861_asus_init_verbs[] = {
10640         /*
10641          * Unmute ADC0 and set the default input to mic-in
10642          */
10643         /* port-A for surround (rear panel)
10644          * according to codec#0 this is the HP jack
10645          */
10646         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
10647         /* route front PCM to HP */
10648         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
10649         /* port-B for mic-in (rear panel) with vref */
10650         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10651         /* port-C for line-in (rear panel) */
10652         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
10653         /* port-D for Front */
10654         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10655         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
10656         /* port-E for HP out (front panel) */
10657         /* this has to be set to VREF80 */
10658         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10659         /* route front PCM to HP */
10660         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
10661         /* port-F for mic-in (front panel) with vref */
10662         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10663         /* port-G for CLFE (rear panel) */
10664         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10665         /* port-H for side (rear panel) */
10666         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10667         /* CD-in */
10668         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
10669         /* route front mic to ADC1*/
10670         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10671         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10672         /* Unmute DAC0~3 & spdif out*/
10673         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10674         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10675         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10676         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10677         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10678         /* Unmute Mixer 14 (mic) 1c (Line in)*/
10679         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10680         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10681         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10682         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10683         
10684         /* Unmute Stereo Mixer 15 */
10685         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10686         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10687         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10688         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
10689
10690         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10691         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10692         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10693         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10694         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10695         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10696         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10697         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10698         /* hp used DAC 3 (Front) */
10699         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
10700         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10701         { }
10702 };
10703
10704 /* additional init verbs for ASUS laptops */
10705 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
10706         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
10707         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
10708         { }
10709 };
10710
10711 /*
10712  * generic initialization of ADC, input mixers and output mixers
10713  */
10714 static struct hda_verb alc861_auto_init_verbs[] = {
10715         /*
10716          * Unmute ADC0 and set the default input to mic-in
10717          */
10718         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
10719         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10720         
10721         /* Unmute DAC0~3 & spdif out*/
10722         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10723         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10724         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10725         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10726         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10727         
10728         /* Unmute Mixer 14 (mic) 1c (Line in)*/
10729         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10730         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10731         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10732         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10733         
10734         /* Unmute Stereo Mixer 15 */
10735         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10736         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10737         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10738         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
10739
10740         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10741         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10742         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10743         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10744         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10745         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10746         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10747         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10748
10749         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10750         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10751         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10752         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
10753         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10754         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10755         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10756         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
10757
10758         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
10759
10760         { }
10761 };
10762
10763 static struct hda_verb alc861_toshiba_init_verbs[] = {
10764         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10765
10766         { }
10767 };
10768
10769 /* toggle speaker-output according to the hp-jack state */
10770 static void alc861_toshiba_automute(struct hda_codec *codec)
10771 {
10772         unsigned int present;
10773
10774         present = snd_hda_codec_read(codec, 0x0f, 0,
10775                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10776         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
10777                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
10778         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
10779                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
10780 }
10781
10782 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
10783                                        unsigned int res)
10784 {
10785         if ((res >> 26) == ALC880_HP_EVENT)
10786                 alc861_toshiba_automute(codec);
10787 }
10788
10789 /* pcm configuration: identiacal with ALC880 */
10790 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
10791 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
10792 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
10793 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
10794
10795
10796 #define ALC861_DIGOUT_NID       0x07
10797
10798 static struct hda_channel_mode alc861_8ch_modes[1] = {
10799         { 8, NULL }
10800 };
10801
10802 static hda_nid_t alc861_dac_nids[4] = {
10803         /* front, surround, clfe, side */
10804         0x03, 0x06, 0x05, 0x04
10805 };
10806
10807 static hda_nid_t alc660_dac_nids[3] = {
10808         /* front, clfe, surround */
10809         0x03, 0x05, 0x06
10810 };
10811
10812 static hda_nid_t alc861_adc_nids[1] = {
10813         /* ADC0-2 */
10814         0x08,
10815 };
10816
10817 static struct hda_input_mux alc861_capture_source = {
10818         .num_items = 5,
10819         .items = {
10820                 { "Mic", 0x0 },
10821                 { "Front Mic", 0x3 },
10822                 { "Line", 0x1 },
10823                 { "CD", 0x4 },
10824                 { "Mixer", 0x5 },
10825         },
10826 };
10827
10828 /* fill in the dac_nids table from the parsed pin configuration */
10829 static int alc861_auto_fill_dac_nids(struct alc_spec *spec,
10830                                      const struct auto_pin_cfg *cfg)
10831 {
10832         int i;
10833         hda_nid_t nid;
10834
10835         spec->multiout.dac_nids = spec->private_dac_nids;
10836         for (i = 0; i < cfg->line_outs; i++) {
10837                 nid = cfg->line_out_pins[i];
10838                 if (nid) {
10839                         if (i >= ARRAY_SIZE(alc861_dac_nids))
10840                                 continue;
10841                         spec->multiout.dac_nids[i] = alc861_dac_nids[i];
10842                 }
10843         }
10844         spec->multiout.num_dacs = cfg->line_outs;
10845         return 0;
10846 }
10847
10848 /* add playback controls from the parsed DAC table */
10849 static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
10850                                              const struct auto_pin_cfg *cfg)
10851 {
10852         char name[32];
10853         static const char *chname[4] = {
10854                 "Front", "Surround", NULL /*CLFE*/, "Side"
10855         };
10856         hda_nid_t nid;
10857         int i, idx, err;
10858
10859         for (i = 0; i < cfg->line_outs; i++) {
10860                 nid = spec->multiout.dac_nids[i];
10861                 if (!nid)
10862                         continue;
10863                 if (nid == 0x05) {
10864                         /* Center/LFE */
10865                         err = add_control(spec, ALC_CTL_BIND_MUTE,
10866                                           "Center Playback Switch",
10867                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
10868                                                               HDA_OUTPUT));
10869                         if (err < 0)
10870                                 return err;
10871                         err = add_control(spec, ALC_CTL_BIND_MUTE,
10872                                           "LFE Playback Switch",
10873                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10874                                                               HDA_OUTPUT));
10875                         if (err < 0)
10876                                 return err;
10877                 } else {
10878                         for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1;
10879                              idx++)
10880                                 if (nid == alc861_dac_nids[idx])
10881                                         break;
10882                         sprintf(name, "%s Playback Switch", chname[idx]);
10883                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
10884                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10885                                                               HDA_OUTPUT));
10886                         if (err < 0)
10887                                 return err;
10888                 }
10889         }
10890         return 0;
10891 }
10892
10893 static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
10894 {
10895         int err;
10896         hda_nid_t nid;
10897
10898         if (!pin)
10899                 return 0;
10900
10901         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
10902                 nid = 0x03;
10903                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10904                                   "Headphone Playback Switch",
10905                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
10906                 if (err < 0)
10907                         return err;
10908                 spec->multiout.hp_nid = nid;
10909         }
10910         return 0;
10911 }
10912
10913 /* create playback/capture controls for input pins */
10914 static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec,
10915                                                 const struct auto_pin_cfg *cfg)
10916 {
10917         struct hda_input_mux *imux = &spec->private_imux;
10918         int i, err, idx, idx1;
10919
10920         for (i = 0; i < AUTO_PIN_LAST; i++) {
10921                 switch (cfg->input_pins[i]) {
10922                 case 0x0c:
10923                         idx1 = 1;
10924                         idx = 2;        /* Line In */
10925                         break;
10926                 case 0x0f:
10927                         idx1 = 2;
10928                         idx = 2;        /* Line In */
10929                         break;
10930                 case 0x0d:
10931                         idx1 = 0;
10932                         idx = 1;        /* Mic In */
10933                         break;
10934                 case 0x10:
10935                         idx1 = 3;
10936                         idx = 1;        /* Mic In */
10937                         break;
10938                 case 0x11:
10939                         idx1 = 4;
10940                         idx = 0;        /* CD */
10941                         break;
10942                 default:
10943                         continue;
10944                 }
10945
10946                 err = new_analog_input(spec, cfg->input_pins[i],
10947                                        auto_pin_cfg_labels[i], idx, 0x15);
10948                 if (err < 0)
10949                         return err;
10950
10951                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
10952                 imux->items[imux->num_items].index = idx1;
10953                 imux->num_items++;
10954         }
10955         return 0;
10956 }
10957
10958 static struct snd_kcontrol_new alc861_capture_mixer[] = {
10959         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
10960         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
10961
10962         {
10963                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10964                 /* The multiple "Capture Source" controls confuse alsamixer
10965                  * So call somewhat different..
10966                  *FIXME: the controls appear in the "playback" view!
10967                  */
10968                 /* .name = "Capture Source", */
10969                 .name = "Input Source",
10970                 .count = 1,
10971                 .info = alc_mux_enum_info,
10972                 .get = alc_mux_enum_get,
10973                 .put = alc_mux_enum_put,
10974         },
10975         { } /* end */
10976 };
10977
10978 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
10979                                               hda_nid_t nid,
10980                                               int pin_type, int dac_idx)
10981 {
10982         /* set as output */
10983
10984         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
10985                             pin_type);
10986         snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE,
10987                             AMP_OUT_UNMUTE);
10988
10989 }
10990
10991 static void alc861_auto_init_multi_out(struct hda_codec *codec)
10992 {
10993         struct alc_spec *spec = codec->spec;
10994         int i;
10995
10996         alc_subsystem_id(codec, 0x0e, 0x0f, 0x0b);
10997         for (i = 0; i < spec->autocfg.line_outs; i++) {
10998                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
10999                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
11000                 if (nid)
11001                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
11002                                                           spec->multiout.dac_nids[i]);
11003         }
11004 }
11005
11006 static void alc861_auto_init_hp_out(struct hda_codec *codec)
11007 {
11008         struct alc_spec *spec = codec->spec;
11009         hda_nid_t pin;
11010
11011         pin = spec->autocfg.hp_pins[0];
11012         if (pin) /* connect to front */
11013                 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
11014                                                   spec->multiout.dac_nids[0]);
11015 }
11016
11017 static void alc861_auto_init_analog_input(struct hda_codec *codec)
11018 {
11019         struct alc_spec *spec = codec->spec;
11020         int i;
11021
11022         for (i = 0; i < AUTO_PIN_LAST; i++) {
11023                 hda_nid_t nid = spec->autocfg.input_pins[i];
11024                 if (nid >= 0x0c && nid <= 0x11) {
11025                         snd_hda_codec_write(codec, nid, 0,
11026                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
11027                                             i <= AUTO_PIN_FRONT_MIC ?
11028                                             PIN_VREF80 : PIN_IN);
11029                 }
11030         }
11031 }
11032
11033 /* parse the BIOS configuration and set up the alc_spec */
11034 /* return 1 if successful, 0 if the proper config is not found,
11035  * or a negative error code
11036  */
11037 static int alc861_parse_auto_config(struct hda_codec *codec)
11038 {
11039         struct alc_spec *spec = codec->spec;
11040         int err;
11041         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
11042
11043         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11044                                            alc861_ignore);
11045         if (err < 0)
11046                 return err;
11047         if (!spec->autocfg.line_outs)
11048                 return 0; /* can't find valid BIOS pin config */
11049
11050         err = alc861_auto_fill_dac_nids(spec, &spec->autocfg);
11051         if (err < 0)
11052                 return err;
11053         err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg);
11054         if (err < 0)
11055                 return err;
11056         err = alc861_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
11057         if (err < 0)
11058                 return err;
11059         err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg);
11060         if (err < 0)
11061                 return err;
11062
11063         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
11064
11065         if (spec->autocfg.dig_out_pin)
11066                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
11067
11068         if (spec->kctl_alloc)
11069                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
11070
11071         spec->init_verbs[spec->num_init_verbs++] = alc861_auto_init_verbs;
11072
11073         spec->num_mux_defs = 1;
11074         spec->input_mux = &spec->private_imux;
11075
11076         spec->adc_nids = alc861_adc_nids;
11077         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
11078         spec->mixers[spec->num_mixers] = alc861_capture_mixer;
11079         spec->num_mixers++;
11080
11081         return 1;
11082 }
11083
11084 /* additional initialization for auto-configuration model */
11085 static void alc861_auto_init(struct hda_codec *codec)
11086 {
11087         alc861_auto_init_multi_out(codec);
11088         alc861_auto_init_hp_out(codec);
11089         alc861_auto_init_analog_input(codec);
11090 }
11091
11092 #ifdef CONFIG_SND_HDA_POWER_SAVE
11093 static struct hda_amp_list alc861_loopbacks[] = {
11094         { 0x15, HDA_INPUT, 0 },
11095         { 0x15, HDA_INPUT, 1 },
11096         { 0x15, HDA_INPUT, 2 },
11097         { 0x15, HDA_INPUT, 3 },
11098         { } /* end */
11099 };
11100 #endif
11101
11102
11103 /*
11104  * configuration and preset
11105  */
11106 static const char *alc861_models[ALC861_MODEL_LAST] = {
11107         [ALC861_3ST]            = "3stack",
11108         [ALC660_3ST]            = "3stack-660",
11109         [ALC861_3ST_DIG]        = "3stack-dig",
11110         [ALC861_6ST_DIG]        = "6stack-dig",
11111         [ALC861_UNIWILL_M31]    = "uniwill-m31",
11112         [ALC861_TOSHIBA]        = "toshiba",
11113         [ALC861_ASUS]           = "asus",
11114         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
11115         [ALC861_AUTO]           = "auto",
11116 };
11117
11118 static struct snd_pci_quirk alc861_cfg_tbl[] = {
11119         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
11120         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
11121         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
11122         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
11123         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
11124         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
11125         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
11126         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
11127          *        Any other models that need this preset?
11128          */
11129         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
11130         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
11131         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
11132         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
11133         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
11134         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
11135         /* FIXME: the below seems conflict */
11136         /* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
11137         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
11138         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
11139         {}
11140 };
11141
11142 static struct alc_config_preset alc861_presets[] = {
11143         [ALC861_3ST] = {
11144                 .mixers = { alc861_3ST_mixer },
11145                 .init_verbs = { alc861_threestack_init_verbs },
11146                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
11147                 .dac_nids = alc861_dac_nids,
11148                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
11149                 .channel_mode = alc861_threestack_modes,
11150                 .need_dac_fix = 1,
11151                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
11152                 .adc_nids = alc861_adc_nids,
11153                 .input_mux = &alc861_capture_source,
11154         },
11155         [ALC861_3ST_DIG] = {
11156                 .mixers = { alc861_base_mixer },
11157                 .init_verbs = { alc861_threestack_init_verbs },
11158                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
11159                 .dac_nids = alc861_dac_nids,
11160                 .dig_out_nid = ALC861_DIGOUT_NID,
11161                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
11162                 .channel_mode = alc861_threestack_modes,
11163                 .need_dac_fix = 1,
11164                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
11165                 .adc_nids = alc861_adc_nids,
11166                 .input_mux = &alc861_capture_source,
11167         },
11168         [ALC861_6ST_DIG] = {
11169                 .mixers = { alc861_base_mixer },
11170                 .init_verbs = { alc861_base_init_verbs },
11171                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
11172                 .dac_nids = alc861_dac_nids,
11173                 .dig_out_nid = ALC861_DIGOUT_NID,
11174                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
11175                 .channel_mode = alc861_8ch_modes,
11176                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
11177                 .adc_nids = alc861_adc_nids,
11178                 .input_mux = &alc861_capture_source,
11179         },
11180         [ALC660_3ST] = {
11181                 .mixers = { alc861_3ST_mixer },
11182                 .init_verbs = { alc861_threestack_init_verbs },
11183                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
11184                 .dac_nids = alc660_dac_nids,
11185                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
11186                 .channel_mode = alc861_threestack_modes,
11187                 .need_dac_fix = 1,
11188                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
11189                 .adc_nids = alc861_adc_nids,
11190                 .input_mux = &alc861_capture_source,
11191         },
11192         [ALC861_UNIWILL_M31] = {
11193                 .mixers = { alc861_uniwill_m31_mixer },
11194                 .init_verbs = { alc861_uniwill_m31_init_verbs },
11195                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
11196                 .dac_nids = alc861_dac_nids,
11197                 .dig_out_nid = ALC861_DIGOUT_NID,
11198                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
11199                 .channel_mode = alc861_uniwill_m31_modes,
11200                 .need_dac_fix = 1,
11201                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
11202                 .adc_nids = alc861_adc_nids,
11203                 .input_mux = &alc861_capture_source,
11204         },
11205         [ALC861_TOSHIBA] = {
11206                 .mixers = { alc861_toshiba_mixer },
11207                 .init_verbs = { alc861_base_init_verbs,
11208                                 alc861_toshiba_init_verbs },
11209                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
11210                 .dac_nids = alc861_dac_nids,
11211                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
11212                 .channel_mode = alc883_3ST_2ch_modes,
11213                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
11214                 .adc_nids = alc861_adc_nids,
11215                 .input_mux = &alc861_capture_source,
11216                 .unsol_event = alc861_toshiba_unsol_event,
11217                 .init_hook = alc861_toshiba_automute,
11218         },
11219         [ALC861_ASUS] = {
11220                 .mixers = { alc861_asus_mixer },
11221                 .init_verbs = { alc861_asus_init_verbs },
11222                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
11223                 .dac_nids = alc861_dac_nids,
11224                 .dig_out_nid = ALC861_DIGOUT_NID,
11225                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
11226                 .channel_mode = alc861_asus_modes,
11227                 .need_dac_fix = 1,
11228                 .hp_nid = 0x06,
11229                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
11230                 .adc_nids = alc861_adc_nids,
11231                 .input_mux = &alc861_capture_source,
11232         },
11233         [ALC861_ASUS_LAPTOP] = {
11234                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
11235                 .init_verbs = { alc861_asus_init_verbs,
11236                                 alc861_asus_laptop_init_verbs },
11237                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
11238                 .dac_nids = alc861_dac_nids,
11239                 .dig_out_nid = ALC861_DIGOUT_NID,
11240                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
11241                 .channel_mode = alc883_3ST_2ch_modes,
11242                 .need_dac_fix = 1,
11243                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
11244                 .adc_nids = alc861_adc_nids,
11245                 .input_mux = &alc861_capture_source,
11246         },
11247 };
11248
11249
11250 static int patch_alc861(struct hda_codec *codec)
11251 {
11252         struct alc_spec *spec;
11253         int board_config;
11254         int err;
11255
11256         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
11257         if (spec == NULL)
11258                 return -ENOMEM;
11259
11260         codec->spec = spec;
11261
11262         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
11263                                                   alc861_models,
11264                                                   alc861_cfg_tbl);
11265
11266         if (board_config < 0) {
11267                 printk(KERN_INFO "hda_codec: Unknown model for ALC861, "
11268                        "trying auto-probe from BIOS...\n");
11269                 board_config = ALC861_AUTO;
11270         }
11271
11272         if (board_config == ALC861_AUTO) {
11273                 /* automatic parse from the BIOS config */
11274                 err = alc861_parse_auto_config(codec);
11275                 if (err < 0) {
11276                         alc_free(codec);
11277                         return err;
11278                 } else if (!err) {
11279                         printk(KERN_INFO
11280                                "hda_codec: Cannot set up configuration "
11281                                "from BIOS.  Using base mode...\n");
11282                    board_config = ALC861_3ST_DIG;
11283                 }
11284         }
11285
11286         if (board_config != ALC861_AUTO)
11287                 setup_preset(spec, &alc861_presets[board_config]);
11288
11289         spec->stream_name_analog = "ALC861 Analog";
11290         spec->stream_analog_playback = &alc861_pcm_analog_playback;
11291         spec->stream_analog_capture = &alc861_pcm_analog_capture;
11292
11293         spec->stream_name_digital = "ALC861 Digital";
11294         spec->stream_digital_playback = &alc861_pcm_digital_playback;
11295         spec->stream_digital_capture = &alc861_pcm_digital_capture;
11296
11297         codec->patch_ops = alc_patch_ops;
11298         if (board_config == ALC861_AUTO)
11299                 spec->init_hook = alc861_auto_init;
11300 #ifdef CONFIG_SND_HDA_POWER_SAVE
11301         if (!spec->loopback.amplist)
11302                 spec->loopback.amplist = alc861_loopbacks;
11303 #endif
11304                 
11305         return 0;
11306 }
11307
11308 /*
11309  * ALC861-VD support
11310  *
11311  * Based on ALC882
11312  *
11313  * In addition, an independent DAC
11314  */
11315 #define ALC861VD_DIGOUT_NID     0x06
11316
11317 static hda_nid_t alc861vd_dac_nids[4] = {
11318         /* front, surr, clfe, side surr */
11319         0x02, 0x03, 0x04, 0x05
11320 };
11321
11322 /* dac_nids for ALC660vd are in a different order - according to
11323  * Realtek's driver.
11324  * This should probably tesult in a different mixer for 6stack models
11325  * of ALC660vd codecs, but for now there is only 3stack mixer
11326  * - and it is the same as in 861vd.
11327  * adc_nids in ALC660vd are (is) the same as in 861vd
11328  */
11329 static hda_nid_t alc660vd_dac_nids[3] = {
11330         /* front, rear, clfe, rear_surr */
11331         0x02, 0x04, 0x03
11332 };
11333
11334 static hda_nid_t alc861vd_adc_nids[1] = {
11335         /* ADC0 */
11336         0x09,
11337 };
11338
11339 /* input MUX */
11340 /* FIXME: should be a matrix-type input source selection */
11341 static struct hda_input_mux alc861vd_capture_source = {
11342         .num_items = 4,
11343         .items = {
11344                 { "Mic", 0x0 },
11345                 { "Front Mic", 0x1 },
11346                 { "Line", 0x2 },
11347                 { "CD", 0x4 },
11348         },
11349 };
11350
11351 static struct hda_input_mux alc861vd_dallas_capture_source = {
11352         .num_items = 3,
11353         .items = {
11354                 { "Front Mic", 0x0 },
11355                 { "ATAPI Mic", 0x1 },
11356                 { "Line In", 0x5 },
11357         },
11358 };
11359
11360 static struct hda_input_mux alc861vd_hp_capture_source = {
11361         .num_items = 2,
11362         .items = {
11363                 { "Front Mic", 0x0 },
11364                 { "ATAPI Mic", 0x1 },
11365         },
11366 };
11367
11368 #define alc861vd_mux_enum_info alc_mux_enum_info
11369 #define alc861vd_mux_enum_get alc_mux_enum_get
11370
11371 static int alc861vd_mux_enum_put(struct snd_kcontrol *kcontrol,
11372                                 struct snd_ctl_elem_value *ucontrol)
11373 {
11374         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
11375         struct alc_spec *spec = codec->spec;
11376         const struct hda_input_mux *imux = spec->input_mux;
11377         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
11378         static hda_nid_t capture_mixers[1] = { 0x22 };
11379         hda_nid_t nid = capture_mixers[adc_idx];
11380         unsigned int *cur_val = &spec->cur_mux[adc_idx];
11381         unsigned int i, idx;
11382
11383         idx = ucontrol->value.enumerated.item[0];
11384         if (idx >= imux->num_items)
11385                 idx = imux->num_items - 1;
11386         if (*cur_val == idx)
11387                 return 0;
11388         for (i = 0; i < imux->num_items; i++) {
11389                 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
11390                 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
11391                                          imux->items[i].index,
11392                                          HDA_AMP_MUTE, v);
11393         }
11394         *cur_val = idx;
11395         return 1;
11396 }
11397
11398 /*
11399  * 2ch mode
11400  */
11401 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
11402         { 2, NULL }
11403 };
11404
11405 /*
11406  * 6ch mode
11407  */
11408 static struct hda_verb alc861vd_6stack_ch6_init[] = {
11409         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11410         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11411         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11412         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11413         { } /* end */
11414 };
11415
11416 /*
11417  * 8ch mode
11418  */
11419 static struct hda_verb alc861vd_6stack_ch8_init[] = {
11420         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11421         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11422         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11423         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11424         { } /* end */
11425 };
11426
11427 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
11428         { 6, alc861vd_6stack_ch6_init },
11429         { 8, alc861vd_6stack_ch8_init },
11430 };
11431
11432 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
11433         {
11434                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11435                 .name = "Channel Mode",
11436                 .info = alc_ch_mode_info,
11437                 .get = alc_ch_mode_get,
11438                 .put = alc_ch_mode_put,
11439         },
11440         { } /* end */
11441 };
11442
11443 static struct snd_kcontrol_new alc861vd_capture_mixer[] = {
11444         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
11445         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
11446
11447         {
11448                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11449                 /* The multiple "Capture Source" controls confuse alsamixer
11450                  * So call somewhat different..
11451                  *FIXME: the controls appear in the "playback" view!
11452                  */
11453                 /* .name = "Capture Source", */
11454                 .name = "Input Source",
11455                 .count = 1,
11456                 .info = alc861vd_mux_enum_info,
11457                 .get = alc861vd_mux_enum_get,
11458                 .put = alc861vd_mux_enum_put,
11459         },
11460         { } /* end */
11461 };
11462
11463 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
11464  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
11465  */
11466 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
11467         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11468         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
11469
11470         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11471         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
11472
11473         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
11474                                 HDA_OUTPUT),
11475         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
11476                                 HDA_OUTPUT),
11477         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
11478         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
11479
11480         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
11481         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
11482
11483         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
11484
11485         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11486         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11487         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11488
11489         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11490         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
11491         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
11492
11493         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
11494         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11495
11496         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
11497         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
11498
11499         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
11500         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
11501
11502         { } /* end */
11503 };
11504
11505 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
11506         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11507         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
11508
11509         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
11510
11511         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11512         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11513         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11514
11515         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11516         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
11517         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
11518
11519         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
11520         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11521
11522         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
11523         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
11524
11525         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
11526         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
11527
11528         { } /* end */
11529 };
11530
11531 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
11532         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11533         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
11534         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11535
11536         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
11537
11538         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11539         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11540         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11541
11542         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11543         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
11544         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
11545
11546         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
11547         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
11548
11549         { } /* end */
11550 };
11551
11552 /* Pin assignment: Front=0x14, HP = 0x15,
11553  *                 Front Mic=0x18, ATAPI Mic = 0x19, Line In = 0x1d
11554  */
11555 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
11556         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11557         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
11558         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11559         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
11560         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11561         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11562         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
11563         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
11564         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x05, HDA_INPUT),
11565         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x05, HDA_INPUT),
11566         { } /* end */
11567 };
11568
11569 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
11570  *                 Front Mic=0x18, ATAPI Mic = 0x19,
11571  */
11572 static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
11573         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11574         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
11575         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11576         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
11577         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11578         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11579         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
11580         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
11581         
11582         { } /* end */
11583 };
11584
11585 /*
11586  * generic initialization of ADC, input mixers and output mixers
11587  */
11588 static struct hda_verb alc861vd_volume_init_verbs[] = {
11589         /*
11590          * Unmute ADC0 and set the default input to mic-in
11591          */
11592         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
11593         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11594
11595         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
11596          * the analog-loopback mixer widget
11597          */
11598         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11599         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11600         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11601         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11602         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11603         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11604
11605         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
11606         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11607         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11608         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11609         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
11610
11611         /*
11612          * Set up output mixers (0x02 - 0x05)
11613          */
11614         /* set vol=0 to output mixers */
11615         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11616         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11617         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11618         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11619
11620         /* set up input amps for analog loopback */
11621         /* Amp Indices: DAC = 0, mixer = 1 */
11622         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11623         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11624         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11625         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11626         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11627         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11628         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11629         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11630
11631         { }
11632 };
11633
11634 /*
11635  * 3-stack pin configuration:
11636  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
11637  */
11638 static struct hda_verb alc861vd_3stack_init_verbs[] = {
11639         /*
11640          * Set pin mode and muting
11641          */
11642         /* set front pin widgets 0x14 for output */
11643         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11644         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11645         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
11646
11647         /* Mic (rear) pin: input vref at 80% */
11648         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11649         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11650         /* Front Mic pin: input vref at 80% */
11651         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11652         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11653         /* Line In pin: input */
11654         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11655         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11656         /* Line-2 In: Headphone output (output 0 - 0x0c) */
11657         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11658         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11659         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
11660         /* CD pin widget for input */
11661         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11662
11663         { }
11664 };
11665
11666 /*
11667  * 6-stack pin configuration:
11668  */
11669 static struct hda_verb alc861vd_6stack_init_verbs[] = {
11670         /*
11671          * Set pin mode and muting
11672          */
11673         /* set front pin widgets 0x14 for output */
11674         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11675         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11676         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
11677
11678         /* Rear Pin: output 1 (0x0d) */
11679         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11680         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11681         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
11682         /* CLFE Pin: output 2 (0x0e) */
11683         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11684         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11685         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
11686         /* Side Pin: output 3 (0x0f) */
11687         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11688         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11689         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
11690
11691         /* Mic (rear) pin: input vref at 80% */
11692         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11693         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11694         /* Front Mic pin: input vref at 80% */
11695         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11696         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11697         /* Line In pin: input */
11698         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11699         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11700         /* Line-2 In: Headphone output (output 0 - 0x0c) */
11701         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11702         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11703         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
11704         /* CD pin widget for input */
11705         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11706
11707         { }
11708 };
11709
11710 static struct hda_verb alc861vd_eapd_verbs[] = {
11711         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
11712         { }
11713 };
11714
11715 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
11716         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11717         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11718         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
11719         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11720         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT}, 
11721         {}
11722 };
11723
11724 /* toggle speaker-output according to the hp-jack state */
11725 static void alc861vd_lenovo_hp_automute(struct hda_codec *codec)
11726 {
11727         unsigned int present;
11728         unsigned char bits;
11729
11730         present = snd_hda_codec_read(codec, 0x1b, 0,
11731                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11732         bits = present ? HDA_AMP_MUTE : 0;
11733         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
11734                                  HDA_AMP_MUTE, bits);
11735 }
11736
11737 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
11738 {
11739         unsigned int present;
11740         unsigned char bits;
11741
11742         present = snd_hda_codec_read(codec, 0x18, 0,
11743                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11744         bits = present ? HDA_AMP_MUTE : 0;
11745         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
11746                                  HDA_AMP_MUTE, bits);
11747 }
11748
11749 static void alc861vd_lenovo_automute(struct hda_codec *codec)
11750 {
11751         alc861vd_lenovo_hp_automute(codec);
11752         alc861vd_lenovo_mic_automute(codec);
11753 }
11754
11755 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
11756                                         unsigned int res)
11757 {
11758         switch (res >> 26) {
11759         case ALC880_HP_EVENT:
11760                 alc861vd_lenovo_hp_automute(codec);
11761                 break;
11762         case ALC880_MIC_EVENT:
11763                 alc861vd_lenovo_mic_automute(codec);
11764                 break;
11765         }
11766 }
11767
11768 static struct hda_verb alc861vd_dallas_verbs[] = {
11769         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11770         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11771         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11772         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11773
11774         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11775         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11776         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11777         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11778         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11779         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11780         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11781         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11782         
11783         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11784         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11785         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11786         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11787         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11788         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11789         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11790         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11791
11792         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
11793         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11794         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
11795         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11796         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11797         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11798         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11799         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11800
11801         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11802         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11803         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11804         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11805
11806         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11807         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},  
11808         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11809
11810         { } /* end */
11811 };
11812
11813 /* toggle speaker-output according to the hp-jack state */
11814 static void alc861vd_dallas_automute(struct hda_codec *codec)
11815 {
11816         unsigned int present;
11817
11818         present = snd_hda_codec_read(codec, 0x15, 0,
11819                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11820         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
11821                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
11822 }
11823
11824 static void alc861vd_dallas_unsol_event(struct hda_codec *codec, unsigned int res)
11825 {
11826         if ((res >> 26) == ALC880_HP_EVENT)
11827                 alc861vd_dallas_automute(codec);
11828 }
11829
11830 #ifdef CONFIG_SND_HDA_POWER_SAVE
11831 #define alc861vd_loopbacks      alc880_loopbacks
11832 #endif
11833
11834 /* pcm configuration: identiacal with ALC880 */
11835 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
11836 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
11837 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
11838 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
11839
11840 /*
11841  * configuration and preset
11842  */
11843 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
11844         [ALC660VD_3ST]          = "3stack-660",
11845         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
11846         [ALC861VD_3ST]          = "3stack",
11847         [ALC861VD_3ST_DIG]      = "3stack-digout",
11848         [ALC861VD_6ST_DIG]      = "6stack-digout",
11849         [ALC861VD_LENOVO]       = "lenovo",
11850         [ALC861VD_DALLAS]       = "dallas",
11851         [ALC861VD_HP]           = "hp",
11852         [ALC861VD_AUTO]         = "auto",
11853 };
11854
11855 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
11856         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
11857         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
11858         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
11859         SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),
11860         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
11861         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
11862         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
11863         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
11864         SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS),
11865         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
11866         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
11867         SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo", ALC861VD_LENOVO),
11868         SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo 3000 C200", ALC861VD_LENOVO),
11869         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
11870         {}
11871 };
11872
11873 static struct alc_config_preset alc861vd_presets[] = {
11874         [ALC660VD_3ST] = {
11875                 .mixers = { alc861vd_3st_mixer },
11876                 .init_verbs = { alc861vd_volume_init_verbs,
11877                                  alc861vd_3stack_init_verbs },
11878                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
11879                 .dac_nids = alc660vd_dac_nids,
11880                 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
11881                 .adc_nids = alc861vd_adc_nids,
11882                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
11883                 .channel_mode = alc861vd_3stack_2ch_modes,
11884                 .input_mux = &alc861vd_capture_source,
11885         },
11886         [ALC660VD_3ST_DIG] = {
11887                 .mixers = { alc861vd_3st_mixer },
11888                 .init_verbs = { alc861vd_volume_init_verbs,
11889                                  alc861vd_3stack_init_verbs },
11890                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
11891                 .dac_nids = alc660vd_dac_nids,
11892                 .dig_out_nid = ALC861VD_DIGOUT_NID,
11893                 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
11894                 .adc_nids = alc861vd_adc_nids,
11895                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
11896                 .channel_mode = alc861vd_3stack_2ch_modes,
11897                 .input_mux = &alc861vd_capture_source,
11898         },
11899         [ALC861VD_3ST] = {
11900                 .mixers = { alc861vd_3st_mixer },
11901                 .init_verbs = { alc861vd_volume_init_verbs,
11902                                  alc861vd_3stack_init_verbs },
11903                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
11904                 .dac_nids = alc861vd_dac_nids,
11905                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
11906                 .channel_mode = alc861vd_3stack_2ch_modes,
11907                 .input_mux = &alc861vd_capture_source,
11908         },
11909         [ALC861VD_3ST_DIG] = {
11910                 .mixers = { alc861vd_3st_mixer },
11911                 .init_verbs = { alc861vd_volume_init_verbs,
11912                                  alc861vd_3stack_init_verbs },
11913                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
11914                 .dac_nids = alc861vd_dac_nids,
11915                 .dig_out_nid = ALC861VD_DIGOUT_NID,
11916                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
11917                 .channel_mode = alc861vd_3stack_2ch_modes,
11918                 .input_mux = &alc861vd_capture_source,
11919         },
11920         [ALC861VD_6ST_DIG] = {
11921                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
11922                 .init_verbs = { alc861vd_volume_init_verbs,
11923                                 alc861vd_6stack_init_verbs },
11924                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
11925                 .dac_nids = alc861vd_dac_nids,
11926                 .dig_out_nid = ALC861VD_DIGOUT_NID,
11927                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
11928                 .channel_mode = alc861vd_6stack_modes,
11929                 .input_mux = &alc861vd_capture_source,
11930         },
11931         [ALC861VD_LENOVO] = {
11932                 .mixers = { alc861vd_lenovo_mixer },
11933                 .init_verbs = { alc861vd_volume_init_verbs,
11934                                 alc861vd_3stack_init_verbs,
11935                                 alc861vd_eapd_verbs,
11936                                 alc861vd_lenovo_unsol_verbs },
11937                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
11938                 .dac_nids = alc660vd_dac_nids,
11939                 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
11940                 .adc_nids = alc861vd_adc_nids,
11941                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
11942                 .channel_mode = alc861vd_3stack_2ch_modes,
11943                 .input_mux = &alc861vd_capture_source,
11944                 .unsol_event = alc861vd_lenovo_unsol_event,
11945                 .init_hook = alc861vd_lenovo_automute,
11946         },
11947         [ALC861VD_DALLAS] = {
11948                 .mixers = { alc861vd_dallas_mixer },
11949                 .init_verbs = { alc861vd_dallas_verbs },
11950                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
11951                 .dac_nids = alc861vd_dac_nids,
11952                 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
11953                 .adc_nids = alc861vd_adc_nids,
11954                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
11955                 .channel_mode = alc861vd_3stack_2ch_modes,
11956                 .input_mux = &alc861vd_dallas_capture_source,
11957                 .unsol_event = alc861vd_dallas_unsol_event,
11958                 .init_hook = alc861vd_dallas_automute,
11959         },
11960         [ALC861VD_HP] = {
11961                 .mixers = { alc861vd_hp_mixer },
11962                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
11963                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
11964                 .dac_nids = alc861vd_dac_nids,
11965                 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
11966                 .dig_out_nid = ALC861VD_DIGOUT_NID,
11967                 .adc_nids = alc861vd_adc_nids,
11968                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
11969                 .channel_mode = alc861vd_3stack_2ch_modes,
11970                 .input_mux = &alc861vd_hp_capture_source,
11971                 .unsol_event = alc861vd_dallas_unsol_event,
11972                 .init_hook = alc861vd_dallas_automute,
11973         },              
11974 };
11975
11976 /*
11977  * BIOS auto configuration
11978  */
11979 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
11980                                 hda_nid_t nid, int pin_type, int dac_idx)
11981 {
11982         /* set as output */
11983         snd_hda_codec_write(codec, nid, 0,
11984                                 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
11985         snd_hda_codec_write(codec, nid, 0,
11986                                 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
11987 }
11988
11989 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
11990 {
11991         struct alc_spec *spec = codec->spec;
11992         int i;
11993
11994         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
11995         for (i = 0; i <= HDA_SIDE; i++) {
11996                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
11997                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
11998                 if (nid)
11999                         alc861vd_auto_set_output_and_unmute(codec, nid,
12000                                                             pin_type, i);
12001         }
12002 }
12003
12004
12005 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
12006 {
12007         struct alc_spec *spec = codec->spec;
12008         hda_nid_t pin;
12009
12010         pin = spec->autocfg.hp_pins[0];
12011         if (pin) /* connect to front and  use dac 0 */
12012                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
12013 }
12014
12015 #define alc861vd_is_input_pin(nid)      alc880_is_input_pin(nid)
12016 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
12017
12018 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
12019 {
12020         struct alc_spec *spec = codec->spec;
12021         int i;
12022
12023         for (i = 0; i < AUTO_PIN_LAST; i++) {
12024                 hda_nid_t nid = spec->autocfg.input_pins[i];
12025                 if (alc861vd_is_input_pin(nid)) {
12026                         snd_hda_codec_write(codec, nid, 0,
12027                                         AC_VERB_SET_PIN_WIDGET_CONTROL,
12028                                         i <= AUTO_PIN_FRONT_MIC ?
12029                                                         PIN_VREF80 : PIN_IN);
12030                         if (nid != ALC861VD_PIN_CD_NID)
12031                                 snd_hda_codec_write(codec, nid, 0,
12032                                                 AC_VERB_SET_AMP_GAIN_MUTE,
12033                                                 AMP_OUT_MUTE);
12034                 }
12035         }
12036 }
12037
12038 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
12039 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
12040
12041 /* add playback controls from the parsed DAC table */
12042 /* Based on ALC880 version. But ALC861VD has separate,
12043  * different NIDs for mute/unmute switch and volume control */
12044 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
12045                                              const struct auto_pin_cfg *cfg)
12046 {
12047         char name[32];
12048         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
12049         hda_nid_t nid_v, nid_s;
12050         int i, err;
12051
12052         for (i = 0; i < cfg->line_outs; i++) {
12053                 if (!spec->multiout.dac_nids[i])
12054                         continue;
12055                 nid_v = alc861vd_idx_to_mixer_vol(
12056                                 alc880_dac_to_idx(
12057                                         spec->multiout.dac_nids[i]));
12058                 nid_s = alc861vd_idx_to_mixer_switch(
12059                                 alc880_dac_to_idx(
12060                                         spec->multiout.dac_nids[i]));
12061
12062                 if (i == 2) {
12063                         /* Center/LFE */
12064                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12065                                           "Center Playback Volume",
12066                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
12067                                                               HDA_OUTPUT));
12068                         if (err < 0)
12069                                 return err;
12070                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12071                                           "LFE Playback Volume",
12072                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
12073                                                               HDA_OUTPUT));
12074                         if (err < 0)
12075                                 return err;
12076                         err = add_control(spec, ALC_CTL_BIND_MUTE,
12077                                           "Center Playback Switch",
12078                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
12079                                                               HDA_INPUT));
12080                         if (err < 0)
12081                                 return err;
12082                         err = add_control(spec, ALC_CTL_BIND_MUTE,
12083                                           "LFE Playback Switch",
12084                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
12085                                                               HDA_INPUT));
12086                         if (err < 0)
12087                                 return err;
12088                 } else {
12089                         sprintf(name, "%s Playback Volume", chname[i]);
12090                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
12091                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
12092                                                               HDA_OUTPUT));
12093                         if (err < 0)
12094                                 return err;
12095                         sprintf(name, "%s Playback Switch", chname[i]);
12096                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
12097                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
12098                                                               HDA_INPUT));
12099                         if (err < 0)
12100                                 return err;
12101                 }
12102         }
12103         return 0;
12104 }
12105
12106 /* add playback controls for speaker and HP outputs */
12107 /* Based on ALC880 version. But ALC861VD has separate,
12108  * different NIDs for mute/unmute switch and volume control */
12109 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
12110                                         hda_nid_t pin, const char *pfx)
12111 {
12112         hda_nid_t nid_v, nid_s;
12113         int err;
12114         char name[32];
12115
12116         if (!pin)
12117                 return 0;
12118
12119         if (alc880_is_fixed_pin(pin)) {
12120                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
12121                 /* specify the DAC as the extra output */
12122                 if (!spec->multiout.hp_nid)
12123                         spec->multiout.hp_nid = nid_v;
12124                 else
12125                         spec->multiout.extra_out_nid[0] = nid_v;
12126                 /* control HP volume/switch on the output mixer amp */
12127                 nid_v = alc861vd_idx_to_mixer_vol(
12128                                 alc880_fixed_pin_idx(pin));
12129                 nid_s = alc861vd_idx_to_mixer_switch(
12130                                 alc880_fixed_pin_idx(pin));
12131
12132                 sprintf(name, "%s Playback Volume", pfx);
12133                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
12134                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
12135                 if (err < 0)
12136                         return err;
12137                 sprintf(name, "%s Playback Switch", pfx);
12138                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
12139                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
12140                 if (err < 0)
12141                         return err;
12142         } else if (alc880_is_multi_pin(pin)) {
12143                 /* set manual connection */
12144                 /* we have only a switch on HP-out PIN */
12145                 sprintf(name, "%s Playback Switch", pfx);
12146                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
12147                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
12148                 if (err < 0)
12149                         return err;
12150         }
12151         return 0;
12152 }
12153
12154 /* parse the BIOS configuration and set up the alc_spec
12155  * return 1 if successful, 0 if the proper config is not found,
12156  * or a negative error code
12157  * Based on ALC880 version - had to change it to override
12158  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
12159 static int alc861vd_parse_auto_config(struct hda_codec *codec)
12160 {
12161         struct alc_spec *spec = codec->spec;
12162         int err;
12163         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
12164
12165         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
12166                                            alc861vd_ignore);
12167         if (err < 0)
12168                 return err;
12169         if (!spec->autocfg.line_outs)
12170                 return 0; /* can't find valid BIOS pin config */
12171
12172         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
12173         if (err < 0)
12174                 return err;
12175         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
12176         if (err < 0)
12177                 return err;
12178         err = alc861vd_auto_create_extra_out(spec,
12179                                              spec->autocfg.speaker_pins[0],
12180                                              "Speaker");
12181         if (err < 0)
12182                 return err;
12183         err = alc861vd_auto_create_extra_out(spec,
12184                                              spec->autocfg.hp_pins[0],
12185                                              "Headphone");
12186         if (err < 0)
12187                 return err;
12188         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
12189         if (err < 0)
12190                 return err;
12191
12192         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
12193
12194         if (spec->autocfg.dig_out_pin)
12195                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
12196
12197         if (spec->kctl_alloc)
12198                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
12199
12200         spec->init_verbs[spec->num_init_verbs++]
12201                 = alc861vd_volume_init_verbs;
12202
12203         spec->num_mux_defs = 1;
12204         spec->input_mux = &spec->private_imux;
12205
12206         err = alc_auto_add_mic_boost(codec);
12207         if (err < 0)
12208                 return err;
12209
12210         return 1;
12211 }
12212
12213 /* additional initialization for auto-configuration model */
12214 static void alc861vd_auto_init(struct hda_codec *codec)
12215 {
12216         alc861vd_auto_init_multi_out(codec);
12217         alc861vd_auto_init_hp_out(codec);
12218         alc861vd_auto_init_analog_input(codec);
12219 }
12220
12221 static int patch_alc861vd(struct hda_codec *codec)
12222 {
12223         struct alc_spec *spec;
12224         int err, board_config;
12225
12226         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
12227         if (spec == NULL)
12228                 return -ENOMEM;
12229
12230         codec->spec = spec;
12231
12232         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
12233                                                   alc861vd_models,
12234                                                   alc861vd_cfg_tbl);
12235
12236         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
12237                 printk(KERN_INFO "hda_codec: Unknown model for ALC660VD/"
12238                         "ALC861VD, trying auto-probe from BIOS...\n");
12239                 board_config = ALC861VD_AUTO;
12240         }
12241
12242         if (board_config == ALC861VD_AUTO) {
12243                 /* automatic parse from the BIOS config */
12244                 err = alc861vd_parse_auto_config(codec);
12245                 if (err < 0) {
12246                         alc_free(codec);
12247                         return err;
12248                 } else if (!err) {
12249                         printk(KERN_INFO
12250                                "hda_codec: Cannot set up configuration "
12251                                "from BIOS.  Using base mode...\n");
12252                         board_config = ALC861VD_3ST;
12253                 }
12254         }
12255
12256         if (board_config != ALC861VD_AUTO)
12257                 setup_preset(spec, &alc861vd_presets[board_config]);
12258
12259         spec->stream_name_analog = "ALC861VD Analog";
12260         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
12261         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
12262
12263         spec->stream_name_digital = "ALC861VD Digital";
12264         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
12265         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
12266
12267         spec->adc_nids = alc861vd_adc_nids;
12268         spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
12269
12270         spec->mixers[spec->num_mixers] = alc861vd_capture_mixer;
12271         spec->num_mixers++;
12272
12273         codec->patch_ops = alc_patch_ops;
12274
12275         if (board_config == ALC861VD_AUTO)
12276                 spec->init_hook = alc861vd_auto_init;
12277 #ifdef CONFIG_SND_HDA_POWER_SAVE
12278         if (!spec->loopback.amplist)
12279                 spec->loopback.amplist = alc861vd_loopbacks;
12280 #endif
12281
12282         return 0;
12283 }
12284
12285 /*
12286  * ALC662 support
12287  *
12288  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
12289  * configuration.  Each pin widget can choose any input DACs and a mixer.
12290  * Each ADC is connected from a mixer of all inputs.  This makes possible
12291  * 6-channel independent captures.
12292  *
12293  * In addition, an independent DAC for the multi-playback (not used in this
12294  * driver yet).
12295  */
12296 #define ALC662_DIGOUT_NID       0x06
12297 #define ALC662_DIGIN_NID        0x0a
12298
12299 static hda_nid_t alc662_dac_nids[4] = {
12300         /* front, rear, clfe, rear_surr */
12301         0x02, 0x03, 0x04
12302 };
12303
12304 static hda_nid_t alc662_adc_nids[1] = {
12305         /* ADC1-2 */
12306         0x09,
12307 };
12308 /* input MUX */
12309 /* FIXME: should be a matrix-type input source selection */
12310
12311 static struct hda_input_mux alc662_capture_source = {
12312         .num_items = 4,
12313         .items = {
12314                 { "Mic", 0x0 },
12315                 { "Front Mic", 0x1 },
12316                 { "Line", 0x2 },
12317                 { "CD", 0x4 },
12318         },
12319 };
12320
12321 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
12322         .num_items = 2,
12323         .items = {
12324                 { "Mic", 0x1 },
12325                 { "Line", 0x2 },
12326         },
12327 };
12328
12329 static struct hda_input_mux alc662_eeepc_capture_source = {
12330         .num_items = 2,
12331         .items = {
12332                 { "i-Mic", 0x1 },
12333                 { "e-Mic", 0x0 },
12334         },
12335 };
12336
12337 #define alc662_mux_enum_info alc_mux_enum_info
12338 #define alc662_mux_enum_get alc_mux_enum_get
12339
12340 static int alc662_mux_enum_put(struct snd_kcontrol *kcontrol,
12341                                struct snd_ctl_elem_value *ucontrol)
12342 {
12343         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
12344         struct alc_spec *spec = codec->spec;
12345         const struct hda_input_mux *imux = spec->input_mux;
12346         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
12347         static hda_nid_t capture_mixers[2] = { 0x23, 0x22 };
12348         hda_nid_t nid = capture_mixers[adc_idx];
12349         unsigned int *cur_val = &spec->cur_mux[adc_idx];
12350         unsigned int i, idx;
12351
12352         idx = ucontrol->value.enumerated.item[0];
12353         if (idx >= imux->num_items)
12354                 idx = imux->num_items - 1;
12355         if (*cur_val == idx)
12356                 return 0;
12357         for (i = 0; i < imux->num_items; i++) {
12358                 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
12359                 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
12360                                          imux->items[i].index,
12361                                          HDA_AMP_MUTE, v);
12362         }
12363         *cur_val = idx;
12364         return 1;
12365 }
12366 /*
12367  * 2ch mode
12368  */
12369 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
12370         { 2, NULL }
12371 };
12372
12373 /*
12374  * 2ch mode
12375  */
12376 static struct hda_verb alc662_3ST_ch2_init[] = {
12377         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
12378         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
12379         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
12380         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
12381         { } /* end */
12382 };
12383
12384 /*
12385  * 6ch mode
12386  */
12387 static struct hda_verb alc662_3ST_ch6_init[] = {
12388         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12389         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
12390         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
12391         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12392         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
12393         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
12394         { } /* end */
12395 };
12396
12397 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
12398         { 2, alc662_3ST_ch2_init },
12399         { 6, alc662_3ST_ch6_init },
12400 };
12401
12402 /*
12403  * 2ch mode
12404  */
12405 static struct hda_verb alc662_sixstack_ch6_init[] = {
12406         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12407         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12408         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12409         { } /* end */
12410 };
12411
12412 /*
12413  * 6ch mode
12414  */
12415 static struct hda_verb alc662_sixstack_ch8_init[] = {
12416         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12417         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12418         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12419         { } /* end */
12420 };
12421
12422 static struct hda_channel_mode alc662_5stack_modes[2] = {
12423         { 2, alc662_sixstack_ch6_init },
12424         { 6, alc662_sixstack_ch8_init },
12425 };
12426
12427 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
12428  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
12429  */
12430
12431 static struct snd_kcontrol_new alc662_base_mixer[] = {
12432         /* output mixer control */
12433         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
12434         HDA_CODEC_MUTE("Front Playback Switch", 0x02, 0x0, HDA_OUTPUT),
12435         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
12436         HDA_CODEC_MUTE("Surround Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12437         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
12438         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
12439         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
12440         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
12441         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12442
12443         /*Input mixer control */
12444         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
12445         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
12446         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
12447         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
12448         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
12449         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
12450         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
12451         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
12452         { } /* end */
12453 };
12454
12455 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
12456         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12457         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
12458         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12459         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
12460         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
12461         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12462         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12463         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12464         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12465         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12466         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12467         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
12468         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
12469         { } /* end */
12470 };
12471
12472 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
12473         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12474         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
12475         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12476         HDA_BIND_MUTE("Surround Playback Switch", 0x03, 2, HDA_INPUT),
12477         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
12478         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
12479         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
12480         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
12481         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12482         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
12483         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
12484         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12485         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12486         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12487         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12488         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12489         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12490         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
12491         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
12492         { } /* end */
12493 };
12494
12495 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
12496         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12497         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
12498         HDA_CODEC_VOLUME("iSpeaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12499         HDA_BIND_MUTE("iSpeaker Playback Switch", 0x03, 2, HDA_INPUT),
12500         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12501         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12502         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12503         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12504         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12505         { } /* end */
12506 };
12507
12508 static struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
12509         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12510
12511         HDA_CODEC_VOLUME("LineOut Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12512         HDA_CODEC_MUTE("LineOut Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12513
12514         HDA_CODEC_VOLUME("e-Mic Boost", 0x18, 0, HDA_INPUT),
12515         HDA_CODEC_VOLUME("e-Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12516         HDA_CODEC_MUTE("e-Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12517
12518         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
12519         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12520         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12521         { } /* end */
12522 };
12523
12524 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
12525         {
12526                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12527                 .name = "Channel Mode",
12528                 .info = alc_ch_mode_info,
12529                 .get = alc_ch_mode_get,
12530                 .put = alc_ch_mode_put,
12531         },
12532         { } /* end */
12533 };
12534
12535 static struct hda_verb alc662_init_verbs[] = {
12536         /* ADC: mute amp left and right */
12537         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12538         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
12539         /* Front mixer: unmute input/output amp left and right (volume = 0) */
12540
12541         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12542         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12543         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12544         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12545         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
12546
12547         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12548         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12549         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12550         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12551         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12552         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12553
12554         /* Front Pin: output 0 (0x0c) */
12555         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12556         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12557
12558         /* Rear Pin: output 1 (0x0d) */
12559         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12560         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12561
12562         /* CLFE Pin: output 2 (0x0e) */
12563         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12564         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12565
12566         /* Mic (rear) pin: input vref at 80% */
12567         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12568         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12569         /* Front Mic pin: input vref at 80% */
12570         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12571         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12572         /* Line In pin: input */
12573         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12574         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12575         /* Line-2 In: Headphone output (output 0 - 0x0c) */
12576         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12577         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12578         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
12579         /* CD pin widget for input */
12580         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12581
12582         /* FIXME: use matrix-type input source selection */
12583         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
12584         /* Input mixer */
12585         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12586         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12587         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12588         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
12589
12590         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12591         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12592         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12593         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
12594         { }
12595 };
12596
12597 static struct hda_verb alc662_sue_init_verbs[] = {
12598         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
12599         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
12600         {}
12601 };
12602
12603 static struct hda_verb alc662_eeepc_sue_init_verbs[] = {
12604         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12605         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12606         {}
12607 };
12608
12609 /*
12610  * generic initialization of ADC, input mixers and output mixers
12611  */
12612 static struct hda_verb alc662_auto_init_verbs[] = {
12613         /*
12614          * Unmute ADC and set the default input to mic-in
12615          */
12616         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
12617         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12618
12619         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
12620          * mixer widget
12621          * Note: PASD motherboards uses the Line In 2 as the input for front
12622          * panel mic (mic 2)
12623          */
12624         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
12625         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12626         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12627         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12628         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12629         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
12630
12631         /*
12632          * Set up output mixers (0x0c - 0x0f)
12633          */
12634         /* set vol=0 to output mixers */
12635         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12636         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12637         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12638
12639         /* set up input amps for analog loopback */
12640         /* Amp Indices: DAC = 0, mixer = 1 */
12641         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12642         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12643         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12644         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12645         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12646         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12647
12648
12649         /* FIXME: use matrix-type input source selection */
12650         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
12651         /* Input mixer */
12652         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12653         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12654         { }
12655 };
12656
12657 /* capture mixer elements */
12658 static struct snd_kcontrol_new alc662_capture_mixer[] = {
12659         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
12660         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
12661         {
12662                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12663                 /* The multiple "Capture Source" controls confuse alsamixer
12664                  * So call somewhat different..
12665                  * FIXME: the controls appear in the "playback" view!
12666                  */
12667                 /* .name = "Capture Source", */
12668                 .name = "Input Source",
12669                 .count = 1,
12670                 .info = alc662_mux_enum_info,
12671                 .get = alc662_mux_enum_get,
12672                 .put = alc662_mux_enum_put,
12673         },
12674         { } /* end */
12675 };
12676
12677 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
12678 {
12679         unsigned int present;
12680         unsigned char bits;
12681
12682         present = snd_hda_codec_read(codec, 0x14, 0,
12683                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12684         bits = present ? HDA_AMP_MUTE : 0;
12685         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
12686                                  HDA_AMP_MUTE, bits);
12687 }
12688
12689 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
12690 {
12691         unsigned int present;
12692         unsigned char bits;
12693
12694         present = snd_hda_codec_read(codec, 0x1b, 0,
12695                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12696         bits = present ? HDA_AMP_MUTE : 0;
12697         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
12698                                  HDA_AMP_MUTE, bits);
12699         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
12700                                  HDA_AMP_MUTE, bits);
12701 }
12702
12703 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
12704                                            unsigned int res)
12705 {
12706         if ((res >> 26) == ALC880_HP_EVENT)
12707                 alc662_lenovo_101e_all_automute(codec);
12708         if ((res >> 26) == ALC880_FRONT_EVENT)
12709                 alc662_lenovo_101e_ispeaker_automute(codec);
12710 }
12711
12712 static void alc662_eeepc_mic_automute(struct hda_codec *codec)
12713 {
12714         unsigned int present;
12715
12716         present = snd_hda_codec_read(codec, 0x18, 0,
12717                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12718         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12719                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
12720         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12721                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
12722         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12723                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
12724         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12725                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
12726 }
12727
12728 /* unsolicited event for HP jack sensing */
12729 static void alc662_eeepc_unsol_event(struct hda_codec *codec,
12730                                      unsigned int res)
12731 {
12732         if ((res >> 26) == ALC880_HP_EVENT)
12733                 alc262_hippo1_automute( codec );
12734
12735         if ((res >> 26) == ALC880_MIC_EVENT)
12736                 alc662_eeepc_mic_automute(codec);
12737 }
12738
12739 static void alc662_eeepc_inithook(struct hda_codec *codec)
12740 {
12741         alc262_hippo1_automute( codec );
12742         alc662_eeepc_mic_automute(codec);
12743 }
12744
12745 #ifdef CONFIG_SND_HDA_POWER_SAVE
12746 #define alc662_loopbacks        alc880_loopbacks
12747 #endif
12748
12749
12750 /* pcm configuration: identiacal with ALC880 */
12751 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
12752 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
12753 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
12754 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
12755
12756 /*
12757  * configuration and preset
12758  */
12759 static const char *alc662_models[ALC662_MODEL_LAST] = {
12760         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
12761         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
12762         [ALC662_3ST_6ch]        = "3stack-6ch",
12763         [ALC662_5ST_DIG]        = "6stack-dig",
12764         [ALC662_LENOVO_101E]    = "lenovo-101e",
12765         [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
12766         [ALC662_AUTO]           = "auto",
12767 };
12768
12769 static struct snd_pci_quirk alc662_cfg_tbl[] = {
12770         SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
12771         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
12772         {}
12773 };
12774
12775 static struct alc_config_preset alc662_presets[] = {
12776         [ALC662_3ST_2ch_DIG] = {
12777                 .mixers = { alc662_3ST_2ch_mixer, alc662_capture_mixer },
12778                 .init_verbs = { alc662_init_verbs },
12779                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
12780                 .dac_nids = alc662_dac_nids,
12781                 .dig_out_nid = ALC662_DIGOUT_NID,
12782                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
12783                 .adc_nids = alc662_adc_nids,
12784                 .dig_in_nid = ALC662_DIGIN_NID,
12785                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
12786                 .channel_mode = alc662_3ST_2ch_modes,
12787                 .input_mux = &alc662_capture_source,
12788         },
12789         [ALC662_3ST_6ch_DIG] = {
12790                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer,
12791                             alc662_capture_mixer },
12792                 .init_verbs = { alc662_init_verbs },
12793                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
12794                 .dac_nids = alc662_dac_nids,
12795                 .dig_out_nid = ALC662_DIGOUT_NID,
12796                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
12797                 .adc_nids = alc662_adc_nids,
12798                 .dig_in_nid = ALC662_DIGIN_NID,
12799                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
12800                 .channel_mode = alc662_3ST_6ch_modes,
12801                 .need_dac_fix = 1,
12802                 .input_mux = &alc662_capture_source,
12803         },
12804         [ALC662_3ST_6ch] = {
12805                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer,
12806                             alc662_capture_mixer },
12807                 .init_verbs = { alc662_init_verbs },
12808                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
12809                 .dac_nids = alc662_dac_nids,
12810                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
12811                 .adc_nids = alc662_adc_nids,
12812                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
12813                 .channel_mode = alc662_3ST_6ch_modes,
12814                 .need_dac_fix = 1,
12815                 .input_mux = &alc662_capture_source,
12816         },
12817         [ALC662_5ST_DIG] = {
12818                 .mixers = { alc662_base_mixer, alc662_chmode_mixer,
12819                             alc662_capture_mixer },
12820                 .init_verbs = { alc662_init_verbs },
12821                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
12822                 .dac_nids = alc662_dac_nids,
12823                 .dig_out_nid = ALC662_DIGOUT_NID,
12824                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
12825                 .adc_nids = alc662_adc_nids,
12826                 .dig_in_nid = ALC662_DIGIN_NID,
12827                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
12828                 .channel_mode = alc662_5stack_modes,
12829                 .input_mux = &alc662_capture_source,
12830         },
12831         [ALC662_LENOVO_101E] = {
12832                 .mixers = { alc662_lenovo_101e_mixer, alc662_capture_mixer },
12833                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
12834                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
12835                 .dac_nids = alc662_dac_nids,
12836                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
12837                 .adc_nids = alc662_adc_nids,
12838                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
12839                 .channel_mode = alc662_3ST_2ch_modes,
12840                 .input_mux = &alc662_lenovo_101e_capture_source,
12841                 .unsol_event = alc662_lenovo_101e_unsol_event,
12842                 .init_hook = alc662_lenovo_101e_all_automute,
12843         },
12844         [ALC662_ASUS_EEEPC_P701] = {
12845                 .mixers = { alc662_eeepc_p701_mixer, alc662_capture_mixer },
12846                 .init_verbs = { alc662_init_verbs,
12847                                 alc662_eeepc_sue_init_verbs },
12848                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
12849                 .dac_nids = alc662_dac_nids,
12850                 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
12851                 .adc_nids = alc662_adc_nids,
12852                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
12853                 .channel_mode = alc662_3ST_2ch_modes,
12854                 .input_mux = &alc662_eeepc_capture_source,
12855                 .unsol_event = alc662_eeepc_unsol_event,
12856                 .init_hook = alc662_eeepc_inithook,
12857         },
12858
12859 };
12860
12861
12862 /*
12863  * BIOS auto configuration
12864  */
12865
12866 /* add playback controls from the parsed DAC table */
12867 static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec,
12868                                              const struct auto_pin_cfg *cfg)
12869 {
12870         char name[32];
12871         static const char *chname[4] = {
12872                 "Front", "Surround", NULL /*CLFE*/, "Side"
12873         };
12874         hda_nid_t nid;
12875         int i, err;
12876
12877         for (i = 0; i < cfg->line_outs; i++) {
12878                 if (!spec->multiout.dac_nids[i])
12879                         continue;
12880                 nid = alc880_idx_to_dac(i);
12881                 if (i == 2) {
12882                         /* Center/LFE */
12883                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12884                                           "Center Playback Volume",
12885                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
12886                                                               HDA_OUTPUT));
12887                         if (err < 0)
12888                                 return err;
12889                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12890                                           "LFE Playback Volume",
12891                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
12892                                                               HDA_OUTPUT));
12893                         if (err < 0)
12894                                 return err;
12895                         err = add_control(spec, ALC_CTL_BIND_MUTE,
12896                                           "Center Playback Switch",
12897                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
12898                                                               HDA_INPUT));
12899                         if (err < 0)
12900                                 return err;
12901                         err = add_control(spec, ALC_CTL_BIND_MUTE,
12902                                           "LFE Playback Switch",
12903                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
12904                                                               HDA_INPUT));
12905                         if (err < 0)
12906                                 return err;
12907                 } else {
12908                         sprintf(name, "%s Playback Volume", chname[i]);
12909                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
12910                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
12911                                                               HDA_OUTPUT));
12912                         if (err < 0)
12913                                 return err;
12914                         sprintf(name, "%s Playback Switch", chname[i]);
12915                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
12916                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
12917                                                               HDA_INPUT));
12918                         if (err < 0)
12919                                 return err;
12920                 }
12921         }
12922         return 0;
12923 }
12924
12925 /* add playback controls for speaker and HP outputs */
12926 static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
12927                                         const char *pfx)
12928 {
12929         hda_nid_t nid;
12930         int err;
12931         char name[32];
12932
12933         if (!pin)
12934                 return 0;
12935
12936         if (alc880_is_fixed_pin(pin)) {
12937                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
12938                 /* printk("DAC nid=%x\n",nid); */
12939                 /* specify the DAC as the extra output */
12940                 if (!spec->multiout.hp_nid)
12941                         spec->multiout.hp_nid = nid;
12942                 else
12943                         spec->multiout.extra_out_nid[0] = nid;
12944                 /* control HP volume/switch on the output mixer amp */
12945                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
12946                 sprintf(name, "%s Playback Volume", pfx);
12947                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
12948                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
12949                 if (err < 0)
12950                         return err;
12951                 sprintf(name, "%s Playback Switch", pfx);
12952                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
12953                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
12954                 if (err < 0)
12955                         return err;
12956         } else if (alc880_is_multi_pin(pin)) {
12957                 /* set manual connection */
12958                 /* we have only a switch on HP-out PIN */
12959                 sprintf(name, "%s Playback Switch", pfx);
12960                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
12961                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
12962                 if (err < 0)
12963                         return err;
12964         }
12965         return 0;
12966 }
12967
12968 /* create playback/capture controls for input pins */
12969 static int alc662_auto_create_analog_input_ctls(struct alc_spec *spec,
12970                                                 const struct auto_pin_cfg *cfg)
12971 {
12972         struct hda_input_mux *imux = &spec->private_imux;
12973         int i, err, idx;
12974
12975         for (i = 0; i < AUTO_PIN_LAST; i++) {
12976                 if (alc880_is_input_pin(cfg->input_pins[i])) {
12977                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
12978                         err = new_analog_input(spec, cfg->input_pins[i],
12979                                                auto_pin_cfg_labels[i],
12980                                                idx, 0x0b);
12981                         if (err < 0)
12982                                 return err;
12983                         imux->items[imux->num_items].label =
12984                                 auto_pin_cfg_labels[i];
12985                         imux->items[imux->num_items].index =
12986                                 alc880_input_pin_idx(cfg->input_pins[i]);
12987                         imux->num_items++;
12988                 }
12989         }
12990         return 0;
12991 }
12992
12993 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
12994                                               hda_nid_t nid, int pin_type,
12995                                               int dac_idx)
12996 {
12997         /* set as output */
12998         snd_hda_codec_write(codec, nid, 0,
12999                             AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
13000         snd_hda_codec_write(codec, nid, 0,
13001                             AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
13002         /* need the manual connection? */
13003         if (alc880_is_multi_pin(nid)) {
13004                 struct alc_spec *spec = codec->spec;
13005                 int idx = alc880_multi_pin_idx(nid);
13006                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
13007                                     AC_VERB_SET_CONNECT_SEL,
13008                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
13009         }
13010 }
13011
13012 static void alc662_auto_init_multi_out(struct hda_codec *codec)
13013 {
13014         struct alc_spec *spec = codec->spec;
13015         int i;
13016
13017         for (i = 0; i <= HDA_SIDE; i++) {
13018                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
13019                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
13020                 if (nid)
13021                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
13022                                                           i);
13023         }
13024 }
13025
13026 static void alc662_auto_init_hp_out(struct hda_codec *codec)
13027 {
13028         struct alc_spec *spec = codec->spec;
13029         hda_nid_t pin;
13030
13031         pin = spec->autocfg.hp_pins[0];
13032         if (pin) /* connect to front */
13033                 /* use dac 0 */
13034                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
13035 }
13036
13037 #define alc662_is_input_pin(nid)        alc880_is_input_pin(nid)
13038 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
13039
13040 static void alc662_auto_init_analog_input(struct hda_codec *codec)
13041 {
13042         struct alc_spec *spec = codec->spec;
13043         int i;
13044
13045         for (i = 0; i < AUTO_PIN_LAST; i++) {
13046                 hda_nid_t nid = spec->autocfg.input_pins[i];
13047                 if (alc662_is_input_pin(nid)) {
13048                         snd_hda_codec_write(codec, nid, 0,
13049                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
13050                                             (i <= AUTO_PIN_FRONT_MIC ?
13051                                              PIN_VREF80 : PIN_IN));
13052                         if (nid != ALC662_PIN_CD_NID)
13053                                 snd_hda_codec_write(codec, nid, 0,
13054                                                     AC_VERB_SET_AMP_GAIN_MUTE,
13055                                                     AMP_OUT_MUTE);
13056                 }
13057         }
13058 }
13059
13060 static int alc662_parse_auto_config(struct hda_codec *codec)
13061 {
13062         struct alc_spec *spec = codec->spec;
13063         int err;
13064         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
13065
13066         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
13067                                            alc662_ignore);
13068         if (err < 0)
13069                 return err;
13070         if (!spec->autocfg.line_outs)
13071                 return 0; /* can't find valid BIOS pin config */
13072
13073         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
13074         if (err < 0)
13075                 return err;
13076         err = alc662_auto_create_multi_out_ctls(spec, &spec->autocfg);
13077         if (err < 0)
13078                 return err;
13079         err = alc662_auto_create_extra_out(spec,
13080                                            spec->autocfg.speaker_pins[0],
13081                                            "Speaker");
13082         if (err < 0)
13083                 return err;
13084         err = alc662_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
13085                                            "Headphone");
13086         if (err < 0)
13087                 return err;
13088         err = alc662_auto_create_analog_input_ctls(spec, &spec->autocfg);
13089         if (err < 0)
13090                 return err;
13091
13092         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
13093
13094         if (spec->autocfg.dig_out_pin)
13095                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
13096
13097         if (spec->kctl_alloc)
13098                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
13099
13100         spec->num_mux_defs = 1;
13101         spec->input_mux = &spec->private_imux;
13102         
13103         spec->init_verbs[spec->num_init_verbs++] = alc662_auto_init_verbs;
13104         spec->mixers[spec->num_mixers] = alc662_capture_mixer;
13105         spec->num_mixers++;
13106         return 1;
13107 }
13108
13109 /* additional initialization for auto-configuration model */
13110 static void alc662_auto_init(struct hda_codec *codec)
13111 {
13112         alc662_auto_init_multi_out(codec);
13113         alc662_auto_init_hp_out(codec);
13114         alc662_auto_init_analog_input(codec);
13115 }
13116
13117 static int patch_alc662(struct hda_codec *codec)
13118 {
13119         struct alc_spec *spec;
13120         int err, board_config;
13121
13122         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13123         if (!spec)
13124                 return -ENOMEM;
13125
13126         codec->spec = spec;
13127
13128         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
13129                                                   alc662_models,
13130                                                   alc662_cfg_tbl);
13131         if (board_config < 0) {
13132                 printk(KERN_INFO "hda_codec: Unknown model for ALC662, "
13133                        "trying auto-probe from BIOS...\n");
13134                 board_config = ALC662_AUTO;
13135         }
13136
13137         if (board_config == ALC662_AUTO) {
13138                 /* automatic parse from the BIOS config */
13139                 err = alc662_parse_auto_config(codec);
13140                 if (err < 0) {
13141                         alc_free(codec);
13142                         return err;
13143                 } else if (!err) {
13144                         printk(KERN_INFO
13145                                "hda_codec: Cannot set up configuration "
13146                                "from BIOS.  Using base mode...\n");
13147                         board_config = ALC662_3ST_2ch_DIG;
13148                 }
13149         }
13150
13151         if (board_config != ALC662_AUTO)
13152                 setup_preset(spec, &alc662_presets[board_config]);
13153
13154         spec->stream_name_analog = "ALC662 Analog";
13155         spec->stream_analog_playback = &alc662_pcm_analog_playback;
13156         spec->stream_analog_capture = &alc662_pcm_analog_capture;
13157
13158         spec->stream_name_digital = "ALC662 Digital";
13159         spec->stream_digital_playback = &alc662_pcm_digital_playback;
13160         spec->stream_digital_capture = &alc662_pcm_digital_capture;
13161
13162         if (!spec->adc_nids && spec->input_mux) {
13163                 spec->adc_nids = alc662_adc_nids;
13164                 spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
13165         }
13166
13167         codec->patch_ops = alc_patch_ops;
13168         if (board_config == ALC662_AUTO)
13169                 spec->init_hook = alc662_auto_init;
13170 #ifdef CONFIG_SND_HDA_POWER_SAVE
13171         if (!spec->loopback.amplist)
13172                 spec->loopback.amplist = alc662_loopbacks;
13173 #endif
13174
13175         return 0;
13176 }
13177
13178 /*
13179  * patch entries
13180  */
13181 struct hda_codec_preset snd_hda_preset_realtek[] = {
13182         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
13183         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
13184         { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
13185         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
13186         { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
13187         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
13188           .patch = patch_alc861 },
13189         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
13190         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
13191         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
13192         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
13193           .patch = patch_alc883 },
13194         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
13195           .patch = patch_alc662 },
13196         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
13197         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
13198         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
13199         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
13200         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
13201         { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 },
13202         {} /* terminator */
13203 };