]> Pileus Git - ~andy/linux/blob - sound/pci/hda/patch_realtek.c
[ALSA] hda-codec - Add support for Haier W66
[~andy/linux] / sound / pci / hda / patch_realtek.c
1 /*
2  * Universal Interface for Intel High Definition Audio Codec
3  *
4  * HD audio interface patch for ALC 260/880/882 codecs
5  *
6  * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7  *                    PeiSen Hou <pshou@realtek.com.tw>
8  *                    Takashi Iwai <tiwai@suse.de>
9  *                    Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
10  *
11  *  This driver is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This driver is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
24  */
25
26 #include <sound/driver.h>
27 #include <linux/init.h>
28 #include <linux/delay.h>
29 #include <linux/slab.h>
30 #include <linux/pci.h>
31 #include <sound/core.h>
32 #include "hda_codec.h"
33 #include "hda_local.h"
34
35 #define ALC880_FRONT_EVENT              0x01
36 #define ALC880_DCVOL_EVENT              0x02
37 #define ALC880_HP_EVENT                 0x04
38 #define ALC880_MIC_EVENT                0x08
39
40 /* ALC880 board config type */
41 enum {
42         ALC880_3ST,
43         ALC880_3ST_DIG,
44         ALC880_5ST,
45         ALC880_5ST_DIG,
46         ALC880_W810,
47         ALC880_Z71V,
48         ALC880_6ST,
49         ALC880_6ST_DIG,
50         ALC880_F1734,
51         ALC880_ASUS,
52         ALC880_ASUS_DIG,
53         ALC880_ASUS_W1V,
54         ALC880_ASUS_DIG2,
55         ALC880_FUJITSU,
56         ALC880_UNIWILL_DIG,
57         ALC880_UNIWILL,
58         ALC880_UNIWILL_P53,
59         ALC880_CLEVO,
60         ALC880_TCL_S700,
61         ALC880_LG,
62         ALC880_LG_LW,
63 #ifdef CONFIG_SND_DEBUG
64         ALC880_TEST,
65 #endif
66         ALC880_AUTO,
67         ALC880_MODEL_LAST /* last tag */
68 };
69
70 /* ALC260 models */
71 enum {
72         ALC260_BASIC,
73         ALC260_HP,
74         ALC260_HP_3013,
75         ALC260_FUJITSU_S702X,
76         ALC260_ACER,
77         ALC260_WILL,
78         ALC260_REPLACER_672V,
79 #ifdef CONFIG_SND_DEBUG
80         ALC260_TEST,
81 #endif
82         ALC260_AUTO,
83         ALC260_MODEL_LAST /* last tag */
84 };
85
86 /* ALC262 models */
87 enum {
88         ALC262_BASIC,
89         ALC262_HIPPO,
90         ALC262_HIPPO_1,
91         ALC262_FUJITSU,
92         ALC262_HP_BPC,
93         ALC262_HP_BPC_D7000_WL,
94         ALC262_HP_BPC_D7000_WF,
95         ALC262_BENQ_ED8,
96         ALC262_SONY_ASSAMD,
97         ALC262_BENQ_T31,
98         ALC262_AUTO,
99         ALC262_MODEL_LAST /* last tag */
100 };
101
102 /* ALC268 models */
103 enum {
104         ALC268_3ST,
105         ALC268_TOSHIBA,
106         ALC268_ACER,
107         ALC268_AUTO,
108         ALC268_MODEL_LAST /* last tag */
109 };
110
111 /* ALC861 models */
112 enum {
113         ALC861_3ST,
114         ALC660_3ST,
115         ALC861_3ST_DIG,
116         ALC861_6ST_DIG,
117         ALC861_UNIWILL_M31,
118         ALC861_TOSHIBA,
119         ALC861_ASUS,
120         ALC861_ASUS_LAPTOP,
121         ALC861_AUTO,
122         ALC861_MODEL_LAST,
123 };
124
125 /* ALC861-VD models */
126 enum {
127         ALC660VD_3ST,
128         ALC660VD_3ST_DIG,
129         ALC861VD_3ST,
130         ALC861VD_3ST_DIG,
131         ALC861VD_6ST_DIG,
132         ALC861VD_LENOVO,
133         ALC861VD_DALLAS,
134         ALC861VD_HP,
135         ALC861VD_AUTO,
136         ALC861VD_MODEL_LAST,
137 };
138
139 /* ALC662 models */
140 enum {
141         ALC662_3ST_2ch_DIG,
142         ALC662_3ST_6ch_DIG,
143         ALC662_3ST_6ch,
144         ALC662_5ST_DIG,
145         ALC662_LENOVO_101E,
146         ALC662_AUTO,
147         ALC662_MODEL_LAST,
148 };
149
150 /* ALC882 models */
151 enum {
152         ALC882_3ST_DIG,
153         ALC882_6ST_DIG,
154         ALC882_ARIMA,
155         ALC882_W2JC,
156         ALC882_TARGA,
157         ALC882_ASUS_A7J,
158         ALC885_MACPRO,
159         ALC885_MBP3,
160         ALC885_IMAC24,
161         ALC882_AUTO,
162         ALC882_MODEL_LAST,
163 };
164
165 /* ALC883 models */
166 enum {
167         ALC883_3ST_2ch_DIG,
168         ALC883_3ST_6ch_DIG,
169         ALC883_3ST_6ch,
170         ALC883_6ST_DIG,
171         ALC883_TARGA_DIG,
172         ALC883_TARGA_2ch_DIG,
173         ALC883_ACER,
174         ALC883_ACER_ASPIRE,
175         ALC883_MEDION,
176         ALC883_MEDION_MD2,      
177         ALC883_LAPTOP_EAPD,
178         ALC883_LENOVO_101E_2ch,
179         ALC883_LENOVO_NB0763,
180         ALC888_LENOVO_MS7195_DIG,
181         ALC883_HAIER_W66,               
182         ALC888_6ST_HP,
183         ALC888_3ST_HP,
184         ALC883_AUTO,
185         ALC883_MODEL_LAST,
186 };
187
188 /* for GPIO Poll */
189 #define GPIO_MASK       0x03
190
191 struct alc_spec {
192         /* codec parameterization */
193         struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
194         unsigned int num_mixers;
195
196         const struct hda_verb *init_verbs[5];   /* initialization verbs
197                                                  * don't forget NULL
198                                                  * termination!
199                                                  */
200         unsigned int num_init_verbs;
201
202         char *stream_name_analog;       /* analog PCM stream */
203         struct hda_pcm_stream *stream_analog_playback;
204         struct hda_pcm_stream *stream_analog_capture;
205
206         char *stream_name_digital;      /* digital PCM stream */
207         struct hda_pcm_stream *stream_digital_playback;
208         struct hda_pcm_stream *stream_digital_capture;
209
210         /* playback */
211         struct hda_multi_out multiout;  /* playback set-up
212                                          * max_channels, dacs must be set
213                                          * dig_out_nid and hp_nid are optional
214                                          */
215
216         /* capture */
217         unsigned int num_adc_nids;
218         hda_nid_t *adc_nids;
219         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
220
221         /* capture source */
222         unsigned int num_mux_defs;
223         const struct hda_input_mux *input_mux;
224         unsigned int cur_mux[3];
225
226         /* channel model */
227         const struct hda_channel_mode *channel_mode;
228         int num_channel_mode;
229         int need_dac_fix;
230
231         /* PCM information */
232         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
233
234         /* dynamic controls, init_verbs and input_mux */
235         struct auto_pin_cfg autocfg;
236         unsigned int num_kctl_alloc, num_kctl_used;
237         struct snd_kcontrol_new *kctl_alloc;
238         struct hda_input_mux private_imux;
239         hda_nid_t private_dac_nids[5];
240
241         /* hooks */
242         void (*init_hook)(struct hda_codec *codec);
243         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
244
245         /* for pin sensing */
246         unsigned int sense_updated: 1;
247         unsigned int jack_present: 1;
248
249 #ifdef CONFIG_SND_HDA_POWER_SAVE
250         struct hda_loopback_check loopback;
251 #endif
252 };
253
254 /*
255  * configuration template - to be copied to the spec instance
256  */
257 struct alc_config_preset {
258         struct snd_kcontrol_new *mixers[5]; /* should be identical size
259                                              * with spec
260                                              */
261         const struct hda_verb *init_verbs[5];
262         unsigned int num_dacs;
263         hda_nid_t *dac_nids;
264         hda_nid_t dig_out_nid;          /* optional */
265         hda_nid_t hp_nid;               /* optional */
266         unsigned int num_adc_nids;
267         hda_nid_t *adc_nids;
268         hda_nid_t dig_in_nid;
269         unsigned int num_channel_mode;
270         const struct hda_channel_mode *channel_mode;
271         int need_dac_fix;
272         unsigned int num_mux_defs;
273         const struct hda_input_mux *input_mux;
274         void (*unsol_event)(struct hda_codec *, unsigned int);
275         void (*init_hook)(struct hda_codec *);
276 #ifdef CONFIG_SND_HDA_POWER_SAVE
277         struct hda_amp_list *loopbacks;
278 #endif
279 };
280
281
282 /*
283  * input MUX handling
284  */
285 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
286                              struct snd_ctl_elem_info *uinfo)
287 {
288         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
289         struct alc_spec *spec = codec->spec;
290         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
291         if (mux_idx >= spec->num_mux_defs)
292                 mux_idx = 0;
293         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
294 }
295
296 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
297                             struct snd_ctl_elem_value *ucontrol)
298 {
299         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
300         struct alc_spec *spec = codec->spec;
301         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
302
303         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
304         return 0;
305 }
306
307 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
308                             struct snd_ctl_elem_value *ucontrol)
309 {
310         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
311         struct alc_spec *spec = codec->spec;
312         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
313         unsigned int mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
314         return snd_hda_input_mux_put(codec, &spec->input_mux[mux_idx], ucontrol,
315                                      spec->adc_nids[adc_idx],
316                                      &spec->cur_mux[adc_idx]);
317 }
318
319
320 /*
321  * channel mode setting
322  */
323 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
324                             struct snd_ctl_elem_info *uinfo)
325 {
326         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
327         struct alc_spec *spec = codec->spec;
328         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
329                                     spec->num_channel_mode);
330 }
331
332 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
333                            struct snd_ctl_elem_value *ucontrol)
334 {
335         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
336         struct alc_spec *spec = codec->spec;
337         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
338                                    spec->num_channel_mode,
339                                    spec->multiout.max_channels);
340 }
341
342 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
343                            struct snd_ctl_elem_value *ucontrol)
344 {
345         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
346         struct alc_spec *spec = codec->spec;
347         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
348                                       spec->num_channel_mode,
349                                       &spec->multiout.max_channels);
350         if (err >= 0 && spec->need_dac_fix)
351                 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
352         return err;
353 }
354
355 /*
356  * Control the mode of pin widget settings via the mixer.  "pc" is used
357  * instead of "%" to avoid consequences of accidently treating the % as 
358  * being part of a format specifier.  Maximum allowed length of a value is
359  * 63 characters plus NULL terminator.
360  *
361  * Note: some retasking pin complexes seem to ignore requests for input
362  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
363  * are requested.  Therefore order this list so that this behaviour will not
364  * cause problems when mixer clients move through the enum sequentially.
365  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
366  * March 2006.
367  */
368 static char *alc_pin_mode_names[] = {
369         "Mic 50pc bias", "Mic 80pc bias",
370         "Line in", "Line out", "Headphone out",
371 };
372 static unsigned char alc_pin_mode_values[] = {
373         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
374 };
375 /* The control can present all 5 options, or it can limit the options based
376  * in the pin being assumed to be exclusively an input or an output pin.  In
377  * addition, "input" pins may or may not process the mic bias option
378  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
379  * accept requests for bias as of chip versions up to March 2006) and/or
380  * wiring in the computer.
381  */
382 #define ALC_PIN_DIR_IN              0x00
383 #define ALC_PIN_DIR_OUT             0x01
384 #define ALC_PIN_DIR_INOUT           0x02
385 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
386 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
387
388 /* Info about the pin modes supported by the different pin direction modes. 
389  * For each direction the minimum and maximum values are given.
390  */
391 static signed char alc_pin_mode_dir_info[5][2] = {
392         { 0, 2 },    /* ALC_PIN_DIR_IN */
393         { 3, 4 },    /* ALC_PIN_DIR_OUT */
394         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
395         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
396         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
397 };
398 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
399 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
400 #define alc_pin_mode_n_items(_dir) \
401         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
402
403 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
404                              struct snd_ctl_elem_info *uinfo)
405 {
406         unsigned int item_num = uinfo->value.enumerated.item;
407         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
408
409         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
410         uinfo->count = 1;
411         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
412
413         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
414                 item_num = alc_pin_mode_min(dir);
415         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
416         return 0;
417 }
418
419 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
420                             struct snd_ctl_elem_value *ucontrol)
421 {
422         unsigned int i;
423         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
424         hda_nid_t nid = kcontrol->private_value & 0xffff;
425         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
426         long *valp = ucontrol->value.integer.value;
427         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
428                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
429                                                  0x00);
430
431         /* Find enumerated value for current pinctl setting */
432         i = alc_pin_mode_min(dir);
433         while (alc_pin_mode_values[i] != pinctl && i <= alc_pin_mode_max(dir))
434                 i++;
435         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
436         return 0;
437 }
438
439 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
440                             struct snd_ctl_elem_value *ucontrol)
441 {
442         signed int change;
443         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
444         hda_nid_t nid = kcontrol->private_value & 0xffff;
445         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
446         long val = *ucontrol->value.integer.value;
447         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
448                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
449                                                  0x00);
450
451         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
452                 val = alc_pin_mode_min(dir);
453
454         change = pinctl != alc_pin_mode_values[val];
455         if (change) {
456                 /* Set pin mode to that requested */
457                 snd_hda_codec_write_cache(codec, nid, 0,
458                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
459                                           alc_pin_mode_values[val]);
460
461                 /* Also enable the retasking pin's input/output as required 
462                  * for the requested pin mode.  Enum values of 2 or less are
463                  * input modes.
464                  *
465                  * Dynamically switching the input/output buffers probably
466                  * reduces noise slightly (particularly on input) so we'll
467                  * do it.  However, having both input and output buffers
468                  * enabled simultaneously doesn't seem to be problematic if
469                  * this turns out to be necessary in the future.
470                  */
471                 if (val <= 2) {
472                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
473                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
474                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
475                                                  HDA_AMP_MUTE, 0);
476                 } else {
477                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
478                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
479                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
480                                                  HDA_AMP_MUTE, 0);
481                 }
482         }
483         return change;
484 }
485
486 #define ALC_PIN_MODE(xname, nid, dir) \
487         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
488           .info = alc_pin_mode_info, \
489           .get = alc_pin_mode_get, \
490           .put = alc_pin_mode_put, \
491           .private_value = nid | (dir<<16) }
492
493 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
494  * together using a mask with more than one bit set.  This control is
495  * currently used only by the ALC260 test model.  At this stage they are not
496  * needed for any "production" models.
497  */
498 #ifdef CONFIG_SND_DEBUG
499 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
500
501 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
502                              struct snd_ctl_elem_value *ucontrol)
503 {
504         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
505         hda_nid_t nid = kcontrol->private_value & 0xffff;
506         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
507         long *valp = ucontrol->value.integer.value;
508         unsigned int val = snd_hda_codec_read(codec, nid, 0,
509                                               AC_VERB_GET_GPIO_DATA, 0x00);
510
511         *valp = (val & mask) != 0;
512         return 0;
513 }
514 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
515                              struct snd_ctl_elem_value *ucontrol)
516 {
517         signed int change;
518         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
519         hda_nid_t nid = kcontrol->private_value & 0xffff;
520         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
521         long val = *ucontrol->value.integer.value;
522         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
523                                                     AC_VERB_GET_GPIO_DATA,
524                                                     0x00);
525
526         /* Set/unset the masked GPIO bit(s) as needed */
527         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
528         if (val == 0)
529                 gpio_data &= ~mask;
530         else
531                 gpio_data |= mask;
532         snd_hda_codec_write_cache(codec, nid, 0,
533                                   AC_VERB_SET_GPIO_DATA, gpio_data);
534
535         return change;
536 }
537 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
538         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
539           .info = alc_gpio_data_info, \
540           .get = alc_gpio_data_get, \
541           .put = alc_gpio_data_put, \
542           .private_value = nid | (mask<<16) }
543 #endif   /* CONFIG_SND_DEBUG */
544
545 /* A switch control to allow the enabling of the digital IO pins on the
546  * ALC260.  This is incredibly simplistic; the intention of this control is
547  * to provide something in the test model allowing digital outputs to be
548  * identified if present.  If models are found which can utilise these
549  * outputs a more complete mixer control can be devised for those models if
550  * necessary.
551  */
552 #ifdef CONFIG_SND_DEBUG
553 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
554
555 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
556                               struct snd_ctl_elem_value *ucontrol)
557 {
558         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
559         hda_nid_t nid = kcontrol->private_value & 0xffff;
560         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
561         long *valp = ucontrol->value.integer.value;
562         unsigned int val = snd_hda_codec_read(codec, nid, 0,
563                                               AC_VERB_GET_DIGI_CONVERT, 0x00);
564
565         *valp = (val & mask) != 0;
566         return 0;
567 }
568 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
569                               struct snd_ctl_elem_value *ucontrol)
570 {
571         signed int change;
572         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
573         hda_nid_t nid = kcontrol->private_value & 0xffff;
574         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
575         long val = *ucontrol->value.integer.value;
576         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
577                                                     AC_VERB_GET_DIGI_CONVERT,
578                                                     0x00);
579
580         /* Set/unset the masked control bit(s) as needed */
581         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
582         if (val==0)
583                 ctrl_data &= ~mask;
584         else
585                 ctrl_data |= mask;
586         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
587                                   ctrl_data);
588
589         return change;
590 }
591 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
592         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
593           .info = alc_spdif_ctrl_info, \
594           .get = alc_spdif_ctrl_get, \
595           .put = alc_spdif_ctrl_put, \
596           .private_value = nid | (mask<<16) }
597 #endif   /* CONFIG_SND_DEBUG */
598
599 /*
600  * set up from the preset table
601  */
602 static void setup_preset(struct alc_spec *spec,
603                          const struct alc_config_preset *preset)
604 {
605         int i;
606
607         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
608                 spec->mixers[spec->num_mixers++] = preset->mixers[i];
609         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
610              i++)
611                 spec->init_verbs[spec->num_init_verbs++] =
612                         preset->init_verbs[i];
613         
614         spec->channel_mode = preset->channel_mode;
615         spec->num_channel_mode = preset->num_channel_mode;
616         spec->need_dac_fix = preset->need_dac_fix;
617
618         spec->multiout.max_channels = spec->channel_mode[0].channels;
619
620         spec->multiout.num_dacs = preset->num_dacs;
621         spec->multiout.dac_nids = preset->dac_nids;
622         spec->multiout.dig_out_nid = preset->dig_out_nid;
623         spec->multiout.hp_nid = preset->hp_nid;
624         
625         spec->num_mux_defs = preset->num_mux_defs;
626         if (!spec->num_mux_defs)
627                 spec->num_mux_defs = 1;
628         spec->input_mux = preset->input_mux;
629
630         spec->num_adc_nids = preset->num_adc_nids;
631         spec->adc_nids = preset->adc_nids;
632         spec->dig_in_nid = preset->dig_in_nid;
633
634         spec->unsol_event = preset->unsol_event;
635         spec->init_hook = preset->init_hook;
636 #ifdef CONFIG_SND_HDA_POWER_SAVE
637         spec->loopback.amplist = preset->loopbacks;
638 #endif
639 }
640
641 /* Enable GPIO mask and set output */
642 static struct hda_verb alc_gpio1_init_verbs[] = {
643         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
644         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
645         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
646         { }
647 };
648
649 static struct hda_verb alc_gpio2_init_verbs[] = {
650         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
651         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
652         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
653         { }
654 };
655
656 static struct hda_verb alc_gpio3_init_verbs[] = {
657         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
658         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
659         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
660         { }
661 };
662
663 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
664  *      31 ~ 16 :       Manufacture ID
665  *      15 ~ 8  :       SKU ID
666  *      7  ~ 0  :       Assembly ID
667  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
668  */
669 static void alc_subsystem_id(struct hda_codec *codec,
670                              unsigned int porta, unsigned int porte,
671                              unsigned int portd)
672 {
673         unsigned int ass, tmp;
674
675         ass = codec->subsystem_id;
676         if (!(ass & 1))
677                 return;
678
679         /* Override */
680         tmp = (ass & 0x38) >> 3;        /* external Amp control */
681         switch (tmp) {
682         case 1:
683                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
684                 break;
685         case 3:
686                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
687                 break;
688         case 7:
689                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
690                 break;
691         case 5:
692                 switch (codec->vendor_id) {
693                 case 0x10ec0862:
694                 case 0x10ec0660:
695                 case 0x10ec0662:        
696                 case 0x10ec0267:
697                 case 0x10ec0268:
698                         snd_hda_codec_write(codec, 0x14, 0,
699                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
700                         snd_hda_codec_write(codec, 0x15, 0,
701                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
702                         return;
703                 }
704         case 6:
705                 if (ass & 4) {  /* bit 2 : 0 = Desktop, 1 = Laptop */
706                         hda_nid_t port = 0;
707                         tmp = (ass & 0x1800) >> 11;
708                         switch (tmp) {
709                         case 0: port = porta; break;
710                         case 1: port = porte; break;
711                         case 2: port = portd; break;
712                         }
713                         if (port)
714                                 snd_hda_codec_write(codec, port, 0,
715                                                     AC_VERB_SET_EAPD_BTLENABLE,
716                                                     2);
717                 }
718                 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
719                 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF,
720                                     (tmp == 5 ? 0x3040 : 0x3050));
721                 break;
722         }
723 }
724
725 /*
726  * Fix-up pin default configurations
727  */
728
729 struct alc_pincfg {
730         hda_nid_t nid;
731         u32 val;
732 };
733
734 static void alc_fix_pincfg(struct hda_codec *codec,
735                            const struct snd_pci_quirk *quirk,
736                            const struct alc_pincfg **pinfix)
737 {
738         const struct alc_pincfg *cfg;
739
740         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
741         if (!quirk)
742                 return;
743
744         cfg = pinfix[quirk->value];
745         for (; cfg->nid; cfg++) {
746                 int i;
747                 u32 val = cfg->val;
748                 for (i = 0; i < 4; i++) {
749                         snd_hda_codec_write(codec, cfg->nid, 0,
750                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0 + i,
751                                     val & 0xff);
752                         val >>= 8;
753                 }
754         }
755 }
756
757 /*
758  * ALC880 3-stack model
759  *
760  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
761  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
762  *                 F-Mic = 0x1b, HP = 0x19
763  */
764
765 static hda_nid_t alc880_dac_nids[4] = {
766         /* front, rear, clfe, rear_surr */
767         0x02, 0x05, 0x04, 0x03
768 };
769
770 static hda_nid_t alc880_adc_nids[3] = {
771         /* ADC0-2 */
772         0x07, 0x08, 0x09,
773 };
774
775 /* The datasheet says the node 0x07 is connected from inputs,
776  * but it shows zero connection in the real implementation on some devices.
777  * Note: this is a 915GAV bug, fixed on 915GLV
778  */
779 static hda_nid_t alc880_adc_nids_alt[2] = {
780         /* ADC1-2 */
781         0x08, 0x09,
782 };
783
784 #define ALC880_DIGOUT_NID       0x06
785 #define ALC880_DIGIN_NID        0x0a
786
787 static struct hda_input_mux alc880_capture_source = {
788         .num_items = 4,
789         .items = {
790                 { "Mic", 0x0 },
791                 { "Front Mic", 0x3 },
792                 { "Line", 0x2 },
793                 { "CD", 0x4 },
794         },
795 };
796
797 /* channel source setting (2/6 channel selection for 3-stack) */
798 /* 2ch mode */
799 static struct hda_verb alc880_threestack_ch2_init[] = {
800         /* set line-in to input, mute it */
801         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
802         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
803         /* set mic-in to input vref 80%, mute it */
804         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
805         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
806         { } /* end */
807 };
808
809 /* 6ch mode */
810 static struct hda_verb alc880_threestack_ch6_init[] = {
811         /* set line-in to output, unmute it */
812         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
813         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
814         /* set mic-in to output, unmute it */
815         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
816         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
817         { } /* end */
818 };
819
820 static struct hda_channel_mode alc880_threestack_modes[2] = {
821         { 2, alc880_threestack_ch2_init },
822         { 6, alc880_threestack_ch6_init },
823 };
824
825 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
826         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
827         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
828         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
829         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
830         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
831         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
832         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
833         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
834         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
835         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
836         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
837         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
838         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
839         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
840         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
841         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
842         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
843         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
844         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
845         {
846                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
847                 .name = "Channel Mode",
848                 .info = alc_ch_mode_info,
849                 .get = alc_ch_mode_get,
850                 .put = alc_ch_mode_put,
851         },
852         { } /* end */
853 };
854
855 /* capture mixer elements */
856 static struct snd_kcontrol_new alc880_capture_mixer[] = {
857         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
858         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
859         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
860         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
861         HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
862         HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
863         {
864                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
865                 /* The multiple "Capture Source" controls confuse alsamixer
866                  * So call somewhat different..
867                  * FIXME: the controls appear in the "playback" view!
868                  */
869                 /* .name = "Capture Source", */
870                 .name = "Input Source",
871                 .count = 3,
872                 .info = alc_mux_enum_info,
873                 .get = alc_mux_enum_get,
874                 .put = alc_mux_enum_put,
875         },
876         { } /* end */
877 };
878
879 /* capture mixer elements (in case NID 0x07 not available) */
880 static struct snd_kcontrol_new alc880_capture_alt_mixer[] = {
881         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
882         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
883         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
884         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
885         {
886                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
887                 /* The multiple "Capture Source" controls confuse alsamixer
888                  * So call somewhat different..
889                  * FIXME: the controls appear in the "playback" view!
890                  */
891                 /* .name = "Capture Source", */
892                 .name = "Input Source",
893                 .count = 2,
894                 .info = alc_mux_enum_info,
895                 .get = alc_mux_enum_get,
896                 .put = alc_mux_enum_put,
897         },
898         { } /* end */
899 };
900
901
902
903 /*
904  * ALC880 5-stack model
905  *
906  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
907  *      Side = 0x02 (0xd)
908  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
909  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
910  */
911
912 /* additional mixers to alc880_three_stack_mixer */
913 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
914         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
915         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
916         { } /* end */
917 };
918
919 /* channel source setting (6/8 channel selection for 5-stack) */
920 /* 6ch mode */
921 static struct hda_verb alc880_fivestack_ch6_init[] = {
922         /* set line-in to input, mute it */
923         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
924         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
925         { } /* end */
926 };
927
928 /* 8ch mode */
929 static struct hda_verb alc880_fivestack_ch8_init[] = {
930         /* set line-in to output, unmute it */
931         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
932         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
933         { } /* end */
934 };
935
936 static struct hda_channel_mode alc880_fivestack_modes[2] = {
937         { 6, alc880_fivestack_ch6_init },
938         { 8, alc880_fivestack_ch8_init },
939 };
940
941
942 /*
943  * ALC880 6-stack model
944  *
945  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
946  *      Side = 0x05 (0x0f)
947  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
948  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
949  */
950
951 static hda_nid_t alc880_6st_dac_nids[4] = {
952         /* front, rear, clfe, rear_surr */
953         0x02, 0x03, 0x04, 0x05
954 };
955
956 static struct hda_input_mux alc880_6stack_capture_source = {
957         .num_items = 4,
958         .items = {
959                 { "Mic", 0x0 },
960                 { "Front Mic", 0x1 },
961                 { "Line", 0x2 },
962                 { "CD", 0x4 },
963         },
964 };
965
966 /* fixed 8-channels */
967 static struct hda_channel_mode alc880_sixstack_modes[1] = {
968         { 8, NULL },
969 };
970
971 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
972         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
973         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
974         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
975         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
976         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
977         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
978         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
979         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
980         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
981         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
982         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
983         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
984         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
985         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
986         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
987         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
988         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
989         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
990         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
991         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
992         {
993                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
994                 .name = "Channel Mode",
995                 .info = alc_ch_mode_info,
996                 .get = alc_ch_mode_get,
997                 .put = alc_ch_mode_put,
998         },
999         { } /* end */
1000 };
1001
1002
1003 /*
1004  * ALC880 W810 model
1005  *
1006  * W810 has rear IO for:
1007  * Front (DAC 02)
1008  * Surround (DAC 03)
1009  * Center/LFE (DAC 04)
1010  * Digital out (06)
1011  *
1012  * The system also has a pair of internal speakers, and a headphone jack.
1013  * These are both connected to Line2 on the codec, hence to DAC 02.
1014  * 
1015  * There is a variable resistor to control the speaker or headphone
1016  * volume. This is a hardware-only device without a software API.
1017  *
1018  * Plugging headphones in will disable the internal speakers. This is
1019  * implemented in hardware, not via the driver using jack sense. In
1020  * a similar fashion, plugging into the rear socket marked "front" will
1021  * disable both the speakers and headphones.
1022  *
1023  * For input, there's a microphone jack, and an "audio in" jack.
1024  * These may not do anything useful with this driver yet, because I
1025  * haven't setup any initialization verbs for these yet...
1026  */
1027
1028 static hda_nid_t alc880_w810_dac_nids[3] = {
1029         /* front, rear/surround, clfe */
1030         0x02, 0x03, 0x04
1031 };
1032
1033 /* fixed 6 channels */
1034 static struct hda_channel_mode alc880_w810_modes[1] = {
1035         { 6, NULL }
1036 };
1037
1038 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
1039 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
1040         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1041         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1042         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1043         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1044         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1045         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1046         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1047         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1048         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1049         { } /* end */
1050 };
1051
1052
1053 /*
1054  * Z710V model
1055  *
1056  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
1057  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
1058  *                 Line = 0x1a
1059  */
1060
1061 static hda_nid_t alc880_z71v_dac_nids[1] = {
1062         0x02
1063 };
1064 #define ALC880_Z71V_HP_DAC      0x03
1065
1066 /* fixed 2 channels */
1067 static struct hda_channel_mode alc880_2_jack_modes[1] = {
1068         { 2, NULL }
1069 };
1070
1071 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
1072         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1073         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1074         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1075         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
1076         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1077         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1078         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1079         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1080         { } /* end */
1081 };
1082
1083
1084 /* FIXME! */
1085 /*
1086  * ALC880 F1734 model
1087  *
1088  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
1089  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
1090  */
1091
1092 static hda_nid_t alc880_f1734_dac_nids[1] = {
1093         0x03
1094 };
1095 #define ALC880_F1734_HP_DAC     0x02
1096
1097 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
1098         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1099         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1100         HDA_CODEC_VOLUME("Internal Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1101         HDA_BIND_MUTE("Internal Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1102         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1103         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1104         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1105         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1106         { } /* end */
1107 };
1108
1109
1110 /* FIXME! */
1111 /*
1112  * ALC880 ASUS model
1113  *
1114  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1115  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1116  *  Mic = 0x18, Line = 0x1a
1117  */
1118
1119 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
1120 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
1121
1122 static struct snd_kcontrol_new alc880_asus_mixer[] = {
1123         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1124         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1125         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1126         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1127         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1128         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1129         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1130         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1131         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1132         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1133         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1134         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1135         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1136         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1137         {
1138                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1139                 .name = "Channel Mode",
1140                 .info = alc_ch_mode_info,
1141                 .get = alc_ch_mode_get,
1142                 .put = alc_ch_mode_put,
1143         },
1144         { } /* end */
1145 };
1146
1147 /* FIXME! */
1148 /*
1149  * ALC880 ASUS W1V model
1150  *
1151  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1152  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1153  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
1154  */
1155
1156 /* additional mixers to alc880_asus_mixer */
1157 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
1158         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
1159         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
1160         { } /* end */
1161 };
1162
1163 /* additional mixers to alc880_asus_mixer */
1164 static struct snd_kcontrol_new alc880_pcbeep_mixer[] = {
1165         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1166         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1167         { } /* end */
1168 };
1169
1170 /* TCL S700 */
1171 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
1172         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1173         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1174         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1175         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
1176         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
1177         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
1178         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
1179         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1180         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1181         {
1182                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1183                 /* The multiple "Capture Source" controls confuse alsamixer
1184                  * So call somewhat different..
1185                  * FIXME: the controls appear in the "playback" view!
1186                  */
1187                 /* .name = "Capture Source", */
1188                 .name = "Input Source",
1189                 .count = 1,
1190                 .info = alc_mux_enum_info,
1191                 .get = alc_mux_enum_get,
1192                 .put = alc_mux_enum_put,
1193         },
1194         { } /* end */
1195 };
1196
1197 /* Uniwill */
1198 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
1199         HDA_CODEC_VOLUME("HPhone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1200         HDA_BIND_MUTE("HPhone Playback Switch", 0x0c, 2, HDA_INPUT),
1201         HDA_CODEC_VOLUME("iSpeaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1202         HDA_BIND_MUTE("iSpeaker Playback Switch", 0x0d, 2, HDA_INPUT),
1203         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1204         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1205         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1206         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1207         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1208         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1209         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1210         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1211         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1212         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1213         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1214         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1215         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1216         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1217         {
1218                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1219                 .name = "Channel Mode",
1220                 .info = alc_ch_mode_info,
1221                 .get = alc_ch_mode_get,
1222                 .put = alc_ch_mode_put,
1223         },
1224         { } /* end */
1225 };
1226
1227 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
1228         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1229         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1230         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1231         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1232         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1233         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1234         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1235         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1236         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1237         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1238         { } /* end */
1239 };
1240
1241 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
1242         HDA_CODEC_VOLUME("HPhone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1243         HDA_BIND_MUTE("HPhone Playback Switch", 0x0c, 2, HDA_INPUT),
1244         HDA_CODEC_VOLUME("iSpeaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1245         HDA_BIND_MUTE("iSpeaker Playback Switch", 0x0d, 2, HDA_INPUT),
1246         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1247         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1248         { } /* end */
1249 };
1250
1251 /*
1252  * build control elements
1253  */
1254 static int alc_build_controls(struct hda_codec *codec)
1255 {
1256         struct alc_spec *spec = codec->spec;
1257         int err;
1258         int i;
1259
1260         for (i = 0; i < spec->num_mixers; i++) {
1261                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1262                 if (err < 0)
1263                         return err;
1264         }
1265
1266         if (spec->multiout.dig_out_nid) {
1267                 err = snd_hda_create_spdif_out_ctls(codec,
1268                                                     spec->multiout.dig_out_nid);
1269                 if (err < 0)
1270                         return err;
1271         }
1272         if (spec->dig_in_nid) {
1273                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1274                 if (err < 0)
1275                         return err;
1276         }
1277         return 0;
1278 }
1279
1280
1281 /*
1282  * initialize the codec volumes, etc
1283  */
1284
1285 /*
1286  * generic initialization of ADC, input mixers and output mixers
1287  */
1288 static struct hda_verb alc880_volume_init_verbs[] = {
1289         /*
1290          * Unmute ADC0-2 and set the default input to mic-in
1291          */
1292         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
1293         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1294         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
1295         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1296         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
1297         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1298
1299         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1300          * mixer widget
1301          * Note: PASD motherboards uses the Line In 2 as the input for front
1302          * panel mic (mic 2)
1303          */
1304         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
1305         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1306         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1307         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
1308         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
1309         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
1310         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
1311         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
1312
1313         /*
1314          * Set up output mixers (0x0c - 0x0f)
1315          */
1316         /* set vol=0 to output mixers */
1317         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1318         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1319         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1320         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1321         /* set up input amps for analog loopback */
1322         /* Amp Indices: DAC = 0, mixer = 1 */
1323         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1324         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1325         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1326         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1327         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1328         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1329         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1330         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1331
1332         { }
1333 };
1334
1335 /*
1336  * 3-stack pin configuration:
1337  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
1338  */
1339 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
1340         /*
1341          * preset connection lists of input pins
1342          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1343          */
1344         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
1345         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1346         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
1347
1348         /*
1349          * Set pin mode and muting
1350          */
1351         /* set front pin widgets 0x14 for output */
1352         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1353         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1354         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1355         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1356         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1357         /* Mic2 (as headphone out) for HP output */
1358         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1359         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1360         /* Line In pin widget for input */
1361         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1362         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1363         /* Line2 (as front mic) pin widget for input and vref at 80% */
1364         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1365         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1366         /* CD pin widget for input */
1367         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1368
1369         { }
1370 };
1371
1372 /*
1373  * 5-stack pin configuration:
1374  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
1375  * line-in/side = 0x1a, f-mic = 0x1b
1376  */
1377 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
1378         /*
1379          * preset connection lists of input pins
1380          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1381          */
1382         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1383         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
1384
1385         /*
1386          * Set pin mode and muting
1387          */
1388         /* set pin widgets 0x14-0x17 for output */
1389         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1390         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1391         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1392         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1393         /* unmute pins for output (no gain on this amp) */
1394         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1395         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1396         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1397         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1398
1399         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1400         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1401         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1402         /* Mic2 (as headphone out) for HP output */
1403         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1404         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1405         /* Line In pin widget for input */
1406         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1407         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1408         /* Line2 (as front mic) pin widget for input and vref at 80% */
1409         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1410         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1411         /* CD pin widget for input */
1412         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1413
1414         { }
1415 };
1416
1417 /*
1418  * W810 pin configuration:
1419  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
1420  */
1421 static struct hda_verb alc880_pin_w810_init_verbs[] = {
1422         /* hphone/speaker input selector: front DAC */
1423         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
1424
1425         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1426         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1427         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1428         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1429         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1430         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1431
1432         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1433         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1434
1435         { }
1436 };
1437
1438 /*
1439  * Z71V pin configuration:
1440  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
1441  */
1442 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
1443         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1444         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1445         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1446         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1447
1448         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1449         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1450         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1451         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1452
1453         { }
1454 };
1455
1456 /*
1457  * 6-stack pin configuration:
1458  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
1459  * f-mic = 0x19, line = 0x1a, HP = 0x1b
1460  */
1461 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
1462         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1463
1464         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1465         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1466         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1467         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1468         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1469         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1470         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1471         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1472
1473         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1474         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1475         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1476         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1477         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1478         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1479         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1480         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1481         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1482         
1483         { }
1484 };
1485
1486 /*
1487  * Uniwill pin configuration:
1488  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
1489  * line = 0x1a
1490  */
1491 static struct hda_verb alc880_uniwill_init_verbs[] = {
1492         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1493
1494         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1495         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1496         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1497         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1498         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1499         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1500         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1501         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1502         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1503         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1504         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1505         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1506         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1507         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1508
1509         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1510         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1511         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1512         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1513         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1514         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1515         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
1516         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
1517         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1518
1519         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
1520         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
1521
1522         { }
1523 };
1524
1525 /*
1526 * Uniwill P53
1527 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19, 
1528  */
1529 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
1530         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1531
1532         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1533         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1534         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1535         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1536         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1537         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1538         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1539         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1540         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1541         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1542         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1543         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1544
1545         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1546         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1547         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1548         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1549         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1550         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1551
1552         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
1553         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
1554
1555         { }
1556 };
1557
1558 static struct hda_verb alc880_beep_init_verbs[] = {
1559         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
1560         { }
1561 };
1562
1563 /* toggle speaker-output according to the hp-jack state */
1564 static void alc880_uniwill_hp_automute(struct hda_codec *codec)
1565 {
1566         unsigned int present;
1567         unsigned char bits;
1568
1569         present = snd_hda_codec_read(codec, 0x14, 0,
1570                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1571         bits = present ? HDA_AMP_MUTE : 0;
1572         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
1573                                  HDA_AMP_MUTE, bits);
1574         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
1575                                  HDA_AMP_MUTE, bits);
1576 }
1577
1578 /* auto-toggle front mic */
1579 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
1580 {
1581         unsigned int present;
1582         unsigned char bits;
1583
1584         present = snd_hda_codec_read(codec, 0x18, 0,
1585                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1586         bits = present ? HDA_AMP_MUTE : 0;
1587         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
1588 }
1589
1590 static void alc880_uniwill_automute(struct hda_codec *codec)
1591 {
1592         alc880_uniwill_hp_automute(codec);
1593         alc880_uniwill_mic_automute(codec);
1594 }
1595
1596 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
1597                                        unsigned int res)
1598 {
1599         /* Looks like the unsol event is incompatible with the standard
1600          * definition.  4bit tag is placed at 28 bit!
1601          */
1602         switch (res >> 28) {
1603         case ALC880_HP_EVENT:
1604                 alc880_uniwill_hp_automute(codec);
1605                 break;
1606         case ALC880_MIC_EVENT:
1607                 alc880_uniwill_mic_automute(codec);
1608                 break;
1609         }
1610 }
1611
1612 static void alc880_uniwill_p53_hp_automute(struct hda_codec *codec)
1613 {
1614         unsigned int present;
1615         unsigned char bits;
1616
1617         present = snd_hda_codec_read(codec, 0x14, 0,
1618                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1619         bits = present ? HDA_AMP_MUTE : 0;
1620         snd_hda_codec_amp_stereo(codec, 0x15, HDA_INPUT, 0, HDA_AMP_MUTE, bits);
1621 }
1622
1623 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
1624 {
1625         unsigned int present;
1626         
1627         present = snd_hda_codec_read(codec, 0x21, 0,
1628                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
1629         present &= HDA_AMP_VOLMASK;
1630         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
1631                                  HDA_AMP_VOLMASK, present);
1632         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
1633                                  HDA_AMP_VOLMASK, present);
1634 }
1635
1636 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
1637                                            unsigned int res)
1638 {
1639         /* Looks like the unsol event is incompatible with the standard
1640          * definition.  4bit tag is placed at 28 bit!
1641          */
1642         if ((res >> 28) == ALC880_HP_EVENT)
1643                 alc880_uniwill_p53_hp_automute(codec);
1644         if ((res >> 28) == ALC880_DCVOL_EVENT)
1645                 alc880_uniwill_p53_dcvol_automute(codec);
1646 }
1647
1648 /* FIXME! */
1649 /*
1650  * F1734 pin configuration:
1651  * HP = 0x14, speaker-out = 0x15, mic = 0x18
1652  */
1653 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
1654         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
1655         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
1656         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
1657         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
1658
1659         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1660         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1661         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1662         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1663
1664         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1665         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1666         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1667         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1668         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1669         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1670         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1671         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1672         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1673
1674         { }
1675 };
1676
1677 /* FIXME! */
1678 /*
1679  * ASUS pin configuration:
1680  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
1681  */
1682 static struct hda_verb alc880_pin_asus_init_verbs[] = {
1683         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
1684         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
1685         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
1686         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
1687
1688         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1689         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1690         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1691         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1692         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1693         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1694         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1695         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1696
1697         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1698         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1699         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1700         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1701         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1702         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1703         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1704         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1705         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1706         
1707         { }
1708 };
1709
1710 /* Enable GPIO mask and set output */
1711 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
1712 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
1713
1714 /* Clevo m520g init */
1715 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
1716         /* headphone output */
1717         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
1718         /* line-out */
1719         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1720         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1721         /* Line-in */
1722         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1723         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1724         /* CD */
1725         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1726         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1727         /* Mic1 (rear panel) */
1728         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1729         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1730         /* Mic2 (front panel) */
1731         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1732         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1733         /* headphone */
1734         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1735         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1736         /* change to EAPD mode */
1737         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
1738         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
1739
1740         { }
1741 };
1742
1743 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
1744         /* change to EAPD mode */
1745         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
1746         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
1747
1748         /* Headphone output */
1749         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1750         /* Front output*/
1751         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1752         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1753
1754         /* Line In pin widget for input */
1755         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1756         /* CD pin widget for input */
1757         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1758         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1759         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1760
1761         /* change to EAPD mode */
1762         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
1763         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
1764
1765         { }
1766 };
1767
1768 /*
1769  * LG m1 express dual
1770  *
1771  * Pin assignment:
1772  *   Rear Line-In/Out (blue): 0x14
1773  *   Build-in Mic-In: 0x15
1774  *   Speaker-out: 0x17
1775  *   HP-Out (green): 0x1b
1776  *   Mic-In/Out (red): 0x19
1777  *   SPDIF-Out: 0x1e
1778  */
1779
1780 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
1781 static hda_nid_t alc880_lg_dac_nids[3] = {
1782         0x05, 0x02, 0x03
1783 };
1784
1785 /* seems analog CD is not working */
1786 static struct hda_input_mux alc880_lg_capture_source = {
1787         .num_items = 3,
1788         .items = {
1789                 { "Mic", 0x1 },
1790                 { "Line", 0x5 },
1791                 { "Internal Mic", 0x6 },
1792         },
1793 };
1794
1795 /* 2,4,6 channel modes */
1796 static struct hda_verb alc880_lg_ch2_init[] = {
1797         /* set line-in and mic-in to input */
1798         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1799         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1800         { }
1801 };
1802
1803 static struct hda_verb alc880_lg_ch4_init[] = {
1804         /* set line-in to out and mic-in to input */
1805         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1806         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1807         { }
1808 };
1809
1810 static struct hda_verb alc880_lg_ch6_init[] = {
1811         /* set line-in and mic-in to output */
1812         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1813         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1814         { }
1815 };
1816
1817 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
1818         { 2, alc880_lg_ch2_init },
1819         { 4, alc880_lg_ch4_init },
1820         { 6, alc880_lg_ch6_init },
1821 };
1822
1823 static struct snd_kcontrol_new alc880_lg_mixer[] = {
1824         /* FIXME: it's not really "master" but front channels */
1825         HDA_CODEC_VOLUME("Master Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1826         HDA_BIND_MUTE("Master Playback Switch", 0x0f, 2, HDA_INPUT),
1827         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1828         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
1829         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
1830         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
1831         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
1832         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
1833         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1834         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1835         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
1836         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
1837         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
1838         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
1839         {
1840                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1841                 .name = "Channel Mode",
1842                 .info = alc_ch_mode_info,
1843                 .get = alc_ch_mode_get,
1844                 .put = alc_ch_mode_put,
1845         },
1846         { } /* end */
1847 };
1848
1849 static struct hda_verb alc880_lg_init_verbs[] = {
1850         /* set capture source to mic-in */
1851         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1852         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1853         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1854         /* mute all amp mixer inputs */
1855         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
1856         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
1857         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
1858         /* line-in to input */
1859         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1860         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1861         /* built-in mic */
1862         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1863         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1864         /* speaker-out */
1865         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1866         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1867         /* mic-in to input */
1868         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
1869         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1870         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1871         /* HP-out */
1872         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
1873         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1874         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1875         /* jack sense */
1876         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
1877         { }
1878 };
1879
1880 /* toggle speaker-output according to the hp-jack state */
1881 static void alc880_lg_automute(struct hda_codec *codec)
1882 {
1883         unsigned int present;
1884         unsigned char bits;
1885
1886         present = snd_hda_codec_read(codec, 0x1b, 0,
1887                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1888         bits = present ? HDA_AMP_MUTE : 0;
1889         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
1890                                  HDA_AMP_MUTE, bits);
1891 }
1892
1893 static void alc880_lg_unsol_event(struct hda_codec *codec, unsigned int res)
1894 {
1895         /* Looks like the unsol event is incompatible with the standard
1896          * definition.  4bit tag is placed at 28 bit!
1897          */
1898         if ((res >> 28) == 0x01)
1899                 alc880_lg_automute(codec);
1900 }
1901
1902 /*
1903  * LG LW20
1904  *
1905  * Pin assignment:
1906  *   Speaker-out: 0x14
1907  *   Mic-In: 0x18
1908  *   Built-in Mic-In: 0x19
1909  *   Line-In: 0x1b
1910  *   HP-Out: 0x1a
1911  *   SPDIF-Out: 0x1e
1912  */
1913
1914 static struct hda_input_mux alc880_lg_lw_capture_source = {
1915         .num_items = 3,
1916         .items = {
1917                 { "Mic", 0x0 },
1918                 { "Internal Mic", 0x1 },
1919                 { "Line In", 0x2 },
1920         },
1921 };
1922
1923 #define alc880_lg_lw_modes alc880_threestack_modes
1924
1925 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
1926         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1927         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1928         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1929         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1930         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1931         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1932         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1933         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1934         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1935         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1936         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1937         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1938         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
1939         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
1940         {
1941                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1942                 .name = "Channel Mode",
1943                 .info = alc_ch_mode_info,
1944                 .get = alc_ch_mode_get,
1945                 .put = alc_ch_mode_put,
1946         },
1947         { } /* end */
1948 };
1949
1950 static struct hda_verb alc880_lg_lw_init_verbs[] = {
1951         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1952         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
1953         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
1954
1955         /* set capture source to mic-in */
1956         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1957         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1958         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1959         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
1960         /* speaker-out */
1961         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1962         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1963         /* HP-out */
1964         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1965         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1966         /* mic-in to input */
1967         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1968         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1969         /* built-in mic */
1970         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1971         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1972         /* jack sense */
1973         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
1974         { }
1975 };
1976
1977 /* toggle speaker-output according to the hp-jack state */
1978 static void alc880_lg_lw_automute(struct hda_codec *codec)
1979 {
1980         unsigned int present;
1981         unsigned char bits;
1982
1983         present = snd_hda_codec_read(codec, 0x1b, 0,
1984                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1985         bits = present ? HDA_AMP_MUTE : 0;
1986         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
1987                                  HDA_AMP_MUTE, bits);
1988 }
1989
1990 static void alc880_lg_lw_unsol_event(struct hda_codec *codec, unsigned int res)
1991 {
1992         /* Looks like the unsol event is incompatible with the standard
1993          * definition.  4bit tag is placed at 28 bit!
1994          */
1995         if ((res >> 28) == 0x01)
1996                 alc880_lg_lw_automute(codec);
1997 }
1998
1999 #ifdef CONFIG_SND_HDA_POWER_SAVE
2000 static struct hda_amp_list alc880_loopbacks[] = {
2001         { 0x0b, HDA_INPUT, 0 },
2002         { 0x0b, HDA_INPUT, 1 },
2003         { 0x0b, HDA_INPUT, 2 },
2004         { 0x0b, HDA_INPUT, 3 },
2005         { 0x0b, HDA_INPUT, 4 },
2006         { } /* end */
2007 };
2008
2009 static struct hda_amp_list alc880_lg_loopbacks[] = {
2010         { 0x0b, HDA_INPUT, 1 },
2011         { 0x0b, HDA_INPUT, 6 },
2012         { 0x0b, HDA_INPUT, 7 },
2013         { } /* end */
2014 };
2015 #endif
2016
2017 /*
2018  * Common callbacks
2019  */
2020
2021 static int alc_init(struct hda_codec *codec)
2022 {
2023         struct alc_spec *spec = codec->spec;
2024         unsigned int i;
2025
2026         for (i = 0; i < spec->num_init_verbs; i++)
2027                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2028
2029         if (spec->init_hook)
2030                 spec->init_hook(codec);
2031
2032         return 0;
2033 }
2034
2035 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2036 {
2037         struct alc_spec *spec = codec->spec;
2038
2039         if (spec->unsol_event)
2040                 spec->unsol_event(codec, res);
2041 }
2042
2043 #ifdef CONFIG_SND_HDA_POWER_SAVE
2044 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2045 {
2046         struct alc_spec *spec = codec->spec;
2047         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2048 }
2049 #endif
2050
2051 /*
2052  * Analog playback callbacks
2053  */
2054 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
2055                                     struct hda_codec *codec,
2056                                     struct snd_pcm_substream *substream)
2057 {
2058         struct alc_spec *spec = codec->spec;
2059         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
2060 }
2061
2062 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2063                                        struct hda_codec *codec,
2064                                        unsigned int stream_tag,
2065                                        unsigned int format,
2066                                        struct snd_pcm_substream *substream)
2067 {
2068         struct alc_spec *spec = codec->spec;
2069         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2070                                                 stream_tag, format, substream);
2071 }
2072
2073 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2074                                        struct hda_codec *codec,
2075                                        struct snd_pcm_substream *substream)
2076 {
2077         struct alc_spec *spec = codec->spec;
2078         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2079 }
2080
2081 /*
2082  * Digital out
2083  */
2084 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2085                                         struct hda_codec *codec,
2086                                         struct snd_pcm_substream *substream)
2087 {
2088         struct alc_spec *spec = codec->spec;
2089         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2090 }
2091
2092 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2093                                            struct hda_codec *codec,
2094                                            unsigned int stream_tag,
2095                                            unsigned int format,
2096                                            struct snd_pcm_substream *substream)
2097 {
2098         struct alc_spec *spec = codec->spec;
2099         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2100                                              stream_tag, format, substream);
2101 }
2102
2103 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2104                                          struct hda_codec *codec,
2105                                          struct snd_pcm_substream *substream)
2106 {
2107         struct alc_spec *spec = codec->spec;
2108         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2109 }
2110
2111 /*
2112  * Analog capture
2113  */
2114 static int alc880_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2115                                       struct hda_codec *codec,
2116                                       unsigned int stream_tag,
2117                                       unsigned int format,
2118                                       struct snd_pcm_substream *substream)
2119 {
2120         struct alc_spec *spec = codec->spec;
2121
2122         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
2123                                    stream_tag, 0, format);
2124         return 0;
2125 }
2126
2127 static int alc880_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2128                                       struct hda_codec *codec,
2129                                       struct snd_pcm_substream *substream)
2130 {
2131         struct alc_spec *spec = codec->spec;
2132
2133         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
2134                                    0, 0, 0);
2135         return 0;
2136 }
2137
2138
2139 /*
2140  */
2141 static struct hda_pcm_stream alc880_pcm_analog_playback = {
2142         .substreams = 1,
2143         .channels_min = 2,
2144         .channels_max = 8,
2145         /* NID is set in alc_build_pcms */
2146         .ops = {
2147                 .open = alc880_playback_pcm_open,
2148                 .prepare = alc880_playback_pcm_prepare,
2149                 .cleanup = alc880_playback_pcm_cleanup
2150         },
2151 };
2152
2153 static struct hda_pcm_stream alc880_pcm_analog_capture = {
2154         .substreams = 2,
2155         .channels_min = 2,
2156         .channels_max = 2,
2157         /* NID is set in alc_build_pcms */
2158         .ops = {
2159                 .prepare = alc880_capture_pcm_prepare,
2160                 .cleanup = alc880_capture_pcm_cleanup
2161         },
2162 };
2163
2164 static struct hda_pcm_stream alc880_pcm_digital_playback = {
2165         .substreams = 1,
2166         .channels_min = 2,
2167         .channels_max = 2,
2168         /* NID is set in alc_build_pcms */
2169         .ops = {
2170                 .open = alc880_dig_playback_pcm_open,
2171                 .close = alc880_dig_playback_pcm_close,
2172                 .prepare = alc880_dig_playback_pcm_prepare
2173         },
2174 };
2175
2176 static struct hda_pcm_stream alc880_pcm_digital_capture = {
2177         .substreams = 1,
2178         .channels_min = 2,
2179         .channels_max = 2,
2180         /* NID is set in alc_build_pcms */
2181 };
2182
2183 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2184 static struct hda_pcm_stream alc_pcm_null_playback = {
2185         .substreams = 0,
2186         .channels_min = 0,
2187         .channels_max = 0,
2188 };
2189
2190 static int alc_build_pcms(struct hda_codec *codec)
2191 {
2192         struct alc_spec *spec = codec->spec;
2193         struct hda_pcm *info = spec->pcm_rec;
2194         int i;
2195
2196         codec->num_pcms = 1;
2197         codec->pcm_info = info;
2198
2199         info->name = spec->stream_name_analog;
2200         if (spec->stream_analog_playback) {
2201                 snd_assert(spec->multiout.dac_nids, return -EINVAL);
2202                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
2203                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2204         }
2205         if (spec->stream_analog_capture) {
2206                 snd_assert(spec->adc_nids, return -EINVAL);
2207                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
2208                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2209         }
2210
2211         if (spec->channel_mode) {
2212                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2213                 for (i = 0; i < spec->num_channel_mode; i++) {
2214                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2215                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2216                         }
2217                 }
2218         }
2219
2220         /* SPDIF for stream index #1 */
2221         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2222                 codec->num_pcms = 2;
2223                 info = spec->pcm_rec + 1;
2224                 info->name = spec->stream_name_digital;
2225                 if (spec->multiout.dig_out_nid &&
2226                     spec->stream_digital_playback) {
2227                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
2228                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2229                 }
2230                 if (spec->dig_in_nid &&
2231                     spec->stream_digital_capture) {
2232                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
2233                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2234                 }
2235         }
2236
2237         /* If the use of more than one ADC is requested for the current
2238          * model, configure a second analog capture-only PCM.
2239          */
2240         /* Additional Analaog capture for index #2 */
2241         if (spec->num_adc_nids > 1 && spec->stream_analog_capture &&
2242             spec->adc_nids) {
2243                 codec->num_pcms = 3;
2244                 info = spec->pcm_rec + 2;
2245                 info->name = spec->stream_name_analog;
2246                 /* No playback stream for second PCM */
2247                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = alc_pcm_null_playback;
2248                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2249                 if (spec->stream_analog_capture) {
2250                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
2251                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[1];
2252                 }
2253         }
2254
2255         return 0;
2256 }
2257
2258 static void alc_free(struct hda_codec *codec)
2259 {
2260         struct alc_spec *spec = codec->spec;
2261         unsigned int i;
2262
2263         if (!spec)
2264                 return;
2265
2266         if (spec->kctl_alloc) {
2267                 for (i = 0; i < spec->num_kctl_used; i++)
2268                         kfree(spec->kctl_alloc[i].name);
2269                 kfree(spec->kctl_alloc);
2270         }
2271         kfree(spec);
2272 }
2273
2274 /*
2275  */
2276 static struct hda_codec_ops alc_patch_ops = {
2277         .build_controls = alc_build_controls,
2278         .build_pcms = alc_build_pcms,
2279         .init = alc_init,
2280         .free = alc_free,
2281         .unsol_event = alc_unsol_event,
2282 #ifdef CONFIG_SND_HDA_POWER_SAVE
2283         .check_power_status = alc_check_power_status,
2284 #endif
2285 };
2286
2287
2288 /*
2289  * Test configuration for debugging
2290  *
2291  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
2292  * enum controls.
2293  */
2294 #ifdef CONFIG_SND_DEBUG
2295 static hda_nid_t alc880_test_dac_nids[4] = {
2296         0x02, 0x03, 0x04, 0x05
2297 };
2298
2299 static struct hda_input_mux alc880_test_capture_source = {
2300         .num_items = 7,
2301         .items = {
2302                 { "In-1", 0x0 },
2303                 { "In-2", 0x1 },
2304                 { "In-3", 0x2 },
2305                 { "In-4", 0x3 },
2306                 { "CD", 0x4 },
2307                 { "Front", 0x5 },
2308                 { "Surround", 0x6 },
2309         },
2310 };
2311
2312 static struct hda_channel_mode alc880_test_modes[4] = {
2313         { 2, NULL },
2314         { 4, NULL },
2315         { 6, NULL },
2316         { 8, NULL },
2317 };
2318
2319 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
2320                                  struct snd_ctl_elem_info *uinfo)
2321 {
2322         static char *texts[] = {
2323                 "N/A", "Line Out", "HP Out",
2324                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
2325         };
2326         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2327         uinfo->count = 1;
2328         uinfo->value.enumerated.items = 8;
2329         if (uinfo->value.enumerated.item >= 8)
2330                 uinfo->value.enumerated.item = 7;
2331         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2332         return 0;
2333 }
2334
2335 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
2336                                 struct snd_ctl_elem_value *ucontrol)
2337 {
2338         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2339         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2340         unsigned int pin_ctl, item = 0;
2341
2342         pin_ctl = snd_hda_codec_read(codec, nid, 0,
2343                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2344         if (pin_ctl & AC_PINCTL_OUT_EN) {
2345                 if (pin_ctl & AC_PINCTL_HP_EN)
2346                         item = 2;
2347                 else
2348                         item = 1;
2349         } else if (pin_ctl & AC_PINCTL_IN_EN) {
2350                 switch (pin_ctl & AC_PINCTL_VREFEN) {
2351                 case AC_PINCTL_VREF_HIZ: item = 3; break;
2352                 case AC_PINCTL_VREF_50:  item = 4; break;
2353                 case AC_PINCTL_VREF_GRD: item = 5; break;
2354                 case AC_PINCTL_VREF_80:  item = 6; break;
2355                 case AC_PINCTL_VREF_100: item = 7; break;
2356                 }
2357         }
2358         ucontrol->value.enumerated.item[0] = item;
2359         return 0;
2360 }
2361
2362 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
2363                                 struct snd_ctl_elem_value *ucontrol)
2364 {
2365         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2366         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2367         static unsigned int ctls[] = {
2368                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
2369                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
2370                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
2371                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
2372                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
2373                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
2374         };
2375         unsigned int old_ctl, new_ctl;
2376
2377         old_ctl = snd_hda_codec_read(codec, nid, 0,
2378                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2379         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
2380         if (old_ctl != new_ctl) {
2381                 int val;
2382                 snd_hda_codec_write_cache(codec, nid, 0,
2383                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
2384                                           new_ctl);
2385                 val = ucontrol->value.enumerated.item[0] >= 3 ?
2386                         HDA_AMP_MUTE : 0;
2387                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
2388                                          HDA_AMP_MUTE, val);
2389                 return 1;
2390         }
2391         return 0;
2392 }
2393
2394 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
2395                                  struct snd_ctl_elem_info *uinfo)
2396 {
2397         static char *texts[] = {
2398                 "Front", "Surround", "CLFE", "Side"
2399         };
2400         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2401         uinfo->count = 1;
2402         uinfo->value.enumerated.items = 4;
2403         if (uinfo->value.enumerated.item >= 4)
2404                 uinfo->value.enumerated.item = 3;
2405         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2406         return 0;
2407 }
2408
2409 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
2410                                 struct snd_ctl_elem_value *ucontrol)
2411 {
2412         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2413         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2414         unsigned int sel;
2415
2416         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
2417         ucontrol->value.enumerated.item[0] = sel & 3;
2418         return 0;
2419 }
2420
2421 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
2422                                 struct snd_ctl_elem_value *ucontrol)
2423 {
2424         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2425         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2426         unsigned int sel;
2427
2428         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
2429         if (ucontrol->value.enumerated.item[0] != sel) {
2430                 sel = ucontrol->value.enumerated.item[0] & 3;
2431                 snd_hda_codec_write_cache(codec, nid, 0,
2432                                           AC_VERB_SET_CONNECT_SEL, sel);
2433                 return 1;
2434         }
2435         return 0;
2436 }
2437
2438 #define PIN_CTL_TEST(xname,nid) {                       \
2439                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
2440                         .name = xname,                 \
2441                         .info = alc_test_pin_ctl_info, \
2442                         .get = alc_test_pin_ctl_get,   \
2443                         .put = alc_test_pin_ctl_put,   \
2444                         .private_value = nid           \
2445                         }
2446
2447 #define PIN_SRC_TEST(xname,nid) {                       \
2448                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
2449                         .name = xname,                 \
2450                         .info = alc_test_pin_src_info, \
2451                         .get = alc_test_pin_src_get,   \
2452                         .put = alc_test_pin_src_put,   \
2453                         .private_value = nid           \
2454                         }
2455
2456 static struct snd_kcontrol_new alc880_test_mixer[] = {
2457         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2458         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2459         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
2460         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2461         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2462         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2463         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
2464         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2465         PIN_CTL_TEST("Front Pin Mode", 0x14),
2466         PIN_CTL_TEST("Surround Pin Mode", 0x15),
2467         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
2468         PIN_CTL_TEST("Side Pin Mode", 0x17),
2469         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
2470         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
2471         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
2472         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
2473         PIN_SRC_TEST("In-1 Pin Source", 0x18),
2474         PIN_SRC_TEST("In-2 Pin Source", 0x19),
2475         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
2476         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
2477         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
2478         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
2479         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
2480         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
2481         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
2482         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
2483         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
2484         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
2485         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
2486         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
2487         {
2488                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2489                 .name = "Channel Mode",
2490                 .info = alc_ch_mode_info,
2491                 .get = alc_ch_mode_get,
2492                 .put = alc_ch_mode_put,
2493         },
2494         { } /* end */
2495 };
2496
2497 static struct hda_verb alc880_test_init_verbs[] = {
2498         /* Unmute inputs of 0x0c - 0x0f */
2499         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2500         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2501         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2502         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2503         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2504         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2505         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2506         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2507         /* Vol output for 0x0c-0x0f */
2508         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2509         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2510         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2511         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2512         /* Set output pins 0x14-0x17 */
2513         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2514         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2515         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2516         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2517         /* Unmute output pins 0x14-0x17 */
2518         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2519         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2520         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2521         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2522         /* Set input pins 0x18-0x1c */
2523         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2524         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2525         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2526         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2527         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2528         /* Mute input pins 0x18-0x1b */
2529         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2530         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2531         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2532         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2533         /* ADC set up */
2534         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2535         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2536         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2537         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2538         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2539         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2540         /* Analog input/passthru */
2541         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2542         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2543         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2544         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2545         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2546         { }
2547 };
2548 #endif
2549
2550 /*
2551  */
2552
2553 static const char *alc880_models[ALC880_MODEL_LAST] = {
2554         [ALC880_3ST]            = "3stack",
2555         [ALC880_TCL_S700]       = "tcl",
2556         [ALC880_3ST_DIG]        = "3stack-digout",
2557         [ALC880_CLEVO]          = "clevo",
2558         [ALC880_5ST]            = "5stack",
2559         [ALC880_5ST_DIG]        = "5stack-digout",
2560         [ALC880_W810]           = "w810",
2561         [ALC880_Z71V]           = "z71v",
2562         [ALC880_6ST]            = "6stack",
2563         [ALC880_6ST_DIG]        = "6stack-digout",
2564         [ALC880_ASUS]           = "asus",
2565         [ALC880_ASUS_W1V]       = "asus-w1v",
2566         [ALC880_ASUS_DIG]       = "asus-dig",
2567         [ALC880_ASUS_DIG2]      = "asus-dig2",
2568         [ALC880_UNIWILL_DIG]    = "uniwill",
2569         [ALC880_UNIWILL_P53]    = "uniwill-p53",
2570         [ALC880_FUJITSU]        = "fujitsu",
2571         [ALC880_F1734]          = "F1734",
2572         [ALC880_LG]             = "lg",
2573         [ALC880_LG_LW]          = "lg-lw",
2574 #ifdef CONFIG_SND_DEBUG
2575         [ALC880_TEST]           = "test",
2576 #endif
2577         [ALC880_AUTO]           = "auto",
2578 };
2579
2580 static struct snd_pci_quirk alc880_cfg_tbl[] = {
2581         /* Broken BIOS configuration */
2582         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG),
2583         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
2584
2585         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
2586         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
2587         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
2588         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
2589         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
2590         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
2591         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
2592         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
2593         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
2594
2595         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
2596         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
2597
2598         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
2599         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
2600         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
2601         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
2602         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
2603         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
2604         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
2605         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
2606         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
2607         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
2608         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS", ALC880_ASUS),
2609         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
2610         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
2611         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
2612         SND_PCI_QUIRK(0x1043, 0, "ASUS", ALC880_ASUS),
2613
2614         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
2615         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
2616         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
2617         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
2618         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
2619         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
2620         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
2621         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
2622         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
2623         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
2624         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
2625         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
2626         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
2627         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
2628         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
2629         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
2630         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
2631         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
2632
2633         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
2634         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
2635         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
2636         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
2637
2638         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
2639         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
2640         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
2641         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
2642
2643         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
2644         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
2645         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
2646         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
2647
2648         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
2649         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
2650         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
2651         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
2652         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
2653         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
2654         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
2655         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
2656         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
2657         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
2658         SND_PCI_QUIRK(0x8086, 0, "Intel mobo", ALC880_3ST),
2659
2660         {}
2661 };
2662
2663 /*
2664  * ALC880 codec presets
2665  */
2666 static struct alc_config_preset alc880_presets[] = {
2667         [ALC880_3ST] = {
2668                 .mixers = { alc880_three_stack_mixer },
2669                 .init_verbs = { alc880_volume_init_verbs,
2670                                 alc880_pin_3stack_init_verbs },
2671                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2672                 .dac_nids = alc880_dac_nids,
2673                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
2674                 .channel_mode = alc880_threestack_modes,
2675                 .need_dac_fix = 1,
2676                 .input_mux = &alc880_capture_source,
2677         },
2678         [ALC880_3ST_DIG] = {
2679                 .mixers = { alc880_three_stack_mixer },
2680                 .init_verbs = { alc880_volume_init_verbs,
2681                                 alc880_pin_3stack_init_verbs },
2682                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2683                 .dac_nids = alc880_dac_nids,
2684                 .dig_out_nid = ALC880_DIGOUT_NID,
2685                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
2686                 .channel_mode = alc880_threestack_modes,
2687                 .need_dac_fix = 1,
2688                 .input_mux = &alc880_capture_source,
2689         },
2690         [ALC880_TCL_S700] = {
2691                 .mixers = { alc880_tcl_s700_mixer },
2692                 .init_verbs = { alc880_volume_init_verbs,
2693                                 alc880_pin_tcl_S700_init_verbs,
2694                                 alc880_gpio2_init_verbs },
2695                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2696                 .dac_nids = alc880_dac_nids,
2697                 .hp_nid = 0x03,
2698                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
2699                 .channel_mode = alc880_2_jack_modes,
2700                 .input_mux = &alc880_capture_source,
2701         },
2702         [ALC880_5ST] = {
2703                 .mixers = { alc880_three_stack_mixer,
2704                             alc880_five_stack_mixer},
2705                 .init_verbs = { alc880_volume_init_verbs,
2706                                 alc880_pin_5stack_init_verbs },
2707                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2708                 .dac_nids = alc880_dac_nids,
2709                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
2710                 .channel_mode = alc880_fivestack_modes,
2711                 .input_mux = &alc880_capture_source,
2712         },
2713         [ALC880_5ST_DIG] = {
2714                 .mixers = { alc880_three_stack_mixer,
2715                             alc880_five_stack_mixer },
2716                 .init_verbs = { alc880_volume_init_verbs,
2717                                 alc880_pin_5stack_init_verbs },
2718                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2719                 .dac_nids = alc880_dac_nids,
2720                 .dig_out_nid = ALC880_DIGOUT_NID,
2721                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
2722                 .channel_mode = alc880_fivestack_modes,
2723                 .input_mux = &alc880_capture_source,
2724         },
2725         [ALC880_6ST] = {
2726                 .mixers = { alc880_six_stack_mixer },
2727                 .init_verbs = { alc880_volume_init_verbs,
2728                                 alc880_pin_6stack_init_verbs },
2729                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
2730                 .dac_nids = alc880_6st_dac_nids,
2731                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
2732                 .channel_mode = alc880_sixstack_modes,
2733                 .input_mux = &alc880_6stack_capture_source,
2734         },
2735         [ALC880_6ST_DIG] = {
2736                 .mixers = { alc880_six_stack_mixer },
2737                 .init_verbs = { alc880_volume_init_verbs,
2738                                 alc880_pin_6stack_init_verbs },
2739                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
2740                 .dac_nids = alc880_6st_dac_nids,
2741                 .dig_out_nid = ALC880_DIGOUT_NID,
2742                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
2743                 .channel_mode = alc880_sixstack_modes,
2744                 .input_mux = &alc880_6stack_capture_source,
2745         },
2746         [ALC880_W810] = {
2747                 .mixers = { alc880_w810_base_mixer },
2748                 .init_verbs = { alc880_volume_init_verbs,
2749                                 alc880_pin_w810_init_verbs,
2750                                 alc880_gpio2_init_verbs },
2751                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
2752                 .dac_nids = alc880_w810_dac_nids,
2753                 .dig_out_nid = ALC880_DIGOUT_NID,
2754                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
2755                 .channel_mode = alc880_w810_modes,
2756                 .input_mux = &alc880_capture_source,
2757         },
2758         [ALC880_Z71V] = {
2759                 .mixers = { alc880_z71v_mixer },
2760                 .init_verbs = { alc880_volume_init_verbs,
2761                                 alc880_pin_z71v_init_verbs },
2762                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
2763                 .dac_nids = alc880_z71v_dac_nids,
2764                 .dig_out_nid = ALC880_DIGOUT_NID,
2765                 .hp_nid = 0x03,
2766                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
2767                 .channel_mode = alc880_2_jack_modes,
2768                 .input_mux = &alc880_capture_source,
2769         },
2770         [ALC880_F1734] = {
2771                 .mixers = { alc880_f1734_mixer },
2772                 .init_verbs = { alc880_volume_init_verbs,
2773                                 alc880_pin_f1734_init_verbs },
2774                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
2775                 .dac_nids = alc880_f1734_dac_nids,
2776                 .hp_nid = 0x02,
2777                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
2778                 .channel_mode = alc880_2_jack_modes,
2779                 .input_mux = &alc880_capture_source,
2780         },
2781         [ALC880_ASUS] = {
2782                 .mixers = { alc880_asus_mixer },
2783                 .init_verbs = { alc880_volume_init_verbs,
2784                                 alc880_pin_asus_init_verbs,
2785                                 alc880_gpio1_init_verbs },
2786                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2787                 .dac_nids = alc880_asus_dac_nids,
2788                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
2789                 .channel_mode = alc880_asus_modes,
2790                 .need_dac_fix = 1,
2791                 .input_mux = &alc880_capture_source,
2792         },
2793         [ALC880_ASUS_DIG] = {
2794                 .mixers = { alc880_asus_mixer },
2795                 .init_verbs = { alc880_volume_init_verbs,
2796                                 alc880_pin_asus_init_verbs,
2797                                 alc880_gpio1_init_verbs },
2798                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2799                 .dac_nids = alc880_asus_dac_nids,
2800                 .dig_out_nid = ALC880_DIGOUT_NID,
2801                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
2802                 .channel_mode = alc880_asus_modes,
2803                 .need_dac_fix = 1,
2804                 .input_mux = &alc880_capture_source,
2805         },
2806         [ALC880_ASUS_DIG2] = {
2807                 .mixers = { alc880_asus_mixer },
2808                 .init_verbs = { alc880_volume_init_verbs,
2809                                 alc880_pin_asus_init_verbs,
2810                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
2811                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2812                 .dac_nids = alc880_asus_dac_nids,
2813                 .dig_out_nid = ALC880_DIGOUT_NID,
2814                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
2815                 .channel_mode = alc880_asus_modes,
2816                 .need_dac_fix = 1,
2817                 .input_mux = &alc880_capture_source,
2818         },
2819         [ALC880_ASUS_W1V] = {
2820                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
2821                 .init_verbs = { alc880_volume_init_verbs,
2822                                 alc880_pin_asus_init_verbs,
2823                                 alc880_gpio1_init_verbs },
2824                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2825                 .dac_nids = alc880_asus_dac_nids,
2826                 .dig_out_nid = ALC880_DIGOUT_NID,
2827                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
2828                 .channel_mode = alc880_asus_modes,
2829                 .need_dac_fix = 1,
2830                 .input_mux = &alc880_capture_source,
2831         },
2832         [ALC880_UNIWILL_DIG] = {
2833                 .mixers = { alc880_asus_mixer, alc880_pcbeep_mixer },
2834                 .init_verbs = { alc880_volume_init_verbs,
2835                                 alc880_pin_asus_init_verbs },
2836                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2837                 .dac_nids = alc880_asus_dac_nids,
2838                 .dig_out_nid = ALC880_DIGOUT_NID,
2839                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
2840                 .channel_mode = alc880_asus_modes,
2841                 .need_dac_fix = 1,
2842                 .input_mux = &alc880_capture_source,
2843         },
2844         [ALC880_UNIWILL] = {
2845                 .mixers = { alc880_uniwill_mixer },
2846                 .init_verbs = { alc880_volume_init_verbs,
2847                                 alc880_uniwill_init_verbs },
2848                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2849                 .dac_nids = alc880_asus_dac_nids,
2850                 .dig_out_nid = ALC880_DIGOUT_NID,
2851                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
2852                 .channel_mode = alc880_threestack_modes,
2853                 .need_dac_fix = 1,
2854                 .input_mux = &alc880_capture_source,
2855                 .unsol_event = alc880_uniwill_unsol_event,
2856                 .init_hook = alc880_uniwill_automute,
2857         },
2858         [ALC880_UNIWILL_P53] = {
2859                 .mixers = { alc880_uniwill_p53_mixer },
2860                 .init_verbs = { alc880_volume_init_verbs,
2861                                 alc880_uniwill_p53_init_verbs },
2862                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2863                 .dac_nids = alc880_asus_dac_nids,
2864                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
2865                 .channel_mode = alc880_threestack_modes,
2866                 .input_mux = &alc880_capture_source,
2867                 .unsol_event = alc880_uniwill_p53_unsol_event,
2868                 .init_hook = alc880_uniwill_p53_hp_automute,
2869         },
2870         [ALC880_FUJITSU] = {
2871                 .mixers = { alc880_fujitsu_mixer,
2872                             alc880_pcbeep_mixer, },
2873                 .init_verbs = { alc880_volume_init_verbs,
2874                                 alc880_uniwill_p53_init_verbs,
2875                                 alc880_beep_init_verbs },
2876                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2877                 .dac_nids = alc880_dac_nids,
2878                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
2879                 .channel_mode = alc880_2_jack_modes,
2880                 .input_mux = &alc880_capture_source,
2881                 .unsol_event = alc880_uniwill_p53_unsol_event,
2882                 .init_hook = alc880_uniwill_p53_hp_automute,
2883         },
2884         [ALC880_CLEVO] = {
2885                 .mixers = { alc880_three_stack_mixer },
2886                 .init_verbs = { alc880_volume_init_verbs,
2887                                 alc880_pin_clevo_init_verbs },
2888                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2889                 .dac_nids = alc880_dac_nids,
2890                 .hp_nid = 0x03,
2891                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
2892                 .channel_mode = alc880_threestack_modes,
2893                 .need_dac_fix = 1,
2894                 .input_mux = &alc880_capture_source,
2895         },
2896         [ALC880_LG] = {
2897                 .mixers = { alc880_lg_mixer },
2898                 .init_verbs = { alc880_volume_init_verbs,
2899                                 alc880_lg_init_verbs },
2900                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
2901                 .dac_nids = alc880_lg_dac_nids,
2902                 .dig_out_nid = ALC880_DIGOUT_NID,
2903                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
2904                 .channel_mode = alc880_lg_ch_modes,
2905                 .need_dac_fix = 1,
2906                 .input_mux = &alc880_lg_capture_source,
2907                 .unsol_event = alc880_lg_unsol_event,
2908                 .init_hook = alc880_lg_automute,
2909 #ifdef CONFIG_SND_HDA_POWER_SAVE
2910                 .loopbacks = alc880_lg_loopbacks,
2911 #endif
2912         },
2913         [ALC880_LG_LW] = {
2914                 .mixers = { alc880_lg_lw_mixer },
2915                 .init_verbs = { alc880_volume_init_verbs,
2916                                 alc880_lg_lw_init_verbs },
2917                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2918                 .dac_nids = alc880_dac_nids,
2919                 .dig_out_nid = ALC880_DIGOUT_NID,
2920                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
2921                 .channel_mode = alc880_lg_lw_modes,
2922                 .input_mux = &alc880_lg_lw_capture_source,
2923                 .unsol_event = alc880_lg_lw_unsol_event,
2924                 .init_hook = alc880_lg_lw_automute,
2925         },
2926 #ifdef CONFIG_SND_DEBUG
2927         [ALC880_TEST] = {
2928                 .mixers = { alc880_test_mixer },
2929                 .init_verbs = { alc880_test_init_verbs },
2930                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
2931                 .dac_nids = alc880_test_dac_nids,
2932                 .dig_out_nid = ALC880_DIGOUT_NID,
2933                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
2934                 .channel_mode = alc880_test_modes,
2935                 .input_mux = &alc880_test_capture_source,
2936         },
2937 #endif
2938 };
2939
2940 /*
2941  * Automatic parse of I/O pins from the BIOS configuration
2942  */
2943
2944 #define NUM_CONTROL_ALLOC       32
2945 #define NUM_VERB_ALLOC          32
2946
2947 enum {
2948         ALC_CTL_WIDGET_VOL,
2949         ALC_CTL_WIDGET_MUTE,
2950         ALC_CTL_BIND_MUTE,
2951 };
2952 static struct snd_kcontrol_new alc880_control_templates[] = {
2953         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2954         HDA_CODEC_MUTE(NULL, 0, 0, 0),
2955         HDA_BIND_MUTE(NULL, 0, 0, 0),
2956 };
2957
2958 /* add dynamic controls */
2959 static int add_control(struct alc_spec *spec, int type, const char *name,
2960                        unsigned long val)
2961 {
2962         struct snd_kcontrol_new *knew;
2963
2964         if (spec->num_kctl_used >= spec->num_kctl_alloc) {
2965                 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
2966
2967                 /* array + terminator */
2968                 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL);
2969                 if (!knew)
2970                         return -ENOMEM;
2971                 if (spec->kctl_alloc) {
2972                         memcpy(knew, spec->kctl_alloc,
2973                                sizeof(*knew) * spec->num_kctl_alloc);
2974                         kfree(spec->kctl_alloc);
2975                 }
2976                 spec->kctl_alloc = knew;
2977                 spec->num_kctl_alloc = num;
2978         }
2979
2980         knew = &spec->kctl_alloc[spec->num_kctl_used];
2981         *knew = alc880_control_templates[type];
2982         knew->name = kstrdup(name, GFP_KERNEL);
2983         if (!knew->name)
2984                 return -ENOMEM;
2985         knew->private_value = val;
2986         spec->num_kctl_used++;
2987         return 0;
2988 }
2989
2990 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
2991 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
2992 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
2993 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
2994 #define alc880_is_input_pin(nid)        ((nid) >= 0x18)
2995 #define alc880_input_pin_idx(nid)       ((nid) - 0x18)
2996 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
2997 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
2998 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
2999 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
3000 #define ALC880_PIN_CD_NID               0x1c
3001
3002 /* fill in the dac_nids table from the parsed pin configuration */
3003 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
3004                                      const struct auto_pin_cfg *cfg)
3005 {
3006         hda_nid_t nid;
3007         int assigned[4];
3008         int i, j;
3009
3010         memset(assigned, 0, sizeof(assigned));
3011         spec->multiout.dac_nids = spec->private_dac_nids;
3012
3013         /* check the pins hardwired to audio widget */
3014         for (i = 0; i < cfg->line_outs; i++) {
3015                 nid = cfg->line_out_pins[i];
3016                 if (alc880_is_fixed_pin(nid)) {
3017                         int idx = alc880_fixed_pin_idx(nid);
3018                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
3019                         assigned[idx] = 1;
3020                 }
3021         }
3022         /* left pins can be connect to any audio widget */
3023         for (i = 0; i < cfg->line_outs; i++) {
3024                 nid = cfg->line_out_pins[i];
3025                 if (alc880_is_fixed_pin(nid))
3026                         continue;
3027                 /* search for an empty channel */
3028                 for (j = 0; j < cfg->line_outs; j++) {
3029                         if (!assigned[j]) {
3030                                 spec->multiout.dac_nids[i] =
3031                                         alc880_idx_to_dac(j);
3032                                 assigned[j] = 1;
3033                                 break;
3034                         }
3035                 }
3036         }
3037         spec->multiout.num_dacs = cfg->line_outs;
3038         return 0;
3039 }
3040
3041 /* add playback controls from the parsed DAC table */
3042 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
3043                                              const struct auto_pin_cfg *cfg)
3044 {
3045         char name[32];
3046         static const char *chname[4] = {
3047                 "Front", "Surround", NULL /*CLFE*/, "Side"
3048         };
3049         hda_nid_t nid;
3050         int i, err;
3051
3052         for (i = 0; i < cfg->line_outs; i++) {
3053                 if (!spec->multiout.dac_nids[i])
3054                         continue;
3055                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
3056                 if (i == 2) {
3057                         /* Center/LFE */
3058                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3059                                           "Center Playback Volume",
3060                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
3061                                                               HDA_OUTPUT));
3062                         if (err < 0)
3063                                 return err;
3064                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3065                                           "LFE Playback Volume",
3066                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
3067                                                               HDA_OUTPUT));
3068                         if (err < 0)
3069                                 return err;
3070                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3071                                           "Center Playback Switch",
3072                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
3073                                                               HDA_INPUT));
3074                         if (err < 0)
3075                                 return err;
3076                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3077                                           "LFE Playback Switch",
3078                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
3079                                                               HDA_INPUT));
3080                         if (err < 0)
3081                                 return err;
3082                 } else {
3083                         sprintf(name, "%s Playback Volume", chname[i]);
3084                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3085                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3086                                                               HDA_OUTPUT));
3087                         if (err < 0)
3088                                 return err;
3089                         sprintf(name, "%s Playback Switch", chname[i]);
3090                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3091                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
3092                                                               HDA_INPUT));
3093                         if (err < 0)
3094                                 return err;
3095                 }
3096         }
3097         return 0;
3098 }
3099
3100 /* add playback controls for speaker and HP outputs */
3101 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
3102                                         const char *pfx)
3103 {
3104         hda_nid_t nid;
3105         int err;
3106         char name[32];
3107
3108         if (!pin)
3109                 return 0;
3110
3111         if (alc880_is_fixed_pin(pin)) {
3112                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
3113                 /* specify the DAC as the extra output */
3114                 if (!spec->multiout.hp_nid)
3115                         spec->multiout.hp_nid = nid;
3116                 else
3117                         spec->multiout.extra_out_nid[0] = nid;
3118                 /* control HP volume/switch on the output mixer amp */
3119                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
3120                 sprintf(name, "%s Playback Volume", pfx);
3121                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3122                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3123                 if (err < 0)
3124                         return err;
3125                 sprintf(name, "%s Playback Switch", pfx);
3126                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3127                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
3128                 if (err < 0)
3129                         return err;
3130         } else if (alc880_is_multi_pin(pin)) {
3131                 /* set manual connection */
3132                 /* we have only a switch on HP-out PIN */
3133                 sprintf(name, "%s Playback Switch", pfx);
3134                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3135                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3136                 if (err < 0)
3137                         return err;
3138         }
3139         return 0;
3140 }
3141
3142 /* create input playback/capture controls for the given pin */
3143 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
3144                             const char *ctlname,
3145                             int idx, hda_nid_t mix_nid)
3146 {
3147         char name[32];
3148         int err;
3149
3150         sprintf(name, "%s Playback Volume", ctlname);
3151         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3152                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3153         if (err < 0)
3154                 return err;
3155         sprintf(name, "%s Playback Switch", ctlname);
3156         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3157                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3158         if (err < 0)
3159                 return err;
3160         return 0;
3161 }
3162
3163 /* create playback/capture controls for input pins */
3164 static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
3165                                                 const struct auto_pin_cfg *cfg)
3166 {
3167         struct hda_input_mux *imux = &spec->private_imux;
3168         int i, err, idx;
3169
3170         for (i = 0; i < AUTO_PIN_LAST; i++) {
3171                 if (alc880_is_input_pin(cfg->input_pins[i])) {
3172                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
3173                         err = new_analog_input(spec, cfg->input_pins[i],
3174                                                auto_pin_cfg_labels[i],
3175                                                idx, 0x0b);
3176                         if (err < 0)
3177                                 return err;
3178                         imux->items[imux->num_items].label =
3179                                 auto_pin_cfg_labels[i];
3180                         imux->items[imux->num_items].index =
3181                                 alc880_input_pin_idx(cfg->input_pins[i]);
3182                         imux->num_items++;
3183                 }
3184         }
3185         return 0;
3186 }
3187
3188 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
3189                                               hda_nid_t nid, int pin_type,
3190                                               int dac_idx)
3191 {
3192         /* set as output */
3193         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3194                             pin_type);
3195         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3196                             AMP_OUT_UNMUTE);
3197         /* need the manual connection? */
3198         if (alc880_is_multi_pin(nid)) {
3199                 struct alc_spec *spec = codec->spec;
3200                 int idx = alc880_multi_pin_idx(nid);
3201                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
3202                                     AC_VERB_SET_CONNECT_SEL,
3203                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
3204         }
3205 }
3206
3207 static int get_pin_type(int line_out_type)
3208 {
3209         if (line_out_type == AUTO_PIN_HP_OUT)
3210                 return PIN_HP;
3211         else
3212                 return PIN_OUT;
3213 }
3214
3215 static void alc880_auto_init_multi_out(struct hda_codec *codec)
3216 {
3217         struct alc_spec *spec = codec->spec;
3218         int i;
3219         
3220         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
3221         for (i = 0; i < spec->autocfg.line_outs; i++) {
3222                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3223                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3224                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
3225         }
3226 }
3227
3228 static void alc880_auto_init_extra_out(struct hda_codec *codec)
3229 {
3230         struct alc_spec *spec = codec->spec;
3231         hda_nid_t pin;
3232
3233         pin = spec->autocfg.speaker_pins[0];
3234         if (pin) /* connect to front */
3235                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
3236         pin = spec->autocfg.hp_pins[0];
3237         if (pin) /* connect to front */
3238                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
3239 }
3240
3241 static void alc880_auto_init_analog_input(struct hda_codec *codec)
3242 {
3243         struct alc_spec *spec = codec->spec;
3244         int i;
3245
3246         for (i = 0; i < AUTO_PIN_LAST; i++) {
3247                 hda_nid_t nid = spec->autocfg.input_pins[i];
3248                 if (alc880_is_input_pin(nid)) {
3249                         snd_hda_codec_write(codec, nid, 0,
3250                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
3251                                             i <= AUTO_PIN_FRONT_MIC ?
3252                                             PIN_VREF80 : PIN_IN);
3253                         if (nid != ALC880_PIN_CD_NID)
3254                                 snd_hda_codec_write(codec, nid, 0,
3255                                                     AC_VERB_SET_AMP_GAIN_MUTE,
3256                                                     AMP_OUT_MUTE);
3257                 }
3258         }
3259 }
3260
3261 /* parse the BIOS configuration and set up the alc_spec */
3262 /* return 1 if successful, 0 if the proper config is not found,
3263  * or a negative error code
3264  */
3265 static int alc880_parse_auto_config(struct hda_codec *codec)
3266 {
3267         struct alc_spec *spec = codec->spec;
3268         int err;
3269         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
3270
3271         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
3272                                            alc880_ignore);
3273         if (err < 0)
3274                 return err;
3275         if (!spec->autocfg.line_outs)
3276                 return 0; /* can't find valid BIOS pin config */
3277
3278         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
3279         if (err < 0)
3280                 return err;
3281         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
3282         if (err < 0)
3283                 return err;
3284         err = alc880_auto_create_extra_out(spec,
3285                                            spec->autocfg.speaker_pins[0],
3286                                            "Speaker");
3287         if (err < 0)
3288                 return err;
3289         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
3290                                            "Headphone");
3291         if (err < 0)
3292                 return err;
3293         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
3294         if (err < 0)
3295                 return err;
3296
3297         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3298
3299         if (spec->autocfg.dig_out_pin)
3300                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
3301         if (spec->autocfg.dig_in_pin)
3302                 spec->dig_in_nid = ALC880_DIGIN_NID;
3303
3304         if (spec->kctl_alloc)
3305                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
3306
3307         spec->init_verbs[spec->num_init_verbs++] = alc880_volume_init_verbs;
3308
3309         spec->num_mux_defs = 1;
3310         spec->input_mux = &spec->private_imux;
3311
3312         return 1;
3313 }
3314
3315 /* additional initialization for auto-configuration model */
3316 static void alc880_auto_init(struct hda_codec *codec)
3317 {
3318         alc880_auto_init_multi_out(codec);
3319         alc880_auto_init_extra_out(codec);
3320         alc880_auto_init_analog_input(codec);
3321 }
3322
3323 /*
3324  * OK, here we have finally the patch for ALC880
3325  */
3326
3327 static int patch_alc880(struct hda_codec *codec)
3328 {
3329         struct alc_spec *spec;
3330         int board_config;
3331         int err;
3332
3333         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3334         if (spec == NULL)
3335                 return -ENOMEM;
3336
3337         codec->spec = spec;
3338
3339         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
3340                                                   alc880_models,
3341                                                   alc880_cfg_tbl);
3342         if (board_config < 0) {
3343                 printk(KERN_INFO "hda_codec: Unknown model for ALC880, "
3344                        "trying auto-probe from BIOS...\n");
3345                 board_config = ALC880_AUTO;
3346         }
3347
3348         if (board_config == ALC880_AUTO) {
3349                 /* automatic parse from the BIOS config */
3350                 err = alc880_parse_auto_config(codec);
3351                 if (err < 0) {
3352                         alc_free(codec);
3353                         return err;
3354                 } else if (!err) {
3355                         printk(KERN_INFO
3356                                "hda_codec: Cannot set up configuration "
3357                                "from BIOS.  Using 3-stack mode...\n");
3358                         board_config = ALC880_3ST;
3359                 }
3360         }
3361
3362         if (board_config != ALC880_AUTO)
3363                 setup_preset(spec, &alc880_presets[board_config]);
3364
3365         spec->stream_name_analog = "ALC880 Analog";
3366         spec->stream_analog_playback = &alc880_pcm_analog_playback;
3367         spec->stream_analog_capture = &alc880_pcm_analog_capture;
3368
3369         spec->stream_name_digital = "ALC880 Digital";
3370         spec->stream_digital_playback = &alc880_pcm_digital_playback;
3371         spec->stream_digital_capture = &alc880_pcm_digital_capture;
3372
3373         if (!spec->adc_nids && spec->input_mux) {
3374                 /* check whether NID 0x07 is valid */
3375                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
3376                 /* get type */
3377                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
3378                 if (wcap != AC_WID_AUD_IN) {
3379                         spec->adc_nids = alc880_adc_nids_alt;
3380                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
3381                         spec->mixers[spec->num_mixers] =
3382                                 alc880_capture_alt_mixer;
3383                         spec->num_mixers++;
3384                 } else {
3385                         spec->adc_nids = alc880_adc_nids;
3386                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
3387                         spec->mixers[spec->num_mixers] = alc880_capture_mixer;
3388                         spec->num_mixers++;
3389                 }
3390         }
3391
3392         codec->patch_ops = alc_patch_ops;
3393         if (board_config == ALC880_AUTO)
3394                 spec->init_hook = alc880_auto_init;
3395 #ifdef CONFIG_SND_HDA_POWER_SAVE
3396         if (!spec->loopback.amplist)
3397                 spec->loopback.amplist = alc880_loopbacks;
3398 #endif
3399
3400         return 0;
3401 }
3402
3403
3404 /*
3405  * ALC260 support
3406  */
3407
3408 static hda_nid_t alc260_dac_nids[1] = {
3409         /* front */
3410         0x02,
3411 };
3412
3413 static hda_nid_t alc260_adc_nids[1] = {
3414         /* ADC0 */
3415         0x04,
3416 };
3417
3418 static hda_nid_t alc260_adc_nids_alt[1] = {
3419         /* ADC1 */
3420         0x05,
3421 };
3422
3423 static hda_nid_t alc260_hp_adc_nids[2] = {
3424         /* ADC1, 0 */
3425         0x05, 0x04
3426 };
3427
3428 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
3429  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
3430  */
3431 static hda_nid_t alc260_dual_adc_nids[2] = {
3432         /* ADC0, ADC1 */
3433         0x04, 0x05
3434 };
3435
3436 #define ALC260_DIGOUT_NID       0x03
3437 #define ALC260_DIGIN_NID        0x06
3438
3439 static struct hda_input_mux alc260_capture_source = {
3440         .num_items = 4,
3441         .items = {
3442                 { "Mic", 0x0 },
3443                 { "Front Mic", 0x1 },
3444                 { "Line", 0x2 },
3445                 { "CD", 0x4 },
3446         },
3447 };
3448
3449 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
3450  * headphone jack and the internal CD lines since these are the only pins at
3451  * which audio can appear.  For flexibility, also allow the option of
3452  * recording the mixer output on the second ADC (ADC0 doesn't have a
3453  * connection to the mixer output).
3454  */
3455 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
3456         {
3457                 .num_items = 3,
3458                 .items = {
3459                         { "Mic/Line", 0x0 },
3460                         { "CD", 0x4 },
3461                         { "Headphone", 0x2 },
3462                 },
3463         },
3464         {
3465                 .num_items = 4,
3466                 .items = {
3467                         { "Mic/Line", 0x0 },
3468                         { "CD", 0x4 },
3469                         { "Headphone", 0x2 },
3470                         { "Mixer", 0x5 },
3471                 },
3472         },
3473
3474 };
3475
3476 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
3477  * the Fujitsu S702x, but jacks are marked differently.
3478  */
3479 static struct hda_input_mux alc260_acer_capture_sources[2] = {
3480         {
3481                 .num_items = 4,
3482                 .items = {
3483                         { "Mic", 0x0 },
3484                         { "Line", 0x2 },
3485                         { "CD", 0x4 },
3486                         { "Headphone", 0x5 },
3487                 },
3488         },
3489         {
3490                 .num_items = 5,
3491                 .items = {
3492                         { "Mic", 0x0 },
3493                         { "Line", 0x2 },
3494                         { "CD", 0x4 },
3495                         { "Headphone", 0x6 },
3496                         { "Mixer", 0x5 },
3497                 },
3498         },
3499 };
3500 /*
3501  * This is just place-holder, so there's something for alc_build_pcms to look
3502  * at when it calculates the maximum number of channels. ALC260 has no mixer
3503  * element which allows changing the channel mode, so the verb list is
3504  * never used.
3505  */
3506 static struct hda_channel_mode alc260_modes[1] = {
3507         { 2, NULL },
3508 };
3509
3510
3511 /* Mixer combinations
3512  *
3513  * basic: base_output + input + pc_beep + capture
3514  * HP: base_output + input + capture_alt
3515  * HP_3013: hp_3013 + input + capture
3516  * fujitsu: fujitsu + capture
3517  * acer: acer + capture
3518  */
3519
3520 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
3521         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3522         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
3523         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
3524         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
3525         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
3526         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
3527         { } /* end */
3528 };
3529
3530 static struct snd_kcontrol_new alc260_input_mixer[] = {
3531         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3532         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3533         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
3534         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
3535         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
3536         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
3537         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
3538         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
3539         { } /* end */
3540 };
3541
3542 static struct snd_kcontrol_new alc260_pc_beep_mixer[] = {
3543         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT),
3544         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT),
3545         { } /* end */
3546 };
3547
3548 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
3549         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
3550         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
3551         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
3552         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
3553         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3554         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
3555         HDA_CODEC_VOLUME_MONO("iSpeaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
3556         HDA_CODEC_MUTE_MONO("iSpeaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
3557         { } /* end */
3558 };
3559
3560 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12, 
3561  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
3562  */
3563 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
3564         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3565         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
3566         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
3567         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3568         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3569         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
3570         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
3571         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
3572         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
3573         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
3574         HDA_CODEC_VOLUME("Internal Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
3575         HDA_BIND_MUTE("Internal Speaker Playback Switch", 0x09, 2, HDA_INPUT),
3576         { } /* end */
3577 };
3578
3579 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
3580  * versions of the ALC260 don't act on requests to enable mic bias from NID
3581  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
3582  * datasheet doesn't mention this restriction.  At this stage it's not clear
3583  * whether this behaviour is intentional or is a hardware bug in chip
3584  * revisions available in early 2006.  Therefore for now allow the
3585  * "Headphone Jack Mode" control to span all choices, but if it turns out
3586  * that the lack of mic bias for this NID is intentional we could change the
3587  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
3588  *
3589  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
3590  * don't appear to make the mic bias available from the "line" jack, even
3591  * though the NID used for this jack (0x14) can supply it.  The theory is
3592  * that perhaps Acer have included blocking capacitors between the ALC260
3593  * and the output jack.  If this turns out to be the case for all such
3594  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
3595  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
3596  *
3597  * The C20x Tablet series have a mono internal speaker which is controlled
3598  * via the chip's Mono sum widget and pin complex, so include the necessary
3599  * controls for such models.  On models without a "mono speaker" the control
3600  * won't do anything.
3601  */
3602 static struct snd_kcontrol_new alc260_acer_mixer[] = {
3603         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3604         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
3605         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
3606         HDA_CODEC_VOLUME_MONO("Mono Speaker Playback Volume", 0x0a, 1, 0x0,
3607                               HDA_OUTPUT),
3608         HDA_BIND_MUTE_MONO("Mono Speaker Playback Switch", 0x0a, 1, 2,
3609                            HDA_INPUT),
3610         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3611         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3612         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
3613         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
3614         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
3615         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
3616         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
3617         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
3618         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
3619         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
3620         { } /* end */
3621 };
3622
3623 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
3624  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
3625  */
3626 static struct snd_kcontrol_new alc260_will_mixer[] = {
3627         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3628         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
3629         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
3630         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
3631         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
3632         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
3633         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
3634         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
3635         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3636         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3637         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
3638         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
3639         { } /* end */
3640 };
3641
3642 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
3643  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
3644  */
3645 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
3646         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3647         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
3648         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
3649         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
3650         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
3651         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
3652         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
3653         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
3654         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
3655         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
3656         { } /* end */
3657 };
3658
3659 /* capture mixer elements */
3660 static struct snd_kcontrol_new alc260_capture_mixer[] = {
3661         HDA_CODEC_VOLUME("Capture Volume", 0x04, 0x0, HDA_INPUT),
3662         HDA_CODEC_MUTE("Capture Switch", 0x04, 0x0, HDA_INPUT),
3663         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x05, 0x0, HDA_INPUT),
3664         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x05, 0x0, HDA_INPUT),
3665         {
3666                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3667                 /* The multiple "Capture Source" controls confuse alsamixer
3668                  * So call somewhat different..
3669                  * FIXME: the controls appear in the "playback" view!
3670                  */
3671                 /* .name = "Capture Source", */
3672                 .name = "Input Source",
3673                 .count = 2,
3674                 .info = alc_mux_enum_info,
3675                 .get = alc_mux_enum_get,
3676                 .put = alc_mux_enum_put,
3677         },
3678         { } /* end */
3679 };
3680
3681 static struct snd_kcontrol_new alc260_capture_alt_mixer[] = {
3682         HDA_CODEC_VOLUME("Capture Volume", 0x05, 0x0, HDA_INPUT),
3683         HDA_CODEC_MUTE("Capture Switch", 0x05, 0x0, HDA_INPUT),
3684         {
3685                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3686                 /* The multiple "Capture Source" controls confuse alsamixer
3687                  * So call somewhat different..
3688                  * FIXME: the controls appear in the "playback" view!
3689                  */
3690                 /* .name = "Capture Source", */
3691                 .name = "Input Source",
3692                 .count = 1,
3693                 .info = alc_mux_enum_info,
3694                 .get = alc_mux_enum_get,
3695                 .put = alc_mux_enum_put,
3696         },
3697         { } /* end */
3698 };
3699
3700 /*
3701  * initialization verbs
3702  */
3703 static struct hda_verb alc260_init_verbs[] = {
3704         /* Line In pin widget for input */
3705         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3706         /* CD pin widget for input */
3707         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3708         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3709         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3710         /* Mic2 (front panel) pin widget for input and vref at 80% */
3711         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3712         /* LINE-2 is used for line-out in rear */
3713         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3714         /* select line-out */
3715         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
3716         /* LINE-OUT pin */
3717         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3718         /* enable HP */
3719         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3720         /* enable Mono */
3721         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3722         /* mute capture amp left and right */
3723         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3724         /* set connection select to line in (default select for this ADC) */
3725         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
3726         /* mute capture amp left and right */
3727         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3728         /* set connection select to line in (default select for this ADC) */
3729         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
3730         /* set vol=0 Line-Out mixer amp left and right */
3731         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3732         /* unmute pin widget amp left and right (no gain on this amp) */
3733         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3734         /* set vol=0 HP mixer amp left and right */
3735         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3736         /* unmute pin widget amp left and right (no gain on this amp) */
3737         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3738         /* set vol=0 Mono mixer amp left and right */
3739         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3740         /* unmute pin widget amp left and right (no gain on this amp) */
3741         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3742         /* unmute LINE-2 out pin */
3743         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3744         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
3745          * Line In 2 = 0x03
3746          */
3747         /* mute analog inputs */
3748         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3749         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3750         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3751         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3752         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3753         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
3754         /* mute Front out path */
3755         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3756         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3757         /* mute Headphone out path */
3758         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3759         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3760         /* mute Mono out path */
3761         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3762         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3763         { }
3764 };
3765
3766 #if 0 /* should be identical with alc260_init_verbs? */
3767 static struct hda_verb alc260_hp_init_verbs[] = {
3768         /* Headphone and output */
3769         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
3770         /* mono output */
3771         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3772         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3773         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
3774         /* Mic2 (front panel) pin widget for input and vref at 80% */
3775         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
3776         /* Line In pin widget for input */
3777         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3778         /* Line-2 pin widget for output */
3779         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3780         /* CD pin widget for input */
3781         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3782         /* unmute amp left and right */
3783         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
3784         /* set connection select to line in (default select for this ADC) */
3785         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
3786         /* unmute Line-Out mixer amp left and right (volume = 0) */
3787         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
3788         /* mute pin widget amp left and right (no gain on this amp) */
3789         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
3790         /* unmute HP mixer amp left and right (volume = 0) */
3791         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
3792         /* mute pin widget amp left and right (no gain on this amp) */
3793         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
3794         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
3795          * Line In 2 = 0x03
3796          */
3797         /* mute analog inputs */
3798         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3799         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3800         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3801         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3802         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3803         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
3804         /* Unmute Front out path */
3805         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3806         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3807         /* Unmute Headphone out path */
3808         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3809         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3810         /* Unmute Mono out path */
3811         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3812         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3813         { }
3814 };
3815 #endif
3816
3817 static struct hda_verb alc260_hp_3013_init_verbs[] = {
3818         /* Line out and output */
3819         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3820         /* mono output */
3821         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3822         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3823         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
3824         /* Mic2 (front panel) pin widget for input and vref at 80% */
3825         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
3826         /* Line In pin widget for input */
3827         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3828         /* Headphone pin widget for output */
3829         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
3830         /* CD pin widget for input */
3831         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3832         /* unmute amp left and right */
3833         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
3834         /* set connection select to line in (default select for this ADC) */
3835         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
3836         /* unmute Line-Out mixer amp left and right (volume = 0) */
3837         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
3838         /* mute pin widget amp left and right (no gain on this amp) */
3839         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
3840         /* unmute HP mixer amp left and right (volume = 0) */
3841         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
3842         /* mute pin widget amp left and right (no gain on this amp) */
3843         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
3844         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
3845          * Line In 2 = 0x03
3846          */
3847         /* mute analog inputs */
3848         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3849         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3850         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3851         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3852         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3853         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
3854         /* Unmute Front out path */
3855         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3856         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3857         /* Unmute Headphone out path */
3858         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3859         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3860         /* Unmute Mono out path */
3861         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3862         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3863         { }
3864 };
3865
3866 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
3867  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
3868  * audio = 0x16, internal speaker = 0x10.
3869  */
3870 static struct hda_verb alc260_fujitsu_init_verbs[] = {
3871         /* Disable all GPIOs */
3872         {0x01, AC_VERB_SET_GPIO_MASK, 0},
3873         /* Internal speaker is connected to headphone pin */
3874         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3875         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
3876         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3877         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
3878         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3879         /* Ensure all other unused pins are disabled and muted. */
3880         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3881         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3882         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3883         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3884         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3885         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3886         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3887         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3888
3889         /* Disable digital (SPDIF) pins */
3890         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
3891         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
3892
3893         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus 
3894          * when acting as an output.
3895          */
3896         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
3897
3898         /* Start with output sum widgets muted and their output gains at min */
3899         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3900         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3901         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3902         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3903         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3904         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3905         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3906         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3907         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3908
3909         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
3910         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3911         /* Unmute Line1 pin widget output buffer since it starts as an output.
3912          * If the pin mode is changed by the user the pin mode control will
3913          * take care of enabling the pin's input/output buffers as needed.
3914          * Therefore there's no need to enable the input buffer at this
3915          * stage.
3916          */
3917         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3918         /* Unmute input buffer of pin widget used for Line-in (no equiv 
3919          * mixer ctrl)
3920          */
3921         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3922
3923         /* Mute capture amp left and right */
3924         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3925         /* Set ADC connection select to match default mixer setting - line 
3926          * in (on mic1 pin)
3927          */
3928         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
3929
3930         /* Do the same for the second ADC: mute capture input amp and
3931          * set ADC connection to line in (on mic1 pin)
3932          */
3933         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3934         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
3935
3936         /* Mute all inputs to mixer widget (even unconnected ones) */
3937         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
3938         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
3939         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
3940         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
3941         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
3942         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
3943         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
3944         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
3945
3946         { }
3947 };
3948
3949 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
3950  * similar laptops (adapted from Fujitsu init verbs).
3951  */
3952 static struct hda_verb alc260_acer_init_verbs[] = {
3953         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
3954          * the headphone jack.  Turn this on and rely on the standard mute
3955          * methods whenever the user wants to turn these outputs off.
3956          */
3957         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
3958         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
3959         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
3960         /* Internal speaker/Headphone jack is connected to Line-out pin */
3961         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3962         /* Internal microphone/Mic jack is connected to Mic1 pin */
3963         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
3964         /* Line In jack is connected to Line1 pin */
3965         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3966         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
3967         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3968         /* Ensure all other unused pins are disabled and muted. */
3969         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3970         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3971         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3972         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3973         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3974         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3975         /* Disable digital (SPDIF) pins */
3976         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
3977         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
3978
3979         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum 
3980          * bus when acting as outputs.
3981          */
3982         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
3983         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
3984
3985         /* Start with output sum widgets muted and their output gains at min */
3986         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3987         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3988         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3989         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3990         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3991         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3992         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3993         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3994         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3995
3996         /* Unmute Line-out pin widget amp left and right
3997          * (no equiv mixer ctrl)
3998          */
3999         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4000         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
4001         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4002         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
4003          * inputs. If the pin mode is changed by the user the pin mode control
4004          * will take care of enabling the pin's input/output buffers as needed.
4005          * Therefore there's no need to enable the input buffer at this
4006          * stage.
4007          */
4008         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4009         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4010
4011         /* Mute capture amp left and right */
4012         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4013         /* Set ADC connection select to match default mixer setting - mic
4014          * (on mic1 pin)
4015          */
4016         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4017
4018         /* Do similar with the second ADC: mute capture input amp and
4019          * set ADC connection to mic to match ALSA's default state.
4020          */
4021         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4022         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4023
4024         /* Mute all inputs to mixer widget (even unconnected ones) */
4025         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4026         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4027         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4028         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4029         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4030         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4031         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4032         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4033
4034         { }
4035 };
4036
4037 static struct hda_verb alc260_will_verbs[] = {
4038         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4039         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
4040         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
4041         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4042         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
4043         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
4044         {}
4045 };
4046
4047 static struct hda_verb alc260_replacer_672v_verbs[] = {
4048         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4049         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
4050         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
4051
4052         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
4053         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4054         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4055
4056         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4057         {}
4058 };
4059
4060 /* toggle speaker-output according to the hp-jack state */
4061 static void alc260_replacer_672v_automute(struct hda_codec *codec)
4062 {
4063         unsigned int present;
4064
4065         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
4066         present = snd_hda_codec_read(codec, 0x0f, 0,
4067                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
4068         if (present) {
4069                 snd_hda_codec_write_cache(codec, 0x01, 0,
4070                                           AC_VERB_SET_GPIO_DATA, 1);
4071                 snd_hda_codec_write_cache(codec, 0x0f, 0,
4072                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4073                                           PIN_HP);
4074         } else {
4075                 snd_hda_codec_write_cache(codec, 0x01, 0,
4076                                           AC_VERB_SET_GPIO_DATA, 0);
4077                 snd_hda_codec_write_cache(codec, 0x0f, 0,
4078                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4079                                           PIN_OUT);
4080         }
4081 }
4082
4083 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
4084                                        unsigned int res)
4085 {
4086         if ((res >> 26) == ALC880_HP_EVENT)
4087                 alc260_replacer_672v_automute(codec);
4088 }
4089
4090 /* Test configuration for debugging, modelled after the ALC880 test
4091  * configuration.
4092  */
4093 #ifdef CONFIG_SND_DEBUG
4094 static hda_nid_t alc260_test_dac_nids[1] = {
4095         0x02,
4096 };
4097 static hda_nid_t alc260_test_adc_nids[2] = {
4098         0x04, 0x05,
4099 };
4100 /* For testing the ALC260, each input MUX needs its own definition since
4101  * the signal assignments are different.  This assumes that the first ADC 
4102  * is NID 0x04.
4103  */
4104 static struct hda_input_mux alc260_test_capture_sources[2] = {
4105         {
4106                 .num_items = 7,
4107                 .items = {
4108                         { "MIC1 pin", 0x0 },
4109                         { "MIC2 pin", 0x1 },
4110                         { "LINE1 pin", 0x2 },
4111                         { "LINE2 pin", 0x3 },
4112                         { "CD pin", 0x4 },
4113                         { "LINE-OUT pin", 0x5 },
4114                         { "HP-OUT pin", 0x6 },
4115                 },
4116         },
4117         {
4118                 .num_items = 8,
4119                 .items = {
4120                         { "MIC1 pin", 0x0 },
4121                         { "MIC2 pin", 0x1 },
4122                         { "LINE1 pin", 0x2 },
4123                         { "LINE2 pin", 0x3 },
4124                         { "CD pin", 0x4 },
4125                         { "Mixer", 0x5 },
4126                         { "LINE-OUT pin", 0x6 },
4127                         { "HP-OUT pin", 0x7 },
4128                 },
4129         },
4130 };
4131 static struct snd_kcontrol_new alc260_test_mixer[] = {
4132         /* Output driver widgets */
4133         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4134         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4135         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4136         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
4137         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4138         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
4139
4140         /* Modes for retasking pin widgets
4141          * Note: the ALC260 doesn't seem to act on requests to enable mic
4142          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
4143          * mention this restriction.  At this stage it's not clear whether
4144          * this behaviour is intentional or is a hardware bug in chip
4145          * revisions available at least up until early 2006.  Therefore for
4146          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
4147          * choices, but if it turns out that the lack of mic bias for these
4148          * NIDs is intentional we could change their modes from
4149          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4150          */
4151         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
4152         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
4153         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
4154         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
4155         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
4156         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
4157
4158         /* Loopback mixer controls */
4159         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
4160         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
4161         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
4162         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
4163         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
4164         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
4165         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
4166         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
4167         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4168         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4169         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4170         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4171         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
4172         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
4173         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
4174         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
4175
4176         /* Controls for GPIO pins, assuming they are configured as outputs */
4177         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
4178         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
4179         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
4180         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
4181
4182         /* Switches to allow the digital IO pins to be enabled.  The datasheet
4183          * is ambigious as to which NID is which; testing on laptops which
4184          * make this output available should provide clarification. 
4185          */
4186         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
4187         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
4188
4189         { } /* end */
4190 };
4191 static struct hda_verb alc260_test_init_verbs[] = {
4192         /* Enable all GPIOs as outputs with an initial value of 0 */
4193         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
4194         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4195         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
4196
4197         /* Enable retasking pins as output, initially without power amp */
4198         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4199         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4200         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4201         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4202         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4203         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4204
4205         /* Disable digital (SPDIF) pins initially, but users can enable
4206          * them via a mixer switch.  In the case of SPDIF-out, this initverb
4207          * payload also sets the generation to 0, output to be in "consumer"
4208          * PCM format, copyright asserted, no pre-emphasis and no validity
4209          * control.
4210          */
4211         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4212         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4213
4214         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the 
4215          * OUT1 sum bus when acting as an output.
4216          */
4217         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
4218         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
4219         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4220         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
4221
4222         /* Start with output sum widgets muted and their output gains at min */
4223         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4224         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4225         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4226         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4227         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4228         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4229         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4230         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4231         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4232
4233         /* Unmute retasking pin widget output buffers since the default
4234          * state appears to be output.  As the pin mode is changed by the
4235          * user the pin mode control will take care of enabling the pin's
4236          * input/output buffers as needed.
4237          */
4238         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4239         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4240         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4241         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4242         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4243         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4244         /* Also unmute the mono-out pin widget */
4245         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4246
4247         /* Mute capture amp left and right */
4248         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4249         /* Set ADC connection select to match default mixer setting (mic1
4250          * pin)
4251          */
4252         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4253
4254         /* Do the same for the second ADC: mute capture input amp and
4255          * set ADC connection to mic1 pin
4256          */
4257         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4258         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4259
4260         /* Mute all inputs to mixer widget (even unconnected ones) */
4261         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4262         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4263         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4264         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4265         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4266         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4267         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4268         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4269
4270         { }
4271 };
4272 #endif
4273
4274 static struct hda_pcm_stream alc260_pcm_analog_playback = {
4275         .substreams = 1,
4276         .channels_min = 2,
4277         .channels_max = 2,
4278 };
4279
4280 static struct hda_pcm_stream alc260_pcm_analog_capture = {
4281         .substreams = 1,
4282         .channels_min = 2,
4283         .channels_max = 2,
4284 };
4285
4286 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
4287 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
4288
4289 /*
4290  * for BIOS auto-configuration
4291  */
4292
4293 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
4294                                         const char *pfx)
4295 {
4296         hda_nid_t nid_vol;
4297         unsigned long vol_val, sw_val;
4298         char name[32];
4299         int err;
4300
4301         if (nid >= 0x0f && nid < 0x11) {
4302                 nid_vol = nid - 0x7;
4303                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
4304                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
4305         } else if (nid == 0x11) {
4306                 nid_vol = nid - 0x7;
4307                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
4308                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
4309         } else if (nid >= 0x12 && nid <= 0x15) {
4310                 nid_vol = 0x08;
4311                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
4312                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
4313         } else
4314                 return 0; /* N/A */
4315         
4316         snprintf(name, sizeof(name), "%s Playback Volume", pfx);
4317         err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val);
4318         if (err < 0)
4319                 return err;
4320         snprintf(name, sizeof(name), "%s Playback Switch", pfx);
4321         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val);
4322         if (err < 0)
4323                 return err;
4324         return 1;
4325 }
4326
4327 /* add playback controls from the parsed DAC table */
4328 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
4329                                              const struct auto_pin_cfg *cfg)
4330 {
4331         hda_nid_t nid;
4332         int err;
4333
4334         spec->multiout.num_dacs = 1;
4335         spec->multiout.dac_nids = spec->private_dac_nids;
4336         spec->multiout.dac_nids[0] = 0x02;
4337
4338         nid = cfg->line_out_pins[0];
4339         if (nid) {
4340                 err = alc260_add_playback_controls(spec, nid, "Front");
4341                 if (err < 0)
4342                         return err;
4343         }
4344
4345         nid = cfg->speaker_pins[0];
4346         if (nid) {
4347                 err = alc260_add_playback_controls(spec, nid, "Speaker");
4348                 if (err < 0)
4349                         return err;
4350         }
4351
4352         nid = cfg->hp_pins[0];
4353         if (nid) {
4354                 err = alc260_add_playback_controls(spec, nid, "Headphone");
4355                 if (err < 0)
4356                         return err;
4357         }
4358         return 0;
4359 }
4360
4361 /* create playback/capture controls for input pins */
4362 static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec,
4363                                                 const struct auto_pin_cfg *cfg)
4364 {
4365         struct hda_input_mux *imux = &spec->private_imux;
4366         int i, err, idx;
4367
4368         for (i = 0; i < AUTO_PIN_LAST; i++) {
4369                 if (cfg->input_pins[i] >= 0x12) {
4370                         idx = cfg->input_pins[i] - 0x12;
4371                         err = new_analog_input(spec, cfg->input_pins[i],
4372                                                auto_pin_cfg_labels[i], idx,
4373                                                0x07);
4374                         if (err < 0)
4375                                 return err;
4376                         imux->items[imux->num_items].label =
4377                                 auto_pin_cfg_labels[i];
4378                         imux->items[imux->num_items].index = idx;
4379                         imux->num_items++;
4380                 }
4381                 if (cfg->input_pins[i] >= 0x0f && cfg->input_pins[i] <= 0x10){
4382                         idx = cfg->input_pins[i] - 0x09;
4383                         err = new_analog_input(spec, cfg->input_pins[i],
4384                                                auto_pin_cfg_labels[i], idx,
4385                                                0x07);
4386                         if (err < 0)
4387                                 return err;
4388                         imux->items[imux->num_items].label =
4389                                 auto_pin_cfg_labels[i];
4390                         imux->items[imux->num_items].index = idx;
4391                         imux->num_items++;
4392                 }
4393         }
4394         return 0;
4395 }
4396
4397 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
4398                                               hda_nid_t nid, int pin_type,
4399                                               int sel_idx)
4400 {
4401         /* set as output */
4402         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4403                             pin_type);
4404         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4405                             AMP_OUT_UNMUTE);
4406         /* need the manual connection? */
4407         if (nid >= 0x12) {
4408                 int idx = nid - 0x12;
4409                 snd_hda_codec_write(codec, idx + 0x0b, 0,
4410                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
4411         }
4412 }
4413
4414 static void alc260_auto_init_multi_out(struct hda_codec *codec)
4415 {
4416         struct alc_spec *spec = codec->spec;
4417         hda_nid_t nid;
4418
4419         alc_subsystem_id(codec, 0x10, 0x15, 0x0f);
4420         nid = spec->autocfg.line_out_pins[0];
4421         if (nid) {
4422                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
4423                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
4424         }
4425         
4426         nid = spec->autocfg.speaker_pins[0];
4427         if (nid)
4428                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
4429
4430         nid = spec->autocfg.hp_pins[0];
4431         if (nid)
4432                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
4433 }
4434
4435 #define ALC260_PIN_CD_NID               0x16
4436 static void alc260_auto_init_analog_input(struct hda_codec *codec)
4437 {
4438         struct alc_spec *spec = codec->spec;
4439         int i;
4440
4441         for (i = 0; i < AUTO_PIN_LAST; i++) {
4442                 hda_nid_t nid = spec->autocfg.input_pins[i];
4443                 if (nid >= 0x12) {
4444                         snd_hda_codec_write(codec, nid, 0,
4445                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
4446                                             i <= AUTO_PIN_FRONT_MIC ?
4447                                             PIN_VREF80 : PIN_IN);
4448                         if (nid != ALC260_PIN_CD_NID)
4449                                 snd_hda_codec_write(codec, nid, 0,
4450                                                     AC_VERB_SET_AMP_GAIN_MUTE,
4451                                                     AMP_OUT_MUTE);
4452                 }
4453         }
4454 }
4455
4456 /*
4457  * generic initialization of ADC, input mixers and output mixers
4458  */
4459 static struct hda_verb alc260_volume_init_verbs[] = {
4460         /*
4461          * Unmute ADC0-1 and set the default input to mic-in
4462          */
4463         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4464         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4465         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4466         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4467         
4468         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4469          * mixer widget
4470          * Note: PASD motherboards uses the Line In 2 as the input for
4471          * front panel mic (mic 2)
4472          */
4473         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
4474         /* mute analog inputs */
4475         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4476         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4477         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4478         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4479         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4480
4481         /*
4482          * Set up output mixers (0x08 - 0x0a)
4483          */
4484         /* set vol=0 to output mixers */
4485         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4486         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4487         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4488         /* set up input amps for analog loopback */
4489         /* Amp Indices: DAC = 0, mixer = 1 */
4490         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4491         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4492         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4493         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4494         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4495         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4496         
4497         { }
4498 };
4499
4500 static int alc260_parse_auto_config(struct hda_codec *codec)
4501 {
4502         struct alc_spec *spec = codec->spec;
4503         unsigned int wcap;
4504         int err;
4505         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
4506
4507         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
4508                                            alc260_ignore);
4509         if (err < 0)
4510                 return err;
4511         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
4512         if (err < 0)
4513                 return err;
4514         if (!spec->kctl_alloc)
4515                 return 0; /* can't find valid BIOS pin config */
4516         err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg);
4517         if (err < 0)
4518                 return err;
4519
4520         spec->multiout.max_channels = 2;
4521
4522         if (spec->autocfg.dig_out_pin)
4523                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
4524         if (spec->kctl_alloc)
4525                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
4526
4527         spec->init_verbs[spec->num_init_verbs++] = alc260_volume_init_verbs;
4528
4529         spec->num_mux_defs = 1;
4530         spec->input_mux = &spec->private_imux;
4531
4532         /* check whether NID 0x04 is valid */
4533         wcap = get_wcaps(codec, 0x04);
4534         wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */
4535         if (wcap != AC_WID_AUD_IN) {
4536                 spec->adc_nids = alc260_adc_nids_alt;
4537                 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
4538                 spec->mixers[spec->num_mixers] = alc260_capture_alt_mixer;
4539         } else {
4540                 spec->adc_nids = alc260_adc_nids;
4541                 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
4542                 spec->mixers[spec->num_mixers] = alc260_capture_mixer;
4543         }
4544         spec->num_mixers++;
4545
4546         return 1;
4547 }
4548
4549 /* additional initialization for auto-configuration model */
4550 static void alc260_auto_init(struct hda_codec *codec)
4551 {
4552         alc260_auto_init_multi_out(codec);
4553         alc260_auto_init_analog_input(codec);
4554 }
4555
4556 #ifdef CONFIG_SND_HDA_POWER_SAVE
4557 static struct hda_amp_list alc260_loopbacks[] = {
4558         { 0x07, HDA_INPUT, 0 },
4559         { 0x07, HDA_INPUT, 1 },
4560         { 0x07, HDA_INPUT, 2 },
4561         { 0x07, HDA_INPUT, 3 },
4562         { 0x07, HDA_INPUT, 4 },
4563         { } /* end */
4564 };
4565 #endif
4566
4567 /*
4568  * ALC260 configurations
4569  */
4570 static const char *alc260_models[ALC260_MODEL_LAST] = {
4571         [ALC260_BASIC]          = "basic",
4572         [ALC260_HP]             = "hp",
4573         [ALC260_HP_3013]        = "hp-3013",
4574         [ALC260_FUJITSU_S702X]  = "fujitsu",
4575         [ALC260_ACER]           = "acer",
4576         [ALC260_WILL]           = "will",
4577         [ALC260_REPLACER_672V]  = "replacer",
4578 #ifdef CONFIG_SND_DEBUG
4579         [ALC260_TEST]           = "test",
4580 #endif
4581         [ALC260_AUTO]           = "auto",
4582 };
4583
4584 static struct snd_pci_quirk alc260_cfg_tbl[] = {
4585         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
4586         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
4587         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
4588         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013),
4589         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
4590         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP),
4591         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_3013),
4592         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
4593         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
4594         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
4595         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
4596         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
4597         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
4598         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
4599         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
4600         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
4601         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
4602         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
4603         {}
4604 };
4605
4606 static struct alc_config_preset alc260_presets[] = {
4607         [ALC260_BASIC] = {
4608                 .mixers = { alc260_base_output_mixer,
4609                             alc260_input_mixer,
4610                             alc260_pc_beep_mixer,
4611                             alc260_capture_mixer },
4612                 .init_verbs = { alc260_init_verbs },
4613                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4614                 .dac_nids = alc260_dac_nids,
4615                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
4616                 .adc_nids = alc260_adc_nids,
4617                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4618                 .channel_mode = alc260_modes,
4619                 .input_mux = &alc260_capture_source,
4620         },
4621         [ALC260_HP] = {
4622                 .mixers = { alc260_base_output_mixer,
4623                             alc260_input_mixer,
4624                             alc260_capture_alt_mixer },
4625                 .init_verbs = { alc260_init_verbs },
4626                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4627                 .dac_nids = alc260_dac_nids,
4628                 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
4629                 .adc_nids = alc260_hp_adc_nids,
4630                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4631                 .channel_mode = alc260_modes,
4632                 .input_mux = &alc260_capture_source,
4633         },
4634         [ALC260_HP_3013] = {
4635                 .mixers = { alc260_hp_3013_mixer,
4636                             alc260_input_mixer,
4637                             alc260_capture_alt_mixer },
4638                 .init_verbs = { alc260_hp_3013_init_verbs },
4639                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4640                 .dac_nids = alc260_dac_nids,
4641                 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
4642                 .adc_nids = alc260_hp_adc_nids,
4643                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4644                 .channel_mode = alc260_modes,
4645                 .input_mux = &alc260_capture_source,
4646         },
4647         [ALC260_FUJITSU_S702X] = {
4648                 .mixers = { alc260_fujitsu_mixer,
4649                             alc260_capture_mixer },
4650                 .init_verbs = { alc260_fujitsu_init_verbs },
4651                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4652                 .dac_nids = alc260_dac_nids,
4653                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
4654                 .adc_nids = alc260_dual_adc_nids,
4655                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4656                 .channel_mode = alc260_modes,
4657                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
4658                 .input_mux = alc260_fujitsu_capture_sources,
4659         },
4660         [ALC260_ACER] = {
4661                 .mixers = { alc260_acer_mixer,
4662                             alc260_capture_mixer },
4663                 .init_verbs = { alc260_acer_init_verbs },
4664                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4665                 .dac_nids = alc260_dac_nids,
4666                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
4667                 .adc_nids = alc260_dual_adc_nids,
4668                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4669                 .channel_mode = alc260_modes,
4670                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
4671                 .input_mux = alc260_acer_capture_sources,
4672         },
4673         [ALC260_WILL] = {
4674                 .mixers = { alc260_will_mixer,
4675                             alc260_capture_mixer },
4676                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
4677                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4678                 .dac_nids = alc260_dac_nids,
4679                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
4680                 .adc_nids = alc260_adc_nids,
4681                 .dig_out_nid = ALC260_DIGOUT_NID,
4682                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4683                 .channel_mode = alc260_modes,
4684                 .input_mux = &alc260_capture_source,
4685         },
4686         [ALC260_REPLACER_672V] = {
4687                 .mixers = { alc260_replacer_672v_mixer,
4688                             alc260_capture_mixer },
4689                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
4690                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4691                 .dac_nids = alc260_dac_nids,
4692                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
4693                 .adc_nids = alc260_adc_nids,
4694                 .dig_out_nid = ALC260_DIGOUT_NID,
4695                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4696                 .channel_mode = alc260_modes,
4697                 .input_mux = &alc260_capture_source,
4698                 .unsol_event = alc260_replacer_672v_unsol_event,
4699                 .init_hook = alc260_replacer_672v_automute,
4700         },
4701 #ifdef CONFIG_SND_DEBUG
4702         [ALC260_TEST] = {
4703                 .mixers = { alc260_test_mixer,
4704                             alc260_capture_mixer },
4705                 .init_verbs = { alc260_test_init_verbs },
4706                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
4707                 .dac_nids = alc260_test_dac_nids,
4708                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
4709                 .adc_nids = alc260_test_adc_nids,
4710                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4711                 .channel_mode = alc260_modes,
4712                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
4713                 .input_mux = alc260_test_capture_sources,
4714         },
4715 #endif
4716 };
4717
4718 static int patch_alc260(struct hda_codec *codec)
4719 {
4720         struct alc_spec *spec;
4721         int err, board_config;
4722
4723         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4724         if (spec == NULL)
4725                 return -ENOMEM;
4726
4727         codec->spec = spec;
4728
4729         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
4730                                                   alc260_models,
4731                                                   alc260_cfg_tbl);
4732         if (board_config < 0) {
4733                 snd_printd(KERN_INFO "hda_codec: Unknown model for ALC260, "
4734                            "trying auto-probe from BIOS...\n");
4735                 board_config = ALC260_AUTO;
4736         }
4737
4738         if (board_config == ALC260_AUTO) {
4739                 /* automatic parse from the BIOS config */
4740                 err = alc260_parse_auto_config(codec);
4741                 if (err < 0) {
4742                         alc_free(codec);
4743                         return err;
4744                 } else if (!err) {
4745                         printk(KERN_INFO
4746                                "hda_codec: Cannot set up configuration "
4747                                "from BIOS.  Using base mode...\n");
4748                         board_config = ALC260_BASIC;
4749                 }
4750         }
4751
4752         if (board_config != ALC260_AUTO)
4753                 setup_preset(spec, &alc260_presets[board_config]);
4754
4755         spec->stream_name_analog = "ALC260 Analog";
4756         spec->stream_analog_playback = &alc260_pcm_analog_playback;
4757         spec->stream_analog_capture = &alc260_pcm_analog_capture;
4758
4759         spec->stream_name_digital = "ALC260 Digital";
4760         spec->stream_digital_playback = &alc260_pcm_digital_playback;
4761         spec->stream_digital_capture = &alc260_pcm_digital_capture;
4762
4763         codec->patch_ops = alc_patch_ops;
4764         if (board_config == ALC260_AUTO)
4765                 spec->init_hook = alc260_auto_init;
4766 #ifdef CONFIG_SND_HDA_POWER_SAVE
4767         if (!spec->loopback.amplist)
4768                 spec->loopback.amplist = alc260_loopbacks;
4769 #endif
4770
4771         return 0;
4772 }
4773
4774
4775 /*
4776  * ALC882 support
4777  *
4778  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4779  * configuration.  Each pin widget can choose any input DACs and a mixer.
4780  * Each ADC is connected from a mixer of all inputs.  This makes possible
4781  * 6-channel independent captures.
4782  *
4783  * In addition, an independent DAC for the multi-playback (not used in this
4784  * driver yet).
4785  */
4786 #define ALC882_DIGOUT_NID       0x06
4787 #define ALC882_DIGIN_NID        0x0a
4788
4789 static struct hda_channel_mode alc882_ch_modes[1] = {
4790         { 8, NULL }
4791 };
4792
4793 static hda_nid_t alc882_dac_nids[4] = {
4794         /* front, rear, clfe, rear_surr */
4795         0x02, 0x03, 0x04, 0x05
4796 };
4797
4798 /* identical with ALC880 */
4799 #define alc882_adc_nids         alc880_adc_nids
4800 #define alc882_adc_nids_alt     alc880_adc_nids_alt
4801
4802 /* input MUX */
4803 /* FIXME: should be a matrix-type input source selection */
4804
4805 static struct hda_input_mux alc882_capture_source = {
4806         .num_items = 4,
4807         .items = {
4808                 { "Mic", 0x0 },
4809                 { "Front Mic", 0x1 },
4810                 { "Line", 0x2 },
4811                 { "CD", 0x4 },
4812         },
4813 };
4814 #define alc882_mux_enum_info alc_mux_enum_info
4815 #define alc882_mux_enum_get alc_mux_enum_get
4816
4817 static int alc882_mux_enum_put(struct snd_kcontrol *kcontrol,
4818                                struct snd_ctl_elem_value *ucontrol)
4819 {
4820         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4821         struct alc_spec *spec = codec->spec;
4822         const struct hda_input_mux *imux = spec->input_mux;
4823         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
4824         static hda_nid_t capture_mixers[3] = { 0x24, 0x23, 0x22 };
4825         hda_nid_t nid = capture_mixers[adc_idx];
4826         unsigned int *cur_val = &spec->cur_mux[adc_idx];
4827         unsigned int i, idx;
4828
4829         idx = ucontrol->value.enumerated.item[0];
4830         if (idx >= imux->num_items)
4831                 idx = imux->num_items - 1;
4832         if (*cur_val == idx)
4833                 return 0;
4834         for (i = 0; i < imux->num_items; i++) {
4835                 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
4836                 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
4837                                          imux->items[i].index,
4838                                          HDA_AMP_MUTE, v);
4839         }
4840         *cur_val = idx;
4841         return 1;
4842 }
4843
4844 /*
4845  * 2ch mode
4846  */
4847 static struct hda_verb alc882_3ST_ch2_init[] = {
4848         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
4849         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
4850         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
4851         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
4852         { } /* end */
4853 };
4854
4855 /*
4856  * 6ch mode
4857  */
4858 static struct hda_verb alc882_3ST_ch6_init[] = {
4859         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4860         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
4861         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
4862         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4863         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
4864         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
4865         { } /* end */
4866 };
4867
4868 static struct hda_channel_mode alc882_3ST_6ch_modes[2] = {
4869         { 2, alc882_3ST_ch2_init },
4870         { 6, alc882_3ST_ch6_init },
4871 };
4872
4873 /*
4874  * 6ch mode
4875  */
4876 static struct hda_verb alc882_sixstack_ch6_init[] = {
4877         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
4878         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4879         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4880         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4881         { } /* end */
4882 };
4883
4884 /*
4885  * 8ch mode
4886  */
4887 static struct hda_verb alc882_sixstack_ch8_init[] = {
4888         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4889         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4890         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4891         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4892         { } /* end */
4893 };
4894
4895 static struct hda_channel_mode alc882_sixstack_modes[2] = {
4896         { 6, alc882_sixstack_ch6_init },
4897         { 8, alc882_sixstack_ch8_init },
4898 };
4899
4900 /*
4901  * macbook pro ALC885 can switch LineIn to LineOut without loosing Mic
4902  */
4903
4904 /*
4905  * 2ch mode
4906  */
4907 static struct hda_verb alc885_mbp_ch2_init[] = {
4908         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
4909         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4910         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4911         { } /* end */
4912 };
4913
4914 /*
4915  * 6ch mode
4916  */
4917 static struct hda_verb alc885_mbp_ch6_init[] = {
4918         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4919         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4920         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
4921         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4922         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4923         { } /* end */
4924 };
4925
4926 static struct hda_channel_mode alc885_mbp_6ch_modes[2] = {
4927         { 2, alc885_mbp_ch2_init },
4928         { 6, alc885_mbp_ch6_init },
4929 };
4930
4931
4932 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
4933  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
4934  */
4935 static struct snd_kcontrol_new alc882_base_mixer[] = {
4936         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
4937         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
4938         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
4939         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
4940         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
4941         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
4942         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
4943         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
4944         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
4945         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
4946         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
4947         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
4948         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
4949         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
4950         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
4951         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
4952         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
4953         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
4954         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
4955         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
4956         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
4957         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
4958         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
4959         { } /* end */
4960 };
4961
4962 static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
4963         HDA_CODEC_VOLUME("Master Volume", 0x0c, 0x00, HDA_OUTPUT),
4964         HDA_BIND_MUTE   ("Master Switch", 0x0c, 0x02, HDA_INPUT),
4965         HDA_CODEC_MUTE  ("Speaker Switch", 0x14, 0x00, HDA_OUTPUT),
4966         HDA_CODEC_VOLUME("Line Out Volume", 0x0d,0x00, HDA_OUTPUT),
4967         HDA_CODEC_VOLUME("Line In Playback Volume", 0x0b, 0x02, HDA_INPUT),
4968         HDA_CODEC_MUTE  ("Line In Playback Switch", 0x0b, 0x02, HDA_INPUT),
4969         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
4970         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
4971         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0x00, HDA_INPUT),
4972         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
4973         { } /* end */
4974 };
4975 static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
4976         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
4977         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
4978         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
4979         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
4980         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
4981         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
4982         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
4983         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
4984         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
4985         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
4986         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
4987         { } /* end */
4988 };
4989
4990 static struct snd_kcontrol_new alc882_targa_mixer[] = {
4991         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
4992         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
4993         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
4994         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
4995         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
4996         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
4997         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
4998         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
4999         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5000         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5001         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5002         { } /* end */
5003 };
5004
5005 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
5006  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
5007  */
5008 static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
5009         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5010         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
5011         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5012         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
5013         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5014         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5015         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5016         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5017         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
5018         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
5019         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5020         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5021         { } /* end */
5022 };
5023
5024 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
5025         {
5026                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5027                 .name = "Channel Mode",
5028                 .info = alc_ch_mode_info,
5029                 .get = alc_ch_mode_get,
5030                 .put = alc_ch_mode_put,
5031         },
5032         { } /* end */
5033 };
5034
5035 static struct hda_verb alc882_init_verbs[] = {
5036         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5037         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5038         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5039         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5040         /* Rear mixer */
5041         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5042         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5043         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5044         /* CLFE mixer */
5045         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5046         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5047         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5048         /* Side mixer */
5049         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5050         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5051         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5052
5053         /* Front Pin: output 0 (0x0c) */
5054         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5055         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5056         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5057         /* Rear Pin: output 1 (0x0d) */
5058         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5059         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5060         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5061         /* CLFE Pin: output 2 (0x0e) */
5062         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5063         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5064         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
5065         /* Side Pin: output 3 (0x0f) */
5066         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5067         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5068         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
5069         /* Mic (rear) pin: input vref at 80% */
5070         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5071         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5072         /* Front Mic pin: input vref at 80% */
5073         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5074         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5075         /* Line In pin: input */
5076         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5077         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5078         /* Line-2 In: Headphone output (output 0 - 0x0c) */
5079         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5080         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5081         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
5082         /* CD pin widget for input */
5083         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5084
5085         /* FIXME: use matrix-type input source selection */
5086         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5087         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5088         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5089         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5090         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5091         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5092         /* Input mixer2 */
5093         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5094         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5095         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5096         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5097         /* Input mixer3 */
5098         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5099         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5100         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5101         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5102         /* ADC1: mute amp left and right */
5103         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5104         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5105         /* ADC2: mute amp left and right */
5106         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5107         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5108         /* ADC3: mute amp left and right */
5109         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5110         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5111
5112         { }
5113 };
5114
5115 static struct hda_verb alc882_eapd_verbs[] = {
5116         /* change to EAPD mode */
5117         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
5118         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
5119         { }
5120 };
5121
5122 /* Mac Pro test */
5123 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
5124         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5125         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5126         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
5127         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
5128         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
5129         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT),
5130         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT),
5131         { } /* end */
5132 };
5133
5134 static struct hda_verb alc882_macpro_init_verbs[] = {
5135         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5136         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5137         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5138         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5139         /* Front Pin: output 0 (0x0c) */
5140         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5141         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5142         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
5143         /* Front Mic pin: input vref at 80% */
5144         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5145         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5146         /* Speaker:  output */
5147         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5148         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5149         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
5150         /* Headphone output (output 0 - 0x0c) */
5151         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5152         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5153         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
5154
5155         /* FIXME: use matrix-type input source selection */
5156         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5157         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5158         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5159         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5160         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5161         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5162         /* Input mixer2 */
5163         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5164         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5165         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5166         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5167         /* Input mixer3 */
5168         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5169         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5170         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5171         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5172         /* ADC1: mute amp left and right */
5173         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5174         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5175         /* ADC2: mute amp left and right */
5176         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5177         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5178         /* ADC3: mute amp left and right */
5179         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5180         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5181
5182         { }
5183 };
5184
5185 /* Macbook Pro rev3 */
5186 static struct hda_verb alc885_mbp3_init_verbs[] = {
5187         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5188         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5189         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5190         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5191         /* Rear mixer */
5192         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5193         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5194         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5195         /* Front Pin: output 0 (0x0c) */
5196         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5197         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5198         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5199         /* HP Pin: output 0 (0x0d) */
5200         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
5201         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5202         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
5203         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5204         /* Mic (rear) pin: input vref at 80% */
5205         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5206         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5207         /* Front Mic pin: input vref at 80% */
5208         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5209         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5210         /* Line In pin: use output 1 when in LineOut mode */
5211         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5212         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5213         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
5214
5215         /* FIXME: use matrix-type input source selection */
5216         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5217         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5218         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5219         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5220         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5221         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5222         /* Input mixer2 */
5223         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5224         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5225         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5226         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5227         /* Input mixer3 */
5228         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5229         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5230         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5231         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5232         /* ADC1: mute amp left and right */
5233         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5234         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5235         /* ADC2: mute amp left and right */
5236         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5237         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5238         /* ADC3: mute amp left and right */
5239         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5240         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5241
5242         { }
5243 };
5244
5245 /* iMac 24 mixer. */
5246 static struct snd_kcontrol_new alc885_imac24_mixer[] = {
5247         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
5248         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
5249         { } /* end */
5250 };
5251
5252 /* iMac 24 init verbs. */
5253 static struct hda_verb alc885_imac24_init_verbs[] = {
5254         /* Internal speakers: output 0 (0x0c) */
5255         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5256         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5257         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
5258         /* Internal speakers: output 0 (0x0c) */
5259         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5260         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5261         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
5262         /* Headphone: output 0 (0x0c) */
5263         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5264         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5265         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5266         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5267         /* Front Mic: input vref at 80% */
5268         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5269         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5270         { }
5271 };
5272
5273 /* Toggle speaker-output according to the hp-jack state */
5274 static void alc885_imac24_automute(struct hda_codec *codec)
5275 {
5276         unsigned int present;
5277
5278         present = snd_hda_codec_read(codec, 0x14, 0,
5279                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5280         snd_hda_codec_amp_stereo(codec, 0x18, HDA_OUTPUT, 0,
5281                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5282         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
5283                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5284 }
5285
5286 /* Processes unsolicited events. */
5287 static void alc885_imac24_unsol_event(struct hda_codec *codec,
5288                                       unsigned int res)
5289 {
5290         /* Headphone insertion or removal. */
5291         if ((res >> 26) == ALC880_HP_EVENT)
5292                 alc885_imac24_automute(codec);
5293 }
5294
5295 static void alc885_mbp3_automute(struct hda_codec *codec)
5296 {
5297         unsigned int present;
5298
5299         present = snd_hda_codec_read(codec, 0x15, 0,
5300                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5301         snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
5302                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5303         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
5304                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
5305
5306 }
5307 static void alc885_mbp3_unsol_event(struct hda_codec *codec,
5308                                     unsigned int res)
5309 {
5310         /* Headphone insertion or removal. */
5311         if ((res >> 26) == ALC880_HP_EVENT)
5312                 alc885_mbp3_automute(codec);
5313 }
5314
5315
5316 static struct hda_verb alc882_targa_verbs[] = {
5317         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5318         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5319
5320         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5321         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5322         
5323         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
5324         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
5325         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5326
5327         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5328         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5329         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
5330         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
5331         { } /* end */
5332 };
5333
5334 /* toggle speaker-output according to the hp-jack state */
5335 static void alc882_targa_automute(struct hda_codec *codec)
5336 {
5337         unsigned int present;
5338  
5339         present = snd_hda_codec_read(codec, 0x14, 0,
5340                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5341         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
5342                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5343         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
5344                                   present ? 1 : 3);
5345 }
5346
5347 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
5348 {
5349         /* Looks like the unsol event is incompatible with the standard
5350          * definition.  4bit tag is placed at 26 bit!
5351          */
5352         if (((res >> 26) == ALC880_HP_EVENT)) {
5353                 alc882_targa_automute(codec);
5354         }
5355 }
5356
5357 static struct hda_verb alc882_asus_a7j_verbs[] = {
5358         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5359         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5360
5361         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5362         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5363         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5364         
5365         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5366         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5367         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5368
5369         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
5370         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
5371         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5372         { } /* end */
5373 };
5374
5375 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5376 {
5377         unsigned int gpiostate, gpiomask, gpiodir;
5378
5379         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5380                                        AC_VERB_GET_GPIO_DATA, 0);
5381
5382         if (!muted)
5383                 gpiostate |= (1 << pin);
5384         else
5385                 gpiostate &= ~(1 << pin);
5386
5387         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5388                                       AC_VERB_GET_GPIO_MASK, 0);
5389         gpiomask |= (1 << pin);
5390
5391         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5392                                      AC_VERB_GET_GPIO_DIRECTION, 0);
5393         gpiodir |= (1 << pin);
5394
5395
5396         snd_hda_codec_write(codec, codec->afg, 0,
5397                             AC_VERB_SET_GPIO_MASK, gpiomask);
5398         snd_hda_codec_write(codec, codec->afg, 0,
5399                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5400
5401         msleep(1);
5402
5403         snd_hda_codec_write(codec, codec->afg, 0,
5404                             AC_VERB_SET_GPIO_DATA, gpiostate);
5405 }
5406
5407 /* set up GPIO at initialization */
5408 static void alc885_macpro_init_hook(struct hda_codec *codec)
5409 {
5410         alc882_gpio_mute(codec, 0, 0);
5411         alc882_gpio_mute(codec, 1, 0);
5412 }
5413
5414 /* set up GPIO and update auto-muting at initialization */
5415 static void alc885_imac24_init_hook(struct hda_codec *codec)
5416 {
5417         alc885_macpro_init_hook(codec);
5418         alc885_imac24_automute(codec);
5419 }
5420
5421 /*
5422  * generic initialization of ADC, input mixers and output mixers
5423  */
5424 static struct hda_verb alc882_auto_init_verbs[] = {
5425         /*
5426          * Unmute ADC0-2 and set the default input to mic-in
5427          */
5428         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5429         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5430         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5431         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5432         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5433         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5434
5435         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5436          * mixer widget
5437          * Note: PASD motherboards uses the Line In 2 as the input for
5438          * front panel mic (mic 2)
5439          */
5440         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
5441         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5442         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5443         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5444         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5445         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5446
5447         /*
5448          * Set up output mixers (0x0c - 0x0f)
5449          */
5450         /* set vol=0 to output mixers */
5451         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5452         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5453         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5454         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5455         /* set up input amps for analog loopback */
5456         /* Amp Indices: DAC = 0, mixer = 1 */
5457         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5458         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5459         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5460         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5461         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5462         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5463         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5464         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5465         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5466         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5467
5468         /* FIXME: use matrix-type input source selection */
5469         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5470         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5471         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5472         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
5473         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
5474         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
5475         /* Input mixer2 */
5476         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5477         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
5478         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
5479         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
5480         /* Input mixer3 */
5481         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5482         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
5483         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
5484         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
5485
5486         { }
5487 };
5488
5489 /* capture mixer elements */
5490 static struct snd_kcontrol_new alc882_capture_alt_mixer[] = {
5491         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
5492         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
5493         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
5494         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
5495         {
5496                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5497                 /* The multiple "Capture Source" controls confuse alsamixer
5498                  * So call somewhat different..
5499                  * FIXME: the controls appear in the "playback" view!
5500                  */
5501                 /* .name = "Capture Source", */
5502                 .name = "Input Source",
5503                 .count = 2,
5504                 .info = alc882_mux_enum_info,
5505                 .get = alc882_mux_enum_get,
5506                 .put = alc882_mux_enum_put,
5507         },
5508         { } /* end */
5509 };
5510
5511 static struct snd_kcontrol_new alc882_capture_mixer[] = {
5512         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
5513         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
5514         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
5515         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
5516         HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
5517         HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
5518         {
5519                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5520                 /* The multiple "Capture Source" controls confuse alsamixer
5521                  * So call somewhat different..
5522                  * FIXME: the controls appear in the "playback" view!
5523                  */
5524                 /* .name = "Capture Source", */
5525                 .name = "Input Source",
5526                 .count = 3,
5527                 .info = alc882_mux_enum_info,
5528                 .get = alc882_mux_enum_get,
5529                 .put = alc882_mux_enum_put,
5530         },
5531         { } /* end */
5532 };
5533
5534 #ifdef CONFIG_SND_HDA_POWER_SAVE
5535 #define alc882_loopbacks        alc880_loopbacks
5536 #endif
5537
5538 /* pcm configuration: identiacal with ALC880 */
5539 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
5540 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
5541 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
5542 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
5543
5544 /*
5545  * configuration and preset
5546  */
5547 static const char *alc882_models[ALC882_MODEL_LAST] = {
5548         [ALC882_3ST_DIG]        = "3stack-dig",
5549         [ALC882_6ST_DIG]        = "6stack-dig",
5550         [ALC882_ARIMA]          = "arima",
5551         [ALC882_W2JC]           = "w2jc",
5552         [ALC885_MACPRO]         = "macpro",
5553         [ALC885_MBP3]           = "mbp3",
5554         [ALC885_IMAC24]         = "imac24",
5555         [ALC882_AUTO]           = "auto",
5556 };
5557
5558 static struct snd_pci_quirk alc882_cfg_tbl[] = {
5559         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
5560         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
5561         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
5562         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
5563         SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA),
5564         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
5565         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
5566         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
5567         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
5568         {}
5569 };
5570
5571 static struct alc_config_preset alc882_presets[] = {
5572         [ALC882_3ST_DIG] = {
5573                 .mixers = { alc882_base_mixer },
5574                 .init_verbs = { alc882_init_verbs },
5575                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5576                 .dac_nids = alc882_dac_nids,
5577                 .dig_out_nid = ALC882_DIGOUT_NID,
5578                 .dig_in_nid = ALC882_DIGIN_NID,
5579                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
5580                 .channel_mode = alc882_ch_modes,
5581                 .need_dac_fix = 1,
5582                 .input_mux = &alc882_capture_source,
5583         },
5584         [ALC882_6ST_DIG] = {
5585                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
5586                 .init_verbs = { alc882_init_verbs },
5587                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5588                 .dac_nids = alc882_dac_nids,
5589                 .dig_out_nid = ALC882_DIGOUT_NID,
5590                 .dig_in_nid = ALC882_DIGIN_NID,
5591                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
5592                 .channel_mode = alc882_sixstack_modes,
5593                 .input_mux = &alc882_capture_source,
5594         },
5595         [ALC882_ARIMA] = {
5596                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
5597                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs },
5598                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5599                 .dac_nids = alc882_dac_nids,
5600                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
5601                 .channel_mode = alc882_sixstack_modes,
5602                 .input_mux = &alc882_capture_source,
5603         },
5604         [ALC882_W2JC] = {
5605                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
5606                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
5607                                 alc880_gpio1_init_verbs },
5608                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5609                 .dac_nids = alc882_dac_nids,
5610                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
5611                 .channel_mode = alc880_threestack_modes,
5612                 .need_dac_fix = 1,
5613                 .input_mux = &alc882_capture_source,
5614                 .dig_out_nid = ALC882_DIGOUT_NID,
5615         },
5616         [ALC885_MBP3] = {
5617                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
5618                 .init_verbs = { alc885_mbp3_init_verbs,
5619                                 alc880_gpio1_init_verbs },
5620                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5621                 .dac_nids = alc882_dac_nids,
5622                 .channel_mode = alc885_mbp_6ch_modes,
5623                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_6ch_modes),
5624                 .input_mux = &alc882_capture_source,
5625                 .dig_out_nid = ALC882_DIGOUT_NID,
5626                 .dig_in_nid = ALC882_DIGIN_NID,
5627                 .unsol_event = alc885_mbp3_unsol_event,
5628                 .init_hook = alc885_mbp3_automute,
5629         },
5630         [ALC885_MACPRO] = {
5631                 .mixers = { alc882_macpro_mixer },
5632                 .init_verbs = { alc882_macpro_init_verbs },
5633                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5634                 .dac_nids = alc882_dac_nids,
5635                 .dig_out_nid = ALC882_DIGOUT_NID,
5636                 .dig_in_nid = ALC882_DIGIN_NID,
5637                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
5638                 .channel_mode = alc882_ch_modes,
5639                 .input_mux = &alc882_capture_source,
5640                 .init_hook = alc885_macpro_init_hook,
5641         },
5642         [ALC885_IMAC24] = {
5643                 .mixers = { alc885_imac24_mixer },
5644                 .init_verbs = { alc885_imac24_init_verbs },
5645                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5646                 .dac_nids = alc882_dac_nids,
5647                 .dig_out_nid = ALC882_DIGOUT_NID,
5648                 .dig_in_nid = ALC882_DIGIN_NID,
5649                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
5650                 .channel_mode = alc882_ch_modes,
5651                 .input_mux = &alc882_capture_source,
5652                 .unsol_event = alc885_imac24_unsol_event,
5653                 .init_hook = alc885_imac24_init_hook,
5654         },
5655         [ALC882_TARGA] = {
5656                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer,
5657                             alc882_capture_mixer },
5658                 .init_verbs = { alc882_init_verbs, alc882_targa_verbs},
5659                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5660                 .dac_nids = alc882_dac_nids,
5661                 .dig_out_nid = ALC882_DIGOUT_NID,
5662                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
5663                 .adc_nids = alc882_adc_nids,
5664                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
5665                 .channel_mode = alc882_3ST_6ch_modes,
5666                 .need_dac_fix = 1,
5667                 .input_mux = &alc882_capture_source,
5668                 .unsol_event = alc882_targa_unsol_event,
5669                 .init_hook = alc882_targa_automute,
5670         },
5671         [ALC882_ASUS_A7J] = {
5672                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer,
5673                             alc882_capture_mixer },
5674                 .init_verbs = { alc882_init_verbs, alc882_asus_a7j_verbs},
5675                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5676                 .dac_nids = alc882_dac_nids,
5677                 .dig_out_nid = ALC882_DIGOUT_NID,
5678                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
5679                 .adc_nids = alc882_adc_nids,
5680                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
5681                 .channel_mode = alc882_3ST_6ch_modes,
5682                 .need_dac_fix = 1,
5683                 .input_mux = &alc882_capture_source,
5684         },      
5685 };
5686
5687
5688 /*
5689  * Pin config fixes
5690  */
5691 enum { 
5692         PINFIX_ABIT_AW9D_MAX
5693 };
5694
5695 static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
5696         { 0x15, 0x01080104 }, /* side */
5697         { 0x16, 0x01011012 }, /* rear */
5698         { 0x17, 0x01016011 }, /* clfe */
5699         { }
5700 };
5701
5702 static const struct alc_pincfg *alc882_pin_fixes[] = {
5703         [PINFIX_ABIT_AW9D_MAX] = alc882_abit_aw9d_pinfix,
5704 };
5705
5706 static struct snd_pci_quirk alc882_pinfix_tbl[] = {
5707         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
5708         {}
5709 };
5710
5711 /*
5712  * BIOS auto configuration
5713  */
5714 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
5715                                               hda_nid_t nid, int pin_type,
5716                                               int dac_idx)
5717 {
5718         /* set as output */
5719         struct alc_spec *spec = codec->spec;
5720         int idx;
5721
5722         if (spec->multiout.dac_nids[dac_idx] == 0x25)
5723                 idx = 4;
5724         else
5725                 idx = spec->multiout.dac_nids[dac_idx] - 2;
5726
5727         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5728                             pin_type);
5729         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
5730                             AMP_OUT_UNMUTE);
5731         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
5732
5733 }
5734
5735 static void alc882_auto_init_multi_out(struct hda_codec *codec)
5736 {
5737         struct alc_spec *spec = codec->spec;
5738         int i;
5739
5740         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
5741         for (i = 0; i <= HDA_SIDE; i++) {
5742                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
5743                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
5744                 if (nid)
5745                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
5746                                                           i);
5747         }
5748 }
5749
5750 static void alc882_auto_init_hp_out(struct hda_codec *codec)
5751 {
5752         struct alc_spec *spec = codec->spec;
5753         hda_nid_t pin;
5754
5755         pin = spec->autocfg.hp_pins[0];
5756         if (pin) /* connect to front */
5757                 /* use dac 0 */
5758                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
5759 }
5760
5761 #define alc882_is_input_pin(nid)        alc880_is_input_pin(nid)
5762 #define ALC882_PIN_CD_NID               ALC880_PIN_CD_NID
5763
5764 static void alc882_auto_init_analog_input(struct hda_codec *codec)
5765 {
5766         struct alc_spec *spec = codec->spec;
5767         int i;
5768
5769         for (i = 0; i < AUTO_PIN_LAST; i++) {
5770                 hda_nid_t nid = spec->autocfg.input_pins[i];
5771                 if (alc882_is_input_pin(nid)) {
5772                         snd_hda_codec_write(codec, nid, 0,
5773                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
5774                                             i <= AUTO_PIN_FRONT_MIC ?
5775                                             PIN_VREF80 : PIN_IN);
5776                         if (nid != ALC882_PIN_CD_NID)
5777                                 snd_hda_codec_write(codec, nid, 0,
5778                                                     AC_VERB_SET_AMP_GAIN_MUTE,
5779                                                     AMP_OUT_MUTE);
5780                 }
5781         }
5782 }
5783
5784 /* almost identical with ALC880 parser... */
5785 static int alc882_parse_auto_config(struct hda_codec *codec)
5786 {
5787         struct alc_spec *spec = codec->spec;
5788         int err = alc880_parse_auto_config(codec);
5789
5790         if (err < 0)
5791                 return err;
5792         else if (err > 0)
5793                 /* hack - override the init verbs */
5794                 spec->init_verbs[0] = alc882_auto_init_verbs;
5795         return err;
5796 }
5797
5798 /* additional initialization for auto-configuration model */
5799 static void alc882_auto_init(struct hda_codec *codec)
5800 {
5801         alc882_auto_init_multi_out(codec);
5802         alc882_auto_init_hp_out(codec);
5803         alc882_auto_init_analog_input(codec);
5804 }
5805
5806 static int patch_alc882(struct hda_codec *codec)
5807 {
5808         struct alc_spec *spec;
5809         int err, board_config;
5810
5811         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5812         if (spec == NULL)
5813                 return -ENOMEM;
5814
5815         codec->spec = spec;
5816
5817         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
5818                                                   alc882_models,
5819                                                   alc882_cfg_tbl);
5820
5821         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
5822                 /* Pick up systems that don't supply PCI SSID */
5823                 switch (codec->subsystem_id) {
5824                 case 0x106b0c00: /* Mac Pro */
5825                         board_config = ALC885_MACPRO;
5826                         break;
5827                 case 0x106b1000: /* iMac 24 */
5828                         board_config = ALC885_IMAC24;
5829                         break;
5830                 case 0x106b2c00: /* Macbook Pro rev3 */
5831                         board_config = ALC885_MBP3;
5832                         break;
5833                 default:
5834                         printk(KERN_INFO "hda_codec: Unknown model for ALC882, "
5835                                          "trying auto-probe from BIOS...\n");
5836                         board_config = ALC882_AUTO;
5837                 }
5838         }
5839
5840         alc_fix_pincfg(codec, alc882_pinfix_tbl, alc882_pin_fixes);
5841
5842         if (board_config == ALC882_AUTO) {
5843                 /* automatic parse from the BIOS config */
5844                 err = alc882_parse_auto_config(codec);
5845                 if (err < 0) {
5846                         alc_free(codec);
5847                         return err;
5848                 } else if (!err) {
5849                         printk(KERN_INFO
5850                                "hda_codec: Cannot set up configuration "
5851                                "from BIOS.  Using base mode...\n");
5852                         board_config = ALC882_3ST_DIG;
5853                 }
5854         }
5855
5856         if (board_config != ALC882_AUTO)
5857                 setup_preset(spec, &alc882_presets[board_config]);
5858
5859         spec->stream_name_analog = "ALC882 Analog";
5860         spec->stream_analog_playback = &alc882_pcm_analog_playback;
5861         spec->stream_analog_capture = &alc882_pcm_analog_capture;
5862
5863         spec->stream_name_digital = "ALC882 Digital";
5864         spec->stream_digital_playback = &alc882_pcm_digital_playback;
5865         spec->stream_digital_capture = &alc882_pcm_digital_capture;
5866
5867         if (!spec->adc_nids && spec->input_mux) {
5868                 /* check whether NID 0x07 is valid */
5869                 unsigned int wcap = get_wcaps(codec, 0x07);
5870                 /* get type */
5871                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
5872                 if (wcap != AC_WID_AUD_IN) {
5873                         spec->adc_nids = alc882_adc_nids_alt;
5874                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
5875                         spec->mixers[spec->num_mixers] =
5876                                 alc882_capture_alt_mixer;
5877                         spec->num_mixers++;
5878                 } else {
5879                         spec->adc_nids = alc882_adc_nids;
5880                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
5881                         spec->mixers[spec->num_mixers] = alc882_capture_mixer;
5882                         spec->num_mixers++;
5883                 }
5884         }
5885
5886         codec->patch_ops = alc_patch_ops;
5887         if (board_config == ALC882_AUTO)
5888                 spec->init_hook = alc882_auto_init;
5889 #ifdef CONFIG_SND_HDA_POWER_SAVE
5890         if (!spec->loopback.amplist)
5891                 spec->loopback.amplist = alc882_loopbacks;
5892 #endif
5893
5894         return 0;
5895 }
5896
5897 /*
5898  * ALC883 support
5899  *
5900  * ALC883 is almost identical with ALC880 but has cleaner and more flexible
5901  * configuration.  Each pin widget can choose any input DACs and a mixer.
5902  * Each ADC is connected from a mixer of all inputs.  This makes possible
5903  * 6-channel independent captures.
5904  *
5905  * In addition, an independent DAC for the multi-playback (not used in this
5906  * driver yet).
5907  */
5908 #define ALC883_DIGOUT_NID       0x06
5909 #define ALC883_DIGIN_NID        0x0a
5910
5911 static hda_nid_t alc883_dac_nids[4] = {
5912         /* front, rear, clfe, rear_surr */
5913         0x02, 0x04, 0x03, 0x05
5914 };
5915
5916 static hda_nid_t alc883_adc_nids[2] = {
5917         /* ADC1-2 */
5918         0x08, 0x09,
5919 };
5920
5921 /* input MUX */
5922 /* FIXME: should be a matrix-type input source selection */
5923
5924 static struct hda_input_mux alc883_capture_source = {
5925         .num_items = 4,
5926         .items = {
5927                 { "Mic", 0x0 },
5928                 { "Front Mic", 0x1 },
5929                 { "Line", 0x2 },
5930                 { "CD", 0x4 },
5931         },
5932 };
5933
5934 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
5935         .num_items = 2,
5936         .items = {
5937                 { "Mic", 0x1 },
5938                 { "Line", 0x2 },
5939         },
5940 };
5941
5942 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
5943         .num_items = 4,
5944         .items = {
5945                 { "Mic", 0x0 },
5946                 { "iMic", 0x1 },
5947                 { "Line", 0x2 },
5948                 { "CD", 0x4 },
5949         },
5950 };
5951
5952 #define alc883_mux_enum_info alc_mux_enum_info
5953 #define alc883_mux_enum_get alc_mux_enum_get
5954
5955 static int alc883_mux_enum_put(struct snd_kcontrol *kcontrol,
5956                                struct snd_ctl_elem_value *ucontrol)
5957 {
5958         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5959         struct alc_spec *spec = codec->spec;
5960         const struct hda_input_mux *imux = spec->input_mux;
5961         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
5962         static hda_nid_t capture_mixers[3] = { 0x24, 0x23, 0x22 };
5963         hda_nid_t nid = capture_mixers[adc_idx];
5964         unsigned int *cur_val = &spec->cur_mux[adc_idx];
5965         unsigned int i, idx;
5966
5967         idx = ucontrol->value.enumerated.item[0];
5968         if (idx >= imux->num_items)
5969                 idx = imux->num_items - 1;
5970         if (*cur_val == idx)
5971                 return 0;
5972         for (i = 0; i < imux->num_items; i++) {
5973                 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
5974                 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
5975                                          imux->items[i].index,
5976                                          HDA_AMP_MUTE, v);
5977         }
5978         *cur_val = idx;
5979         return 1;
5980 }
5981
5982 /*
5983  * 2ch mode
5984  */
5985 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
5986         { 2, NULL }
5987 };
5988
5989 /*
5990  * 2ch mode
5991  */
5992 static struct hda_verb alc883_3ST_ch2_init[] = {
5993         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
5994         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5995         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5996         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5997         { } /* end */
5998 };
5999
6000 /*
6001  * 6ch mode
6002  */
6003 static struct hda_verb alc883_3ST_ch6_init[] = {
6004         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6005         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6006         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6007         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6008         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6009         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6010         { } /* end */
6011 };
6012
6013 static struct hda_channel_mode alc883_3ST_6ch_modes[2] = {
6014         { 2, alc883_3ST_ch2_init },
6015         { 6, alc883_3ST_ch6_init },
6016 };
6017
6018 /*
6019  * 6ch mode
6020  */
6021 static struct hda_verb alc883_sixstack_ch6_init[] = {
6022         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6023         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6024         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6025         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6026         { } /* end */
6027 };
6028
6029 /*
6030  * 8ch mode
6031  */
6032 static struct hda_verb alc883_sixstack_ch8_init[] = {
6033         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6034         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6035         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6036         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6037         { } /* end */
6038 };
6039
6040 static struct hda_channel_mode alc883_sixstack_modes[2] = {
6041         { 6, alc883_sixstack_ch6_init },
6042         { 8, alc883_sixstack_ch8_init },
6043 };
6044
6045 static struct hda_verb alc883_medion_eapd_verbs[] = {
6046         /* eanable EAPD on medion laptop */
6047         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
6048         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
6049         { }
6050 };
6051
6052 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
6053  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
6054  */
6055
6056 static struct snd_kcontrol_new alc883_base_mixer[] = {
6057         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6058         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6059         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6060         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6061         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6062         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6063         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6064         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6065         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6066         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6067         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6068         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6069         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6070         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6071         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6072         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6073         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6074         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6075         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6076         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6077         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6078         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6079         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6080         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6081         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6082         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6083         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6084         {
6085                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6086                 /* .name = "Capture Source", */
6087                 .name = "Input Source",
6088                 .count = 2,
6089                 .info = alc883_mux_enum_info,
6090                 .get = alc883_mux_enum_get,
6091                 .put = alc883_mux_enum_put,
6092         },
6093         { } /* end */
6094 };
6095
6096 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
6097         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6098         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6099         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6100         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6101         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6102         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6103         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6104         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6105         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6106         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6107         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6108         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6109         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6110         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6111         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6112         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6113         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6114         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6115         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6116         {
6117                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6118                 /* .name = "Capture Source", */
6119                 .name = "Input Source",
6120                 .count = 2,
6121                 .info = alc883_mux_enum_info,
6122                 .get = alc883_mux_enum_get,
6123                 .put = alc883_mux_enum_put,
6124         },
6125         { } /* end */
6126 };
6127
6128 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
6129         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6130         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6131         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6132         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6133         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6134         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6135         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6136         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6137         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6138         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6139         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6140         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6141         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6142         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6143         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6144         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6145         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6146         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6147         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6148         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6149         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6150         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6151         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6152         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6153         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6154         {
6155                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6156                 /* .name = "Capture Source", */
6157                 .name = "Input Source",
6158                 .count = 2,
6159                 .info = alc883_mux_enum_info,
6160                 .get = alc883_mux_enum_get,
6161                 .put = alc883_mux_enum_put,
6162         },
6163         { } /* end */
6164 };
6165
6166 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
6167         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6168         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6169         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6170         HDA_CODEC_MUTE("Surround Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6171         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6172         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6173         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x16, 1, 0x0, HDA_OUTPUT),
6174         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
6175         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6176         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6177         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6178         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6179         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6180         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6181         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6182         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6183         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6184         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6185         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6186         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6187         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6188         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6189         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6190
6191         {
6192                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6193                 /* .name = "Capture Source", */
6194                 .name = "Input Source",
6195                 .count = 1,
6196                 .info = alc883_mux_enum_info,
6197                 .get = alc883_mux_enum_get,
6198                 .put = alc883_mux_enum_put,
6199         },
6200         { } /* end */
6201 };
6202
6203 static struct snd_kcontrol_new alc883_tagra_mixer[] = {
6204         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6205         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6206         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6207         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6208         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6209         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6210         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6211         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6212         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6213         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6214         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6215         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6216         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6217         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6218         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6219         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6220         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6221         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6222         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6223         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6224         {
6225                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6226                 /* .name = "Capture Source", */
6227                 .name = "Input Source",
6228                 .count = 2,
6229                 .info = alc883_mux_enum_info,
6230                 .get = alc883_mux_enum_get,
6231                 .put = alc883_mux_enum_put,
6232         },
6233         { } /* end */
6234 };
6235
6236 static struct snd_kcontrol_new alc883_tagra_2ch_mixer[] = {
6237         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6238         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6239         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6240         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6241         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6242         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6243         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6244         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6245         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6246         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6247         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6248         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6249         {
6250                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6251                 /* .name = "Capture Source", */
6252                 .name = "Input Source",
6253                 .count = 2,
6254                 .info = alc883_mux_enum_info,
6255                 .get = alc883_mux_enum_get,
6256                 .put = alc883_mux_enum_put,
6257         },
6258         { } /* end */
6259 };
6260
6261 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
6262         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6263         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6264         HDA_CODEC_VOLUME("iSpeaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6265         HDA_BIND_MUTE("iSpeaker Playback Switch", 0x0d, 2, HDA_INPUT),
6266         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6267         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6268         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6269         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6270         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6271         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6272         {
6273                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6274                 /* .name = "Capture Source", */
6275                 .name = "Input Source",
6276                 .count = 1,
6277                 .info = alc883_mux_enum_info,
6278                 .get = alc883_mux_enum_get,
6279                 .put = alc883_mux_enum_put,
6280         },
6281         { } /* end */
6282 };
6283
6284 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
6285         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6286         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
6287         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6288         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6289         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6290         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6291         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6292         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6293         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6294         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6295         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6296         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6297         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6298         {
6299                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6300                 /* .name = "Capture Source", */
6301                 .name = "Input Source",
6302                 .count = 2,
6303                 .info = alc883_mux_enum_info,
6304                 .get = alc883_mux_enum_get,
6305                 .put = alc883_mux_enum_put,
6306         },
6307         { } /* end */
6308 };
6309
6310 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
6311         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6312         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6313         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6314         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6315         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6316         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6317         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6318         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6319         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6320         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6321         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6322         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6323         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6324         {
6325                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6326                 /* .name = "Capture Source", */
6327                 .name = "Input Source",
6328                 .count = 2,
6329                 .info = alc883_mux_enum_info,
6330                 .get = alc883_mux_enum_get,
6331                 .put = alc883_mux_enum_put,
6332         },
6333         { } /* end */
6334 };      
6335
6336 static struct snd_kcontrol_new alc888_6st_hp_mixer[] = {
6337         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6338         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6339         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
6340         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
6341         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
6342         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
6343         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
6344         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
6345         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6346         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6347         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6348         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6349         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6350         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6351         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6352         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6353         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6354         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6355         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6356         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6357         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6358         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6359         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6360         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6361         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6362         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6363         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6364         {
6365                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6366                 /* .name = "Capture Source", */
6367                 .name = "Input Source",
6368                 .count = 2,
6369                 .info = alc883_mux_enum_info,
6370                 .get = alc883_mux_enum_get,
6371                 .put = alc883_mux_enum_put,
6372         },
6373         { } /* end */
6374 };
6375
6376 static struct snd_kcontrol_new alc888_3st_hp_mixer[] = {
6377         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6378         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6379         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
6380         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
6381         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
6382         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
6383         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
6384         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
6385         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6386         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6387         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6388         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6389         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6390         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6391         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6392         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6393         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6394         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6395         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6396         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6397         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6398         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6399         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6400         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6401         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6402         {
6403                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6404                 /* .name = "Capture Source", */
6405                 .name = "Input Source",
6406                 .count = 2,
6407                 .info = alc883_mux_enum_info,
6408                 .get = alc883_mux_enum_get,
6409                 .put = alc883_mux_enum_put,
6410         },
6411         { } /* end */
6412 };
6413
6414 static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
6415         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6416         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6417         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6418         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6419         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6420         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6421         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6422         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6423         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6424         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6425         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6426         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6427         {
6428                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6429                 /* .name = "Capture Source", */
6430                 .name = "Input Source",
6431                 .count = 2,
6432                 .info = alc883_mux_enum_info,
6433                 .get = alc883_mux_enum_get,
6434                 .put = alc883_mux_enum_put,
6435         },
6436         { } /* end */
6437 };
6438
6439 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
6440         {
6441                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6442                 .name = "Channel Mode",
6443                 .info = alc_ch_mode_info,
6444                 .get = alc_ch_mode_get,
6445                 .put = alc_ch_mode_put,
6446         },
6447         { } /* end */
6448 };
6449
6450 static struct hda_verb alc883_init_verbs[] = {
6451         /* ADC1: mute amp left and right */
6452         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6453         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6454         /* ADC2: mute amp left and right */
6455         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6456         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6457         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6458         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6459         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6460         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6461         /* Rear mixer */
6462         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6463         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6464         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6465         /* CLFE mixer */
6466         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6467         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6468         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6469         /* Side mixer */
6470         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6471         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6472         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6473
6474         /* mute analog input loopbacks */
6475         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6476         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6477         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6478         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6479         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6480
6481         /* Front Pin: output 0 (0x0c) */
6482         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6483         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6484         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6485         /* Rear Pin: output 1 (0x0d) */
6486         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6487         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6488         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
6489         /* CLFE Pin: output 2 (0x0e) */
6490         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6491         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6492         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
6493         /* Side Pin: output 3 (0x0f) */
6494         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6495         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6496         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
6497         /* Mic (rear) pin: input vref at 80% */
6498         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6499         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6500         /* Front Mic pin: input vref at 80% */
6501         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6502         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6503         /* Line In pin: input */
6504         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6505         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6506         /* Line-2 In: Headphone output (output 0 - 0x0c) */
6507         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6508         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6509         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
6510         /* CD pin widget for input */
6511         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6512
6513         /* FIXME: use matrix-type input source selection */
6514         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6515         /* Input mixer2 */
6516         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6517         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6518         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6519         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
6520         /* Input mixer3 */
6521         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6522         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6523         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6524         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
6525         { }
6526 };
6527
6528 static struct hda_verb alc883_tagra_verbs[] = {
6529         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6530         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6531
6532         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6533         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6534         
6535         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6536         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6537         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6538
6539         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6540         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6541         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
6542         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
6543
6544         { } /* end */
6545 };
6546
6547 static struct hda_verb alc883_lenovo_101e_verbs[] = {
6548         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6549         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
6550         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
6551         { } /* end */
6552 };
6553
6554 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
6555         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6556         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6557         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6558         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6559         { } /* end */
6560 };
6561
6562 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
6563         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6564         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6565         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6566         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
6567         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
6568         { } /* end */
6569 };
6570
6571 static struct hda_verb alc883_haier_w66_verbs[] = {
6572         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6573         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6574
6575         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6576
6577         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
6578         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6579         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6580         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6581         { } /* end */
6582 };
6583
6584 static struct hda_verb alc888_6st_hp_verbs[] = {
6585         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
6586         {0x15, AC_VERB_SET_CONNECT_SEL, 0x02},  /* Rear : output 2 (0x0e) */
6587         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* CLFE : output 1 (0x0d) */
6588         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},  /* Side : output 3 (0x0f) */
6589         { }
6590 };
6591
6592 static struct hda_verb alc888_3st_hp_verbs[] = {
6593         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
6594         {0x18, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
6595         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
6596         { }
6597 };
6598
6599 static struct hda_verb alc888_3st_hp_2ch_init[] = {
6600         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6601         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6602         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6603         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6604         { }
6605 };
6606
6607 static struct hda_verb alc888_3st_hp_6ch_init[] = {
6608         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6609         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6610         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6611         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6612         { }
6613 };
6614
6615 static struct hda_channel_mode alc888_3st_hp_modes[2] = {
6616         { 2, alc888_3st_hp_2ch_init },
6617         { 6, alc888_3st_hp_6ch_init },
6618 };
6619
6620 /* toggle front-jack and RCA according to the hp-jack state */
6621 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
6622 {
6623         unsigned int present;
6624  
6625         present = snd_hda_codec_read(codec, 0x1b, 0,
6626                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6627         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
6628                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6629         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
6630                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6631 }
6632
6633 /* toggle RCA according to the front-jack state */
6634 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
6635 {
6636         unsigned int present;
6637  
6638         present = snd_hda_codec_read(codec, 0x14, 0,
6639                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6640         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
6641                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6642 }
6643
6644 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
6645                                              unsigned int res)
6646 {
6647         if ((res >> 26) == ALC880_HP_EVENT)
6648                 alc888_lenovo_ms7195_front_automute(codec);
6649         if ((res >> 26) == ALC880_FRONT_EVENT)
6650                 alc888_lenovo_ms7195_rca_automute(codec);
6651 }
6652
6653 static struct hda_verb alc883_medion_md2_verbs[] = {
6654         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6655         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6656
6657         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6658
6659         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6660         { } /* end */
6661 };
6662
6663 /* toggle speaker-output according to the hp-jack state */
6664 static void alc883_medion_md2_automute(struct hda_codec *codec)
6665 {
6666         unsigned int present;
6667  
6668         present = snd_hda_codec_read(codec, 0x14, 0,
6669                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6670         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
6671                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6672 }
6673
6674 static void alc883_medion_md2_unsol_event(struct hda_codec *codec,
6675                                           unsigned int res)
6676 {
6677         if ((res >> 26) == ALC880_HP_EVENT)
6678                 alc883_medion_md2_automute(codec);
6679 }
6680
6681 /* toggle speaker-output according to the hp-jack state */
6682 static void alc883_tagra_automute(struct hda_codec *codec)
6683 {
6684         unsigned int present;
6685         unsigned char bits;
6686
6687         present = snd_hda_codec_read(codec, 0x14, 0,
6688                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6689         bits = present ? HDA_AMP_MUTE : 0;
6690         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
6691                                  HDA_AMP_MUTE, bits);
6692         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
6693                                   present ? 1 : 3);
6694 }
6695
6696 static void alc883_tagra_unsol_event(struct hda_codec *codec, unsigned int res)
6697 {
6698         if ((res >> 26) == ALC880_HP_EVENT)
6699                 alc883_tagra_automute(codec);
6700 }
6701
6702 static void alc883_haier_w66_automute(struct hda_codec *codec)
6703 {
6704         unsigned int present;
6705         unsigned char bits;
6706
6707         present = snd_hda_codec_read(codec, 0x1b, 0,
6708                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6709         bits = present ? 0x80 : 0;
6710         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
6711                                  0x80, bits);
6712 }
6713
6714 static void alc883_haier_w66_unsol_event(struct hda_codec *codec,
6715                                          unsigned int res)
6716 {
6717         if ((res >> 26) == ALC880_HP_EVENT)
6718                 alc883_haier_w66_automute(codec);
6719 }
6720
6721 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
6722 {
6723         unsigned int present;
6724         unsigned char bits;
6725
6726         present = snd_hda_codec_read(codec, 0x14, 0,
6727                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6728         bits = present ? HDA_AMP_MUTE : 0;
6729         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
6730                                  HDA_AMP_MUTE, bits);
6731 }
6732
6733 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
6734 {
6735         unsigned int present;
6736         unsigned char bits;
6737
6738         present = snd_hda_codec_read(codec, 0x1b, 0,
6739                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6740         bits = present ? HDA_AMP_MUTE : 0;
6741         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
6742                                  HDA_AMP_MUTE, bits);
6743         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
6744                                  HDA_AMP_MUTE, bits);
6745 }
6746
6747 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
6748                                            unsigned int res)
6749 {
6750         if ((res >> 26) == ALC880_HP_EVENT)
6751                 alc883_lenovo_101e_all_automute(codec);
6752         if ((res >> 26) == ALC880_FRONT_EVENT)
6753                 alc883_lenovo_101e_ispeaker_automute(codec);
6754 }
6755
6756 /* toggle speaker-output according to the hp-jack state */
6757 static void alc883_acer_aspire_automute(struct hda_codec *codec)
6758 {
6759         unsigned int present;
6760  
6761         present = snd_hda_codec_read(codec, 0x14, 0,
6762                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6763         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
6764                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6765         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
6766                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6767 }
6768
6769 static void alc883_acer_aspire_unsol_event(struct hda_codec *codec,
6770                                            unsigned int res)
6771 {
6772         if ((res >> 26) == ALC880_HP_EVENT)
6773                 alc883_acer_aspire_automute(codec);
6774 }
6775
6776 static struct hda_verb alc883_acer_eapd_verbs[] = {
6777         /* HP Pin: output 0 (0x0c) */
6778         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6779         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6780         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6781         /* Front Pin: output 0 (0x0c) */
6782         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6783         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6784         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6785         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
6786         /* eanable EAPD on medion laptop */
6787         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
6788         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
6789         /* enable unsolicited event */
6790         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6791         { }
6792 };
6793
6794 /*
6795  * generic initialization of ADC, input mixers and output mixers
6796  */
6797 static struct hda_verb alc883_auto_init_verbs[] = {
6798         /*
6799          * Unmute ADC0-2 and set the default input to mic-in
6800          */
6801         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6802         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6803         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6804         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6805
6806         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
6807          * mixer widget
6808          * Note: PASD motherboards uses the Line In 2 as the input for
6809          * front panel mic (mic 2)
6810          */
6811         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
6812         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6813         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6814         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6815         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6816         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6817
6818         /*
6819          * Set up output mixers (0x0c - 0x0f)
6820          */
6821         /* set vol=0 to output mixers */
6822         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6823         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6824         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6825         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6826         /* set up input amps for analog loopback */
6827         /* Amp Indices: DAC = 0, mixer = 1 */
6828         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6829         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6830         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6831         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6832         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6833         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6834         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6835         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6836         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6837         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6838
6839         /* FIXME: use matrix-type input source selection */
6840         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6841         /* Input mixer1 */
6842         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6843         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6844         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6845         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
6846         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
6847         /* Input mixer2 */
6848         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6849         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6850         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6851         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
6852         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
6853
6854         { }
6855 };
6856
6857 /* capture mixer elements */
6858 static struct snd_kcontrol_new alc883_capture_mixer[] = {
6859         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6860         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6861         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6862         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6863         {
6864                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6865                 /* The multiple "Capture Source" controls confuse alsamixer
6866                  * So call somewhat different..
6867                  * FIXME: the controls appear in the "playback" view!
6868                  */
6869                 /* .name = "Capture Source", */
6870                 .name = "Input Source",
6871                 .count = 2,
6872                 .info = alc882_mux_enum_info,
6873                 .get = alc882_mux_enum_get,
6874                 .put = alc882_mux_enum_put,
6875         },
6876         { } /* end */
6877 };
6878
6879 #ifdef CONFIG_SND_HDA_POWER_SAVE
6880 #define alc883_loopbacks        alc880_loopbacks
6881 #endif
6882
6883 /* pcm configuration: identiacal with ALC880 */
6884 #define alc883_pcm_analog_playback      alc880_pcm_analog_playback
6885 #define alc883_pcm_analog_capture       alc880_pcm_analog_capture
6886 #define alc883_pcm_digital_playback     alc880_pcm_digital_playback
6887 #define alc883_pcm_digital_capture      alc880_pcm_digital_capture
6888
6889 /*
6890  * configuration and preset
6891  */
6892 static const char *alc883_models[ALC883_MODEL_LAST] = {
6893         [ALC883_3ST_2ch_DIG]    = "3stack-dig",
6894         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
6895         [ALC883_3ST_6ch]        = "3stack-6ch",
6896         [ALC883_6ST_DIG]        = "6stack-dig",
6897         [ALC883_TARGA_DIG]      = "targa-dig",
6898         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
6899         [ALC883_ACER]           = "acer",
6900         [ALC883_ACER_ASPIRE]    = "acer-aspire",
6901         [ALC883_MEDION]         = "medion",
6902         [ALC883_MEDION_MD2]     = "medion-md2",
6903         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
6904         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
6905         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
6906         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
6907         [ALC883_HAIER_W66]      = "haier-w66",
6908         [ALC888_6ST_HP]         = "6stack-hp",
6909         [ALC888_3ST_HP]         = "3stack-hp",
6910         [ALC883_AUTO]           = "auto",
6911 };
6912
6913 static struct snd_pci_quirk alc883_cfg_tbl[] = {
6914         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG),
6915         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
6916         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
6917         SND_PCI_QUIRK(0x1558, 0, "Clevo laptop", ALC883_LAPTOP_EAPD),
6918         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
6919         SND_PCI_QUIRK(0x1458, 0xa002, "MSI", ALC883_6ST_DIG),
6920         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
6921         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
6922         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
6923         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
6924         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
6925         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
6926         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
6927         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
6928         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
6929         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
6930         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
6931         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
6932         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
6933         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
6934         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
6935         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
6936         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
6937         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
6938         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
6939         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
6940         SND_PCI_QUIRK(0x1025, 0, "Acer laptop", ALC883_ACER),
6941         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
6942         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
6943         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
6944         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
6945         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
6946         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
6947         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
6948         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC888_6ST_HP),
6949         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
6950         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
6951         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
6952         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
6953         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
6954         {}
6955 };
6956
6957 static struct alc_config_preset alc883_presets[] = {
6958         [ALC883_3ST_2ch_DIG] = {
6959                 .mixers = { alc883_3ST_2ch_mixer },
6960                 .init_verbs = { alc883_init_verbs },
6961                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
6962                 .dac_nids = alc883_dac_nids,
6963                 .dig_out_nid = ALC883_DIGOUT_NID,
6964                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
6965                 .adc_nids = alc883_adc_nids,
6966                 .dig_in_nid = ALC883_DIGIN_NID,
6967                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
6968                 .channel_mode = alc883_3ST_2ch_modes,
6969                 .input_mux = &alc883_capture_source,
6970         },
6971         [ALC883_3ST_6ch_DIG] = {
6972                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
6973                 .init_verbs = { alc883_init_verbs },
6974                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
6975                 .dac_nids = alc883_dac_nids,
6976                 .dig_out_nid = ALC883_DIGOUT_NID,
6977                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
6978                 .adc_nids = alc883_adc_nids,
6979                 .dig_in_nid = ALC883_DIGIN_NID,
6980                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
6981                 .channel_mode = alc883_3ST_6ch_modes,
6982                 .need_dac_fix = 1,
6983                 .input_mux = &alc883_capture_source,
6984         },
6985         [ALC883_3ST_6ch] = {
6986                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
6987                 .init_verbs = { alc883_init_verbs },
6988                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
6989                 .dac_nids = alc883_dac_nids,
6990                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
6991                 .adc_nids = alc883_adc_nids,
6992                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
6993                 .channel_mode = alc883_3ST_6ch_modes,
6994                 .need_dac_fix = 1,
6995                 .input_mux = &alc883_capture_source,
6996         },
6997         [ALC883_6ST_DIG] = {
6998                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
6999                 .init_verbs = { alc883_init_verbs },
7000                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7001                 .dac_nids = alc883_dac_nids,
7002                 .dig_out_nid = ALC883_DIGOUT_NID,
7003                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7004                 .adc_nids = alc883_adc_nids,
7005                 .dig_in_nid = ALC883_DIGIN_NID,
7006                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7007                 .channel_mode = alc883_sixstack_modes,
7008                 .input_mux = &alc883_capture_source,
7009         },
7010         [ALC883_TARGA_DIG] = {
7011                 .mixers = { alc883_tagra_mixer, alc883_chmode_mixer },
7012                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
7013                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7014                 .dac_nids = alc883_dac_nids,
7015                 .dig_out_nid = ALC883_DIGOUT_NID,
7016                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7017                 .adc_nids = alc883_adc_nids,
7018                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7019                 .channel_mode = alc883_3ST_6ch_modes,
7020                 .need_dac_fix = 1,
7021                 .input_mux = &alc883_capture_source,
7022                 .unsol_event = alc883_tagra_unsol_event,
7023                 .init_hook = alc883_tagra_automute,
7024         },
7025         [ALC883_TARGA_2ch_DIG] = {
7026                 .mixers = { alc883_tagra_2ch_mixer},
7027                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
7028                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7029                 .dac_nids = alc883_dac_nids,
7030                 .dig_out_nid = ALC883_DIGOUT_NID,
7031                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7032                 .adc_nids = alc883_adc_nids,
7033                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7034                 .channel_mode = alc883_3ST_2ch_modes,
7035                 .input_mux = &alc883_capture_source,
7036                 .unsol_event = alc883_tagra_unsol_event,
7037                 .init_hook = alc883_tagra_automute,
7038         },
7039         [ALC883_ACER] = {
7040                 .mixers = { alc883_base_mixer },
7041                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
7042                  * and the headphone jack.  Turn this on and rely on the
7043                  * standard mute methods whenever the user wants to turn
7044                  * these outputs off.
7045                  */
7046                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
7047                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7048                 .dac_nids = alc883_dac_nids,
7049                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7050                 .adc_nids = alc883_adc_nids,
7051                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7052                 .channel_mode = alc883_3ST_2ch_modes,
7053                 .input_mux = &alc883_capture_source,
7054         },
7055         [ALC883_ACER_ASPIRE] = {
7056                 .mixers = { alc883_acer_aspire_mixer },
7057                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
7058                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7059                 .dac_nids = alc883_dac_nids,
7060                 .dig_out_nid = ALC883_DIGOUT_NID,
7061                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7062                 .adc_nids = alc883_adc_nids,
7063                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7064                 .channel_mode = alc883_3ST_2ch_modes,
7065                 .input_mux = &alc883_capture_source,
7066                 .unsol_event = alc883_acer_aspire_unsol_event,
7067                 .init_hook = alc883_acer_aspire_automute,
7068         },
7069         [ALC883_MEDION] = {
7070                 .mixers = { alc883_fivestack_mixer,
7071                             alc883_chmode_mixer },
7072                 .init_verbs = { alc883_init_verbs,
7073                                 alc883_medion_eapd_verbs },
7074                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7075                 .dac_nids = alc883_dac_nids,
7076                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7077                 .adc_nids = alc883_adc_nids,
7078                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7079                 .channel_mode = alc883_sixstack_modes,
7080                 .input_mux = &alc883_capture_source,
7081         },
7082         [ALC883_MEDION_MD2] = {
7083                 .mixers = { alc883_medion_md2_mixer},
7084                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
7085                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7086                 .dac_nids = alc883_dac_nids,
7087                 .dig_out_nid = ALC883_DIGOUT_NID,
7088                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7089                 .adc_nids = alc883_adc_nids,
7090                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7091                 .channel_mode = alc883_3ST_2ch_modes,
7092                 .input_mux = &alc883_capture_source,
7093                 .unsol_event = alc883_medion_md2_unsol_event,
7094                 .init_hook = alc883_medion_md2_automute,
7095         },      
7096         [ALC883_LAPTOP_EAPD] = {
7097                 .mixers = { alc883_base_mixer },
7098                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
7099                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7100                 .dac_nids = alc883_dac_nids,
7101                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7102                 .adc_nids = alc883_adc_nids,
7103                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7104                 .channel_mode = alc883_3ST_2ch_modes,
7105                 .input_mux = &alc883_capture_source,
7106         },
7107         [ALC883_LENOVO_101E_2ch] = {
7108                 .mixers = { alc883_lenovo_101e_2ch_mixer},
7109                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
7110                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7111                 .dac_nids = alc883_dac_nids,
7112                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7113                 .adc_nids = alc883_adc_nids,
7114                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7115                 .channel_mode = alc883_3ST_2ch_modes,
7116                 .input_mux = &alc883_lenovo_101e_capture_source,
7117                 .unsol_event = alc883_lenovo_101e_unsol_event,
7118                 .init_hook = alc883_lenovo_101e_all_automute,
7119         },
7120         [ALC883_LENOVO_NB0763] = {
7121                 .mixers = { alc883_lenovo_nb0763_mixer },
7122                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
7123                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7124                 .dac_nids = alc883_dac_nids,
7125                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7126                 .adc_nids = alc883_adc_nids,
7127                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7128                 .channel_mode = alc883_3ST_2ch_modes,
7129                 .need_dac_fix = 1,
7130                 .input_mux = &alc883_lenovo_nb0763_capture_source,
7131                 .unsol_event = alc883_medion_md2_unsol_event,
7132                 .init_hook = alc883_medion_md2_automute,
7133         },
7134         [ALC888_LENOVO_MS7195_DIG] = {
7135                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
7136                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
7137                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7138                 .dac_nids = alc883_dac_nids,
7139                 .dig_out_nid = ALC883_DIGOUT_NID,
7140                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7141                 .adc_nids = alc883_adc_nids,
7142                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7143                 .channel_mode = alc883_3ST_6ch_modes,
7144                 .need_dac_fix = 1,
7145                 .input_mux = &alc883_capture_source,
7146                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
7147                 .init_hook = alc888_lenovo_ms7195_front_automute,
7148         },
7149         [ALC883_HAIER_W66] = {
7150                 .mixers = { alc883_tagra_2ch_mixer},
7151                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
7152                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7153                 .dac_nids = alc883_dac_nids,
7154                 .dig_out_nid = ALC883_DIGOUT_NID,
7155                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7156                 .adc_nids = alc883_adc_nids,
7157                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7158                 .channel_mode = alc883_3ST_2ch_modes,
7159                 .input_mux = &alc883_capture_source,
7160                 .unsol_event = alc883_haier_w66_unsol_event,
7161                 .init_hook = alc883_haier_w66_automute,
7162         },      
7163         [ALC888_6ST_HP] = {
7164                 .mixers = { alc888_6st_hp_mixer, alc883_chmode_mixer },
7165                 .init_verbs = { alc883_init_verbs, alc888_6st_hp_verbs },
7166                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7167                 .dac_nids = alc883_dac_nids,
7168                 .dig_out_nid = ALC883_DIGOUT_NID,
7169                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7170                 .adc_nids = alc883_adc_nids,
7171                 .dig_in_nid = ALC883_DIGIN_NID,
7172                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7173                 .channel_mode = alc883_sixstack_modes,
7174                 .input_mux = &alc883_capture_source,
7175         },
7176         [ALC888_3ST_HP] = {
7177                 .mixers = { alc888_3st_hp_mixer, alc883_chmode_mixer },
7178                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
7179                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7180                 .dac_nids = alc883_dac_nids,
7181                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7182                 .adc_nids = alc883_adc_nids,
7183                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
7184                 .channel_mode = alc888_3st_hp_modes,
7185                 .need_dac_fix = 1,
7186                 .input_mux = &alc883_capture_source,
7187         },
7188 };
7189
7190
7191 /*
7192  * BIOS auto configuration
7193  */
7194 static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
7195                                               hda_nid_t nid, int pin_type,
7196                                               int dac_idx)
7197 {
7198         /* set as output */
7199         struct alc_spec *spec = codec->spec;
7200         int idx;
7201
7202         if (spec->multiout.dac_nids[dac_idx] == 0x25)
7203                 idx = 4;
7204         else
7205                 idx = spec->multiout.dac_nids[dac_idx] - 2;
7206
7207         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
7208                             pin_type);
7209         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
7210                             AMP_OUT_UNMUTE);
7211         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
7212
7213 }
7214
7215 static void alc883_auto_init_multi_out(struct hda_codec *codec)
7216 {
7217         struct alc_spec *spec = codec->spec;
7218         int i;
7219
7220         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
7221         for (i = 0; i <= HDA_SIDE; i++) {
7222                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
7223                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
7224                 if (nid)
7225                         alc883_auto_set_output_and_unmute(codec, nid, pin_type,
7226                                                           i);
7227         }
7228 }
7229
7230 static void alc883_auto_init_hp_out(struct hda_codec *codec)
7231 {
7232         struct alc_spec *spec = codec->spec;
7233         hda_nid_t pin;
7234
7235         pin = spec->autocfg.hp_pins[0];
7236         if (pin) /* connect to front */
7237                 /* use dac 0 */
7238                 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
7239 }
7240
7241 #define alc883_is_input_pin(nid)        alc880_is_input_pin(nid)
7242 #define ALC883_PIN_CD_NID               ALC880_PIN_CD_NID
7243
7244 static void alc883_auto_init_analog_input(struct hda_codec *codec)
7245 {
7246         struct alc_spec *spec = codec->spec;
7247         int i;
7248
7249         for (i = 0; i < AUTO_PIN_LAST; i++) {
7250                 hda_nid_t nid = spec->autocfg.input_pins[i];
7251                 if (alc883_is_input_pin(nid)) {
7252                         snd_hda_codec_write(codec, nid, 0,
7253                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
7254                                             (i <= AUTO_PIN_FRONT_MIC ?
7255                                              PIN_VREF80 : PIN_IN));
7256                         if (nid != ALC883_PIN_CD_NID)
7257                                 snd_hda_codec_write(codec, nid, 0,
7258                                                     AC_VERB_SET_AMP_GAIN_MUTE,
7259                                                     AMP_OUT_MUTE);
7260                 }
7261         }
7262 }
7263
7264 /* almost identical with ALC880 parser... */
7265 static int alc883_parse_auto_config(struct hda_codec *codec)
7266 {
7267         struct alc_spec *spec = codec->spec;
7268         int err = alc880_parse_auto_config(codec);
7269
7270         if (err < 0)
7271                 return err;
7272         else if (err > 0)
7273                 /* hack - override the init verbs */
7274                 spec->init_verbs[0] = alc883_auto_init_verbs;
7275         spec->mixers[spec->num_mixers] = alc883_capture_mixer;
7276         spec->num_mixers++;
7277         return err;
7278 }
7279
7280 /* additional initialization for auto-configuration model */
7281 static void alc883_auto_init(struct hda_codec *codec)
7282 {
7283         alc883_auto_init_multi_out(codec);
7284         alc883_auto_init_hp_out(codec);
7285         alc883_auto_init_analog_input(codec);
7286 }
7287
7288 static int patch_alc883(struct hda_codec *codec)
7289 {
7290         struct alc_spec *spec;
7291         int err, board_config;
7292
7293         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
7294         if (spec == NULL)
7295                 return -ENOMEM;
7296
7297         codec->spec = spec;
7298
7299         board_config = snd_hda_check_board_config(codec, ALC883_MODEL_LAST,
7300                                                   alc883_models,
7301                                                   alc883_cfg_tbl);
7302         if (board_config < 0) {
7303                 printk(KERN_INFO "hda_codec: Unknown model for ALC883, "
7304                        "trying auto-probe from BIOS...\n");
7305                 board_config = ALC883_AUTO;
7306         }
7307
7308         if (board_config == ALC883_AUTO) {
7309                 /* automatic parse from the BIOS config */
7310                 err = alc883_parse_auto_config(codec);
7311                 if (err < 0) {
7312                         alc_free(codec);
7313                         return err;
7314                 } else if (!err) {
7315                         printk(KERN_INFO
7316                                "hda_codec: Cannot set up configuration "
7317                                "from BIOS.  Using base mode...\n");
7318                         board_config = ALC883_3ST_2ch_DIG;
7319                 }
7320         }
7321
7322         if (board_config != ALC883_AUTO)
7323                 setup_preset(spec, &alc883_presets[board_config]);
7324
7325         spec->stream_name_analog = "ALC883 Analog";
7326         spec->stream_analog_playback = &alc883_pcm_analog_playback;
7327         spec->stream_analog_capture = &alc883_pcm_analog_capture;
7328
7329         spec->stream_name_digital = "ALC883 Digital";
7330         spec->stream_digital_playback = &alc883_pcm_digital_playback;
7331         spec->stream_digital_capture = &alc883_pcm_digital_capture;
7332
7333         if (!spec->adc_nids && spec->input_mux) {
7334                 spec->adc_nids = alc883_adc_nids;
7335                 spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
7336         }
7337
7338         codec->patch_ops = alc_patch_ops;
7339         if (board_config == ALC883_AUTO)
7340                 spec->init_hook = alc883_auto_init;
7341 #ifdef CONFIG_SND_HDA_POWER_SAVE
7342         if (!spec->loopback.amplist)
7343                 spec->loopback.amplist = alc883_loopbacks;
7344 #endif
7345
7346         return 0;
7347 }
7348
7349 /*
7350  * ALC262 support
7351  */
7352
7353 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
7354 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
7355
7356 #define alc262_dac_nids         alc260_dac_nids
7357 #define alc262_adc_nids         alc882_adc_nids
7358 #define alc262_adc_nids_alt     alc882_adc_nids_alt
7359
7360 #define alc262_modes            alc260_modes
7361 #define alc262_capture_source   alc882_capture_source
7362
7363 static struct snd_kcontrol_new alc262_base_mixer[] = {
7364         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7365         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7366         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7367         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7368         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7369         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7370         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7371         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7372         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7373         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
7374         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
7375         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7376         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
7377            HDA_CODEC_MUTE("PC Beelp Playback Switch", 0x0b, 0x05, HDA_INPUT), */
7378         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
7379         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7380         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7381         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
7382         { } /* end */
7383 };
7384
7385 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
7386         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7387         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7388         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7389         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7390         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7391         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7392         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7393         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7394         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7395         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
7396         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
7397         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7398         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
7399            HDA_CODEC_MUTE("PC Beelp Playback Switch", 0x0b, 0x05, HDA_INPUT), */
7400         /*HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),*/
7401         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7402         { } /* end */
7403 };
7404
7405 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
7406         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7407         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7408         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7409         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7410         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
7411
7412         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7413         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7414         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7415         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
7416         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
7417         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7418         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7419         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7420         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7421         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7422         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
7423         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
7424         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
7425         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
7426         { } /* end */
7427 };
7428
7429 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
7430         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7431         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7432         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7433         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7434         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7435         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
7436         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
7437         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
7438         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
7439         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
7440         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
7441         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7442         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7443         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
7444         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
7445         { } /* end */
7446 };
7447
7448 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
7449         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7450         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7451         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
7452         { } /* end */
7453 };
7454
7455 static struct hda_bind_ctls alc262_sony_bind_sw = {
7456         .ops = &snd_hda_bind_sw,
7457         .values = {
7458                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
7459                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
7460                 0,
7461         },
7462 };
7463
7464 static struct snd_kcontrol_new alc262_sony_mixer[] = {
7465         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7466         HDA_BIND_SW("Front Playback Switch", &alc262_sony_bind_sw),
7467         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7468         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7469         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
7470         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
7471         { } /* end */
7472 };
7473
7474 static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
7475         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7476         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7477         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7478         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7479         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7480         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
7481         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
7482         { } /* end */
7483 };
7484
7485 #define alc262_capture_mixer            alc882_capture_mixer
7486 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
7487
7488 /*
7489  * generic initialization of ADC, input mixers and output mixers
7490  */
7491 static struct hda_verb alc262_init_verbs[] = {
7492         /*
7493          * Unmute ADC0-2 and set the default input to mic-in
7494          */
7495         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
7496         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7497         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7498         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7499         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7500         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7501
7502         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
7503          * mixer widget
7504          * Note: PASD motherboards uses the Line In 2 as the input for
7505          * front panel mic (mic 2)
7506          */
7507         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
7508         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7509         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7510         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7511         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7512         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7513
7514         /*
7515          * Set up output mixers (0x0c - 0x0e)
7516          */
7517         /* set vol=0 to output mixers */
7518         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7519         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7520         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7521         /* set up input amps for analog loopback */
7522         /* Amp Indices: DAC = 0, mixer = 1 */
7523         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7524         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7525         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7526         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7527         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7528         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7529
7530         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
7531         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
7532         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
7533         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
7534         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
7535         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
7536
7537         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
7538         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
7539         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
7540         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
7541         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
7542         
7543         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7544         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7545         
7546         /* FIXME: use matrix-type input source selection */
7547         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7548         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
7549         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7550         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7551         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7552         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7553         /* Input mixer2 */
7554         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7555         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7556         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7557         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7558         /* Input mixer3 */
7559         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7560         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7561         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7562         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7563
7564         { }
7565 };
7566
7567 static struct hda_verb alc262_hippo_unsol_verbs[] = {
7568         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
7569         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7570         {}
7571 };
7572
7573 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
7574         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
7575         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7576         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
7577
7578         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
7579         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7580         {}
7581 };
7582
7583 static struct hda_verb alc262_sony_unsol_verbs[] = {
7584         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
7585         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7586         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
7587
7588         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
7589         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7590 };
7591
7592 /* mute/unmute internal speaker according to the hp jack and mute state */
7593 static void alc262_hippo_automute(struct hda_codec *codec)
7594 {
7595         struct alc_spec *spec = codec->spec;
7596         unsigned int mute;
7597         unsigned int present;
7598
7599         /* need to execute and sync at first */
7600         snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
7601         present = snd_hda_codec_read(codec, 0x15, 0,
7602                                      AC_VERB_GET_PIN_SENSE, 0);
7603         spec->jack_present = (present & 0x80000000) != 0;
7604         if (spec->jack_present) {
7605                 /* mute internal speaker */
7606                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7607                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
7608         } else {
7609                 /* unmute internal speaker if necessary */
7610                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
7611                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7612                                          HDA_AMP_MUTE, mute);
7613         }
7614 }
7615
7616 /* unsolicited event for HP jack sensing */
7617 static void alc262_hippo_unsol_event(struct hda_codec *codec,
7618                                        unsigned int res)
7619 {
7620         if ((res >> 26) != ALC880_HP_EVENT)
7621                 return;
7622         alc262_hippo_automute(codec);
7623 }
7624
7625 static void alc262_hippo1_automute(struct hda_codec *codec)
7626 {
7627         unsigned int mute;
7628         unsigned int present;
7629
7630         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
7631         present = snd_hda_codec_read(codec, 0x1b, 0,
7632                                      AC_VERB_GET_PIN_SENSE, 0);
7633         present = (present & 0x80000000) != 0;
7634         if (present) {
7635                 /* mute internal speaker */
7636                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7637                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
7638         } else {
7639                 /* unmute internal speaker if necessary */
7640                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
7641                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7642                                          HDA_AMP_MUTE, mute);
7643         }
7644 }
7645
7646 /* unsolicited event for HP jack sensing */
7647 static void alc262_hippo1_unsol_event(struct hda_codec *codec,
7648                                        unsigned int res)
7649 {
7650         if ((res >> 26) != ALC880_HP_EVENT)
7651                 return;
7652         alc262_hippo1_automute(codec);
7653 }
7654
7655 /*
7656  * fujitsu model
7657  *  0x14 = headphone/spdif-out, 0x15 = internal speaker
7658  */
7659
7660 #define ALC_HP_EVENT    0x37
7661
7662 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
7663         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
7664         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7665         {}
7666 };
7667
7668 static struct hda_input_mux alc262_fujitsu_capture_source = {
7669         .num_items = 2,
7670         .items = {
7671                 { "Mic", 0x0 },
7672                 { "CD", 0x4 },
7673         },
7674 };
7675
7676 static struct hda_input_mux alc262_HP_capture_source = {
7677         .num_items = 5,
7678         .items = {
7679                 { "Mic", 0x0 },
7680                 { "Front Mic", 0x3 },
7681                 { "Line", 0x2 },
7682                 { "CD", 0x4 },
7683                 { "AUX IN", 0x6 },
7684         },
7685 };
7686
7687 /* mute/unmute internal speaker according to the hp jack and mute state */
7688 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
7689 {
7690         struct alc_spec *spec = codec->spec;
7691         unsigned int mute;
7692
7693         if (force || !spec->sense_updated) {
7694                 unsigned int present;
7695                 /* need to execute and sync at first */
7696                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
7697                 present = snd_hda_codec_read(codec, 0x14, 0,
7698                                          AC_VERB_GET_PIN_SENSE, 0);
7699                 spec->jack_present = (present & 0x80000000) != 0;
7700                 spec->sense_updated = 1;
7701         }
7702         if (spec->jack_present) {
7703                 /* mute internal speaker */
7704                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7705                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
7706         } else {
7707                 /* unmute internal speaker if necessary */
7708                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
7709                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7710                                          HDA_AMP_MUTE, mute);
7711         }
7712 }
7713
7714 /* unsolicited event for HP jack sensing */
7715 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
7716                                        unsigned int res)
7717 {
7718         if ((res >> 26) != ALC_HP_EVENT)
7719                 return;
7720         alc262_fujitsu_automute(codec, 1);
7721 }
7722
7723 /* bind volumes of both NID 0x0c and 0x0d */
7724 static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
7725         .ops = &snd_hda_bind_vol,
7726         .values = {
7727                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
7728                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
7729                 0
7730         },
7731 };
7732
7733 /* bind hp and internal speaker mute (with plug check) */
7734 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
7735                                          struct snd_ctl_elem_value *ucontrol)
7736 {
7737         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
7738         long *valp = ucontrol->value.integer.value;
7739         int change;
7740
7741         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
7742                                           HDA_AMP_MUTE,
7743                                           valp[0] ? 0 : HDA_AMP_MUTE);
7744         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
7745                                            HDA_AMP_MUTE,
7746                                            valp[1] ? 0 : HDA_AMP_MUTE);
7747         if (change)
7748                 alc262_fujitsu_automute(codec, 0);
7749         return change;
7750 }
7751
7752 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
7753         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
7754         {
7755                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7756                 .name = "Master Playback Switch",
7757                 .info = snd_hda_mixer_amp_switch_info,
7758                 .get = snd_hda_mixer_amp_switch_get,
7759                 .put = alc262_fujitsu_master_sw_put,
7760                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
7761         },
7762         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7763         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7764         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7765         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7766         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7767         { } /* end */
7768 };
7769
7770 /* additional init verbs for Benq laptops */
7771 static struct hda_verb alc262_EAPD_verbs[] = {
7772         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7773         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
7774         {}
7775 };
7776
7777 static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
7778         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7779         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
7780
7781         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7782         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
7783         {}
7784 };
7785
7786 /* add playback controls from the parsed DAC table */
7787 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
7788                                              const struct auto_pin_cfg *cfg)
7789 {
7790         hda_nid_t nid;
7791         int err;
7792
7793         spec->multiout.num_dacs = 1;    /* only use one dac */
7794         spec->multiout.dac_nids = spec->private_dac_nids;
7795         spec->multiout.dac_nids[0] = 2;
7796
7797         nid = cfg->line_out_pins[0];
7798         if (nid) {
7799                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
7800                                   "Front Playback Volume",
7801                                   HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT));
7802                 if (err < 0)
7803                         return err;
7804                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
7805                                   "Front Playback Switch",
7806                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
7807                 if (err < 0)
7808                         return err;
7809         }
7810
7811         nid = cfg->speaker_pins[0];
7812         if (nid) {
7813                 if (nid == 0x16) {
7814                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
7815                                           "Speaker Playback Volume",
7816                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
7817                                                               HDA_OUTPUT));
7818                         if (err < 0)
7819                                 return err;
7820                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
7821                                           "Speaker Playback Switch",
7822                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
7823                                                               HDA_OUTPUT));
7824                         if (err < 0)
7825                                 return err;
7826                 } else {
7827                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
7828                                           "Speaker Playback Switch",
7829                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
7830                                                               HDA_OUTPUT));
7831                         if (err < 0)
7832                                 return err;
7833                 }
7834         }
7835         nid = cfg->hp_pins[0];
7836         if (nid) {
7837                 /* spec->multiout.hp_nid = 2; */
7838                 if (nid == 0x16) {
7839                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
7840                                           "Headphone Playback Volume",
7841                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
7842                                                               HDA_OUTPUT));
7843                         if (err < 0)
7844                                 return err;
7845                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
7846                                           "Headphone Playback Switch",
7847                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
7848                                                               HDA_OUTPUT));
7849                         if (err < 0)
7850                                 return err;
7851                 } else {
7852                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
7853                                           "Headphone Playback Switch",
7854                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
7855                                                               HDA_OUTPUT));
7856                         if (err < 0)
7857                                 return err;
7858                 }
7859         }
7860         return 0;
7861 }
7862
7863 /* identical with ALC880 */
7864 #define alc262_auto_create_analog_input_ctls \
7865         alc880_auto_create_analog_input_ctls
7866
7867 /*
7868  * generic initialization of ADC, input mixers and output mixers
7869  */
7870 static struct hda_verb alc262_volume_init_verbs[] = {
7871         /*
7872          * Unmute ADC0-2 and set the default input to mic-in
7873          */
7874         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
7875         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7876         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7877         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7878         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7879         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7880
7881         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
7882          * mixer widget
7883          * Note: PASD motherboards uses the Line In 2 as the input for
7884          * front panel mic (mic 2)
7885          */
7886         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
7887         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7888         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7889         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7890         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7891         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7892
7893         /*
7894          * Set up output mixers (0x0c - 0x0f)
7895          */
7896         /* set vol=0 to output mixers */
7897         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7898         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7899         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7900         
7901         /* set up input amps for analog loopback */
7902         /* Amp Indices: DAC = 0, mixer = 1 */
7903         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7904         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7905         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7906         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7907         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7908         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7909
7910         /* FIXME: use matrix-type input source selection */
7911         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7912         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
7913         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7914         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7915         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7916         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7917         /* Input mixer2 */
7918         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7919         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7920         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7921         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7922         /* Input mixer3 */
7923         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7924         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7925         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7926         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7927
7928         { }
7929 };
7930
7931 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
7932         /*
7933          * Unmute ADC0-2 and set the default input to mic-in
7934          */
7935         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
7936         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7937         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7938         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7939         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7940         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7941
7942         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
7943          * mixer widget
7944          * Note: PASD motherboards uses the Line In 2 as the input for
7945          * front panel mic (mic 2)
7946          */
7947         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
7948         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7949         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7950         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7951         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7952         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7953         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
7954         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
7955         
7956         /*
7957          * Set up output mixers (0x0c - 0x0e)
7958          */
7959         /* set vol=0 to output mixers */
7960         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7961         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7962         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7963
7964         /* set up input amps for analog loopback */
7965         /* Amp Indices: DAC = 0, mixer = 1 */
7966         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7967         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7968         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7969         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7970         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7971         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7972
7973         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
7974         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7975         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7976
7977         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7978         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7979
7980         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7981         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7982
7983         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
7984         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
7985         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
7986         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
7987         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
7988
7989         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
7990         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
7991         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
7992         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
7993         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
7994         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
7995
7996
7997         /* FIXME: use matrix-type input source selection */
7998         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7999         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
8000         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8001         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
8002         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
8003         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
8004         /* Input mixer2 */
8005         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8006         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
8007         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
8008         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
8009         /* Input mixer3 */
8010         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8011         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
8012         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
8013         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
8014
8015         { }
8016 };
8017
8018 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
8019         /*
8020          * Unmute ADC0-2 and set the default input to mic-in
8021          */
8022         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
8023         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8024         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8025         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8026         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8027         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8028
8029         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8030          * mixer widget
8031          * Note: PASD motherboards uses the Line In 2 as the input for front
8032          * panel mic (mic 2)
8033          */
8034         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8035         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8036         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8037         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8038         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8039         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8040         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
8041         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
8042         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
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
8051         /* set up input amps for analog loopback */
8052         /* Amp Indices: DAC = 0, mixer = 1 */
8053         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8054         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8055         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8056         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8057         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8058         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8059
8060
8061         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
8062         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
8063         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
8064         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
8065         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
8066         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
8067         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
8068
8069         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8070         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8071
8072         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8073         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
8074
8075         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
8076         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8077         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8078         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
8079         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8080         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8081
8082         /* FIXME: use matrix-type input source selection */
8083         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8084         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
8085         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
8086         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
8087         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
8088         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
8089         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
8090         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
8091         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
8092         /* Input mixer2 */
8093         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8094         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8095         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
8096         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
8097         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
8098         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
8099         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
8100         /* Input mixer3 */
8101         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8102         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8103         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
8104         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
8105         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
8106         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
8107         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
8108
8109         { }
8110 };
8111
8112 #ifdef CONFIG_SND_HDA_POWER_SAVE
8113 #define alc262_loopbacks        alc880_loopbacks
8114 #endif
8115
8116 /* pcm configuration: identiacal with ALC880 */
8117 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
8118 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
8119 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
8120 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
8121
8122 /*
8123  * BIOS auto configuration
8124  */
8125 static int alc262_parse_auto_config(struct hda_codec *codec)
8126 {
8127         struct alc_spec *spec = codec->spec;
8128         int err;
8129         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
8130
8131         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
8132                                            alc262_ignore);
8133         if (err < 0)
8134                 return err;
8135         if (!spec->autocfg.line_outs)
8136                 return 0; /* can't find valid BIOS pin config */
8137         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
8138         if (err < 0)
8139                 return err;
8140         err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg);
8141         if (err < 0)
8142                 return err;
8143
8144         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
8145
8146         if (spec->autocfg.dig_out_pin)
8147                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
8148         if (spec->autocfg.dig_in_pin)
8149                 spec->dig_in_nid = ALC262_DIGIN_NID;
8150
8151         if (spec->kctl_alloc)
8152                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
8153
8154         spec->init_verbs[spec->num_init_verbs++] = alc262_volume_init_verbs;
8155         spec->num_mux_defs = 1;
8156         spec->input_mux = &spec->private_imux;
8157
8158         return 1;
8159 }
8160
8161 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
8162 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
8163 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
8164
8165
8166 /* init callback for auto-configuration model -- overriding the default init */
8167 static void alc262_auto_init(struct hda_codec *codec)
8168 {
8169         alc262_auto_init_multi_out(codec);
8170         alc262_auto_init_hp_out(codec);
8171         alc262_auto_init_analog_input(codec);
8172 }
8173
8174 /*
8175  * configuration and preset
8176  */
8177 static const char *alc262_models[ALC262_MODEL_LAST] = {
8178         [ALC262_BASIC]          = "basic",
8179         [ALC262_HIPPO]          = "hippo",
8180         [ALC262_HIPPO_1]        = "hippo_1",
8181         [ALC262_FUJITSU]        = "fujitsu",
8182         [ALC262_HP_BPC]         = "hp-bpc",
8183         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
8184         [ALC262_BENQ_ED8]       = "benq",
8185         [ALC262_BENQ_T31]       = "benq-t31",
8186         [ALC262_SONY_ASSAMD]    = "sony-assamd",
8187         [ALC262_AUTO]           = "auto",
8188 };
8189
8190 static struct snd_pci_quirk alc262_cfg_tbl[] = {
8191         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
8192         SND_PCI_QUIRK(0x103c, 0x12fe, "HP xw9400", ALC262_HP_BPC),
8193         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
8194         SND_PCI_QUIRK(0x103c, 0x12ff, "HP xw4550", ALC262_HP_BPC),
8195         SND_PCI_QUIRK(0x103c, 0x1308, "HP xw4600", ALC262_HP_BPC),
8196         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
8197         SND_PCI_QUIRK(0x103c, 0x1307, "HP xw6600", ALC262_HP_BPC),
8198         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
8199         SND_PCI_QUIRK(0x103c, 0x1306, "HP xw8600", ALC262_HP_BPC),
8200         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
8201         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
8202         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
8203         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
8204         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
8205         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
8206         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
8207         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
8208         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
8209         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
8210         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
8211         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
8212         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
8213         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
8214         SND_PCI_QUIRK(0x104d, 0x9015, "Sony 0x9015", ALC262_SONY_ASSAMD),
8215         SND_PCI_QUIRK(0x104d, 0x900e, "Sony ASSAMD", ALC262_SONY_ASSAMD),
8216         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
8217         {}
8218 };
8219
8220 static struct alc_config_preset alc262_presets[] = {
8221         [ALC262_BASIC] = {
8222                 .mixers = { alc262_base_mixer },
8223                 .init_verbs = { alc262_init_verbs },
8224                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8225                 .dac_nids = alc262_dac_nids,
8226                 .hp_nid = 0x03,
8227                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8228                 .channel_mode = alc262_modes,
8229                 .input_mux = &alc262_capture_source,
8230         },
8231         [ALC262_HIPPO] = {
8232                 .mixers = { alc262_base_mixer },
8233                 .init_verbs = { alc262_init_verbs, alc262_hippo_unsol_verbs},
8234                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8235                 .dac_nids = alc262_dac_nids,
8236                 .hp_nid = 0x03,
8237                 .dig_out_nid = ALC262_DIGOUT_NID,
8238                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8239                 .channel_mode = alc262_modes,
8240                 .input_mux = &alc262_capture_source,
8241                 .unsol_event = alc262_hippo_unsol_event,
8242                 .init_hook = alc262_hippo_automute,
8243         },
8244         [ALC262_HIPPO_1] = {
8245                 .mixers = { alc262_hippo1_mixer },
8246                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
8247                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8248                 .dac_nids = alc262_dac_nids,
8249                 .hp_nid = 0x02,
8250                 .dig_out_nid = ALC262_DIGOUT_NID,
8251                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8252                 .channel_mode = alc262_modes,
8253                 .input_mux = &alc262_capture_source,
8254                 .unsol_event = alc262_hippo1_unsol_event,
8255                 .init_hook = alc262_hippo1_automute,
8256         },
8257         [ALC262_FUJITSU] = {
8258                 .mixers = { alc262_fujitsu_mixer },
8259                 .init_verbs = { alc262_init_verbs, alc262_fujitsu_unsol_verbs },
8260                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8261                 .dac_nids = alc262_dac_nids,
8262                 .hp_nid = 0x03,
8263                 .dig_out_nid = ALC262_DIGOUT_NID,
8264                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8265                 .channel_mode = alc262_modes,
8266                 .input_mux = &alc262_fujitsu_capture_source,
8267                 .unsol_event = alc262_fujitsu_unsol_event,
8268         },
8269         [ALC262_HP_BPC] = {
8270                 .mixers = { alc262_HP_BPC_mixer },
8271                 .init_verbs = { alc262_HP_BPC_init_verbs },
8272                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8273                 .dac_nids = alc262_dac_nids,
8274                 .hp_nid = 0x03,
8275                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8276                 .channel_mode = alc262_modes,
8277                 .input_mux = &alc262_HP_capture_source,
8278         },
8279         [ALC262_HP_BPC_D7000_WF] = {
8280                 .mixers = { alc262_HP_BPC_WildWest_mixer },
8281                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
8282                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8283                 .dac_nids = alc262_dac_nids,
8284                 .hp_nid = 0x03,
8285                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8286                 .channel_mode = alc262_modes,
8287                 .input_mux = &alc262_HP_capture_source,
8288         },
8289         [ALC262_HP_BPC_D7000_WL] = {
8290                 .mixers = { alc262_HP_BPC_WildWest_mixer,
8291                             alc262_HP_BPC_WildWest_option_mixer },
8292                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
8293                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8294                 .dac_nids = alc262_dac_nids,
8295                 .hp_nid = 0x03,
8296                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8297                 .channel_mode = alc262_modes,
8298                 .input_mux = &alc262_HP_capture_source,
8299         },
8300         [ALC262_BENQ_ED8] = {
8301                 .mixers = { alc262_base_mixer },
8302                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
8303                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8304                 .dac_nids = alc262_dac_nids,
8305                 .hp_nid = 0x03,
8306                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8307                 .channel_mode = alc262_modes,
8308                 .input_mux = &alc262_capture_source,
8309         },
8310         [ALC262_SONY_ASSAMD] = {
8311                 .mixers = { alc262_sony_mixer },
8312                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
8313                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8314                 .dac_nids = alc262_dac_nids,
8315                 .hp_nid = 0x02,
8316                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8317                 .channel_mode = alc262_modes,
8318                 .input_mux = &alc262_capture_source,
8319                 .unsol_event = alc262_hippo_unsol_event,
8320                 .init_hook = alc262_hippo_automute,
8321         },
8322         [ALC262_BENQ_T31] = {
8323                 .mixers = { alc262_benq_t31_mixer },
8324                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs, alc262_hippo_unsol_verbs },
8325                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8326                 .dac_nids = alc262_dac_nids,
8327                 .hp_nid = 0x03,
8328                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8329                 .channel_mode = alc262_modes,
8330                 .input_mux = &alc262_capture_source,
8331                 .unsol_event = alc262_hippo_unsol_event,
8332                 .init_hook = alc262_hippo_automute,
8333         },      
8334 };
8335
8336 static int patch_alc262(struct hda_codec *codec)
8337 {
8338         struct alc_spec *spec;
8339         int board_config;
8340         int err;
8341
8342         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
8343         if (spec == NULL)
8344                 return -ENOMEM;
8345
8346         codec->spec = spec;
8347 #if 0
8348         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
8349          * under-run
8350          */
8351         {
8352         int tmp;
8353         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
8354         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
8355         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
8356         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
8357         }
8358 #endif
8359
8360         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
8361                                                   alc262_models,
8362                                                   alc262_cfg_tbl);
8363
8364         if (board_config < 0) {
8365                 printk(KERN_INFO "hda_codec: Unknown model for ALC262, "
8366                        "trying auto-probe from BIOS...\n");
8367                 board_config = ALC262_AUTO;
8368         }
8369
8370         if (board_config == ALC262_AUTO) {
8371                 /* automatic parse from the BIOS config */
8372                 err = alc262_parse_auto_config(codec);
8373                 if (err < 0) {
8374                         alc_free(codec);
8375                         return err;
8376                 } else if (!err) {
8377                         printk(KERN_INFO
8378                                "hda_codec: Cannot set up configuration "
8379                                "from BIOS.  Using base mode...\n");
8380                         board_config = ALC262_BASIC;
8381                 }
8382         }
8383
8384         if (board_config != ALC262_AUTO)
8385                 setup_preset(spec, &alc262_presets[board_config]);
8386
8387         spec->stream_name_analog = "ALC262 Analog";
8388         spec->stream_analog_playback = &alc262_pcm_analog_playback;
8389         spec->stream_analog_capture = &alc262_pcm_analog_capture;
8390                 
8391         spec->stream_name_digital = "ALC262 Digital";
8392         spec->stream_digital_playback = &alc262_pcm_digital_playback;
8393         spec->stream_digital_capture = &alc262_pcm_digital_capture;
8394
8395         if (!spec->adc_nids && spec->input_mux) {
8396                 /* check whether NID 0x07 is valid */
8397                 unsigned int wcap = get_wcaps(codec, 0x07);
8398
8399                 /* get type */
8400                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
8401                 if (wcap != AC_WID_AUD_IN) {
8402                         spec->adc_nids = alc262_adc_nids_alt;
8403                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
8404                         spec->mixers[spec->num_mixers] =
8405                                 alc262_capture_alt_mixer;
8406                         spec->num_mixers++;
8407                 } else {
8408                         spec->adc_nids = alc262_adc_nids;
8409                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
8410                         spec->mixers[spec->num_mixers] = alc262_capture_mixer;
8411                         spec->num_mixers++;
8412                 }
8413         }
8414
8415         codec->patch_ops = alc_patch_ops;
8416         if (board_config == ALC262_AUTO)
8417                 spec->init_hook = alc262_auto_init;
8418 #ifdef CONFIG_SND_HDA_POWER_SAVE
8419         if (!spec->loopback.amplist)
8420                 spec->loopback.amplist = alc262_loopbacks;
8421 #endif
8422                 
8423         return 0;
8424 }
8425
8426 /*
8427  *  ALC268 channel source setting (2 channel)
8428  */
8429 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
8430 #define alc268_modes            alc260_modes
8431         
8432 static hda_nid_t alc268_dac_nids[2] = {
8433         /* front, hp */
8434         0x02, 0x03
8435 };
8436
8437 static hda_nid_t alc268_adc_nids[2] = {
8438         /* ADC0-1 */
8439         0x08, 0x07
8440 };
8441
8442 static hda_nid_t alc268_adc_nids_alt[1] = {
8443         /* ADC0 */
8444         0x08
8445 };
8446
8447 static struct snd_kcontrol_new alc268_base_mixer[] = {
8448         /* output mixer control */
8449         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
8450         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8451         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
8452         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8453         { }
8454 };
8455
8456 static struct hda_verb alc268_eapd_verbs[] = {
8457         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
8458         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
8459         { }
8460 };
8461
8462 /* Toshiba specific */
8463 #define alc268_toshiba_automute alc262_hippo_automute
8464
8465 static struct hda_verb alc268_toshiba_verbs[] = {
8466         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8467         { } /* end */
8468 };
8469
8470 /* Acer specific */
8471 /* bind volumes of both NID 0x0c and 0x0d */
8472 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
8473         .ops = &snd_hda_bind_vol,
8474         .values = {
8475                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
8476                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
8477                 0
8478         },
8479 };
8480
8481 #define alc268_acer_master_sw_put       alc262_fujitsu_master_sw_put
8482 #define alc268_acer_automute    alc262_fujitsu_automute
8483
8484 static struct snd_kcontrol_new alc268_acer_mixer[] = {
8485         /* output mixer control */
8486         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
8487         {
8488                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8489                 .name = "Master Playback Switch",
8490                 .info = snd_hda_mixer_amp_switch_info,
8491                 .get = snd_hda_mixer_amp_switch_get,
8492                 .put = alc268_acer_master_sw_put,
8493                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
8494         },
8495         { }
8496 };
8497
8498 static struct hda_verb alc268_acer_verbs[] = {
8499         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8500         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8501
8502         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8503         { }
8504 };
8505
8506 /* unsolicited event for HP jack sensing */
8507 static void alc268_toshiba_unsol_event(struct hda_codec *codec,
8508                                        unsigned int res)
8509 {
8510         if ((res >> 28) != ALC880_HP_EVENT)
8511                 return;
8512         alc268_toshiba_automute(codec);
8513 }
8514
8515 static void alc268_acer_unsol_event(struct hda_codec *codec,
8516                                        unsigned int res)
8517 {
8518         if ((res >> 28) != ALC880_HP_EVENT)
8519                 return;
8520         alc268_acer_automute(codec, 1);
8521 }
8522
8523 /*
8524  * generic initialization of ADC, input mixers and output mixers
8525  */
8526 static struct hda_verb alc268_base_init_verbs[] = {
8527         /* Unmute DAC0-1 and set vol = 0 */
8528         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8529         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8530         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8531         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8532         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8533         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8534
8535         /*
8536          * Set up output mixers (0x0c - 0x0e)
8537          */
8538         /* set vol=0 to output mixers */
8539         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8540         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8541         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8542         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
8543
8544         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8545         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8546
8547         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
8548         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8549         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
8550         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8551         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8552         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8553         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8554         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8555
8556         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8557         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8558         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8559         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8560         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8561         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8562         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8563         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8564
8565         /* FIXME: use matrix-type input source selection */
8566         /* Mixer elements: 0x18, 19, 1a, 1c, 14, 15, 0b */
8567         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
8568         /* Input mixer2 */
8569         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8570         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8571         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
8572         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
8573
8574         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8575         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8576         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
8577         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
8578         { }
8579 };
8580
8581 /*
8582  * generic initialization of ADC, input mixers and output mixers
8583  */
8584 static struct hda_verb alc268_volume_init_verbs[] = {
8585         /* set output DAC */
8586         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8587         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8588         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8589         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8590
8591         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8592         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8593         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8594         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8595         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8596
8597         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8598         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8599         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8600         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8601         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8602
8603         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8604         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8605         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8606         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8607
8608         /* set PCBEEP vol = 0 */
8609         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, (0xb000 | (0x00 << 8))},
8610
8611         { }
8612 };
8613
8614 #define alc268_mux_enum_info alc_mux_enum_info
8615 #define alc268_mux_enum_get alc_mux_enum_get
8616
8617 static int alc268_mux_enum_put(struct snd_kcontrol *kcontrol,
8618                                struct snd_ctl_elem_value *ucontrol)
8619 {
8620         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8621         struct alc_spec *spec = codec->spec;
8622         const struct hda_input_mux *imux = spec->input_mux;
8623         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
8624         static hda_nid_t capture_mixers[3] = { 0x23, 0x24 };
8625         hda_nid_t nid = capture_mixers[adc_idx];
8626         unsigned int *cur_val = &spec->cur_mux[adc_idx];
8627         unsigned int i, idx;
8628
8629         idx = ucontrol->value.enumerated.item[0];
8630         if (idx >= imux->num_items)
8631                 idx = imux->num_items - 1;
8632         if (*cur_val == idx)
8633                 return 0;
8634         for (i = 0; i < imux->num_items; i++) {
8635                 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
8636                 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
8637                                          imux->items[i].index,
8638                                          HDA_AMP_MUTE, v);
8639                 snd_hda_codec_write_cache(codec, nid, 0,
8640                                           AC_VERB_SET_CONNECT_SEL,
8641                                           idx );
8642         }
8643         *cur_val = idx;
8644         return 1;
8645 }
8646
8647 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
8648         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
8649         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
8650         {
8651                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8652                 /* The multiple "Capture Source" controls confuse alsamixer
8653                  * So call somewhat different..
8654                  * FIXME: the controls appear in the "playback" view!
8655                  */
8656                 /* .name = "Capture Source", */
8657                 .name = "Input Source",
8658                 .count = 1,
8659                 .info = alc268_mux_enum_info,
8660                 .get = alc268_mux_enum_get,
8661                 .put = alc268_mux_enum_put,
8662         },
8663         { } /* end */
8664 };
8665
8666 static struct snd_kcontrol_new alc268_capture_mixer[] = {
8667         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
8668         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
8669         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
8670         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
8671         {
8672                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8673                 /* The multiple "Capture Source" controls confuse alsamixer
8674                  * So call somewhat different..
8675                  * FIXME: the controls appear in the "playback" view!
8676                  */
8677                 /* .name = "Capture Source", */
8678                 .name = "Input Source",
8679                 .count = 2,
8680                 .info = alc268_mux_enum_info,
8681                 .get = alc268_mux_enum_get,
8682                 .put = alc268_mux_enum_put,
8683         },
8684         { } /* end */
8685 };
8686
8687 static struct hda_input_mux alc268_capture_source = {
8688         .num_items = 4,
8689         .items = {
8690                 { "Mic", 0x0 },
8691                 { "Front Mic", 0x1 },
8692                 { "Line", 0x2 },
8693                 { "CD", 0x3 },
8694         },
8695 };
8696
8697 /* create input playback/capture controls for the given pin */
8698 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
8699                                     const char *ctlname, int idx)
8700 {
8701         char name[32];
8702         int err;
8703
8704         sprintf(name, "%s Playback Volume", ctlname);
8705         if (nid == 0x14) {
8706                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
8707                                   HDA_COMPOSE_AMP_VAL(0x02, 3, idx,
8708                                                       HDA_OUTPUT));
8709                 if (err < 0)
8710                         return err;
8711         } else if (nid == 0x15) {
8712                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
8713                                   HDA_COMPOSE_AMP_VAL(0x03, 3, idx,
8714                                                       HDA_OUTPUT));
8715                 if (err < 0)
8716                         return err;
8717         } else
8718                 return -1;
8719         sprintf(name, "%s Playback Switch", ctlname);
8720         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
8721                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
8722         if (err < 0)
8723                 return err;
8724         return 0;
8725 }
8726
8727 /* add playback controls from the parsed DAC table */
8728 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
8729                                              const struct auto_pin_cfg *cfg)
8730 {
8731         hda_nid_t nid;
8732         int err;
8733
8734         spec->multiout.num_dacs = 2;    /* only use one dac */
8735         spec->multiout.dac_nids = spec->private_dac_nids;
8736         spec->multiout.dac_nids[0] = 2;
8737         spec->multiout.dac_nids[1] = 3;
8738
8739         nid = cfg->line_out_pins[0];
8740         if (nid)
8741                 alc268_new_analog_output(spec, nid, "Front", 0);        
8742
8743         nid = cfg->speaker_pins[0];
8744         if (nid == 0x1d) {
8745                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
8746                                   "Speaker Playback Volume",
8747                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
8748                 if (err < 0)
8749                         return err;
8750         }
8751         nid = cfg->hp_pins[0];
8752         if (nid)
8753                 alc268_new_analog_output(spec, nid, "Headphone", 0);
8754
8755         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
8756         if (nid == 0x16) {
8757                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
8758                                   "Mono Playback Switch",
8759                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_INPUT));
8760                 if (err < 0)
8761                         return err;
8762         }
8763         return 0;       
8764 }
8765
8766 /* create playback/capture controls for input pins */
8767 static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
8768                                                 const struct auto_pin_cfg *cfg)
8769 {
8770         struct hda_input_mux *imux = &spec->private_imux;
8771         int i, idx1;
8772
8773         for (i = 0; i < AUTO_PIN_LAST; i++) {
8774                 switch(cfg->input_pins[i]) {
8775                 case 0x18:
8776                         idx1 = 0;       /* Mic 1 */
8777                         break;
8778                 case 0x19:
8779                         idx1 = 1;       /* Mic 2 */
8780                         break;
8781                 case 0x1a:
8782                         idx1 = 2;       /* Line In */
8783                         break;
8784                 case 0x1c:      
8785                         idx1 = 3;       /* CD */
8786                         break;
8787                 default:
8788                         continue;
8789                 }
8790                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
8791                 imux->items[imux->num_items].index = idx1;
8792                 imux->num_items++;      
8793         }
8794         return 0;
8795 }
8796
8797 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
8798 {
8799         struct alc_spec *spec = codec->spec;
8800         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
8801         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
8802         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
8803         unsigned int    dac_vol1, dac_vol2;
8804
8805         if (speaker_nid) {
8806                 snd_hda_codec_write(codec, speaker_nid, 0,
8807                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
8808                 snd_hda_codec_write(codec, 0x0f, 0,
8809                                     AC_VERB_SET_AMP_GAIN_MUTE,
8810                                     AMP_IN_UNMUTE(1));
8811                 snd_hda_codec_write(codec, 0x10, 0,
8812                                     AC_VERB_SET_AMP_GAIN_MUTE,
8813                                     AMP_IN_UNMUTE(1));
8814         } else {
8815                 snd_hda_codec_write(codec, 0x0f, 0,
8816                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
8817                 snd_hda_codec_write(codec, 0x10, 0,
8818                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
8819         }
8820
8821         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
8822         if (line_nid == 0x14)   
8823                 dac_vol2 = AMP_OUT_ZERO;
8824         else if (line_nid == 0x15)
8825                 dac_vol1 = AMP_OUT_ZERO;
8826         if (hp_nid == 0x14)     
8827                 dac_vol2 = AMP_OUT_ZERO;
8828         else if (hp_nid == 0x15)
8829                 dac_vol1 = AMP_OUT_ZERO;
8830         if (line_nid != 0x16 || hp_nid != 0x16 ||
8831             spec->autocfg.line_out_pins[1] != 0x16 ||
8832             spec->autocfg.line_out_pins[2] != 0x16)
8833                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
8834
8835         snd_hda_codec_write(codec, 0x02, 0,
8836                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
8837         snd_hda_codec_write(codec, 0x03, 0,
8838                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
8839 }
8840
8841 /* pcm configuration: identiacal with ALC880 */
8842 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
8843 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
8844 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
8845
8846 /*
8847  * BIOS auto configuration
8848  */
8849 static int alc268_parse_auto_config(struct hda_codec *codec)
8850 {
8851         struct alc_spec *spec = codec->spec;
8852         int err;
8853         static hda_nid_t alc268_ignore[] = { 0 };
8854
8855         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
8856                                            alc268_ignore);
8857         if (err < 0)
8858                 return err;
8859         if (!spec->autocfg.line_outs)
8860                 return 0; /* can't find valid BIOS pin config */
8861
8862         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
8863         if (err < 0)
8864                 return err;
8865         err = alc268_auto_create_analog_input_ctls(spec, &spec->autocfg);
8866         if (err < 0)
8867                 return err;
8868
8869         spec->multiout.max_channels = 2;
8870
8871         /* digital only support output */
8872         if (spec->autocfg.dig_out_pin)
8873                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
8874
8875         if (spec->kctl_alloc)
8876                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
8877
8878         spec->init_verbs[spec->num_init_verbs++] = alc268_volume_init_verbs;
8879         spec->num_mux_defs = 1;
8880         spec->input_mux = &spec->private_imux;
8881
8882         return 1;
8883 }
8884
8885 #define alc268_auto_init_multi_out      alc882_auto_init_multi_out
8886 #define alc268_auto_init_hp_out         alc882_auto_init_hp_out
8887 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
8888
8889 /* init callback for auto-configuration model -- overriding the default init */
8890 static void alc268_auto_init(struct hda_codec *codec)
8891 {
8892         alc268_auto_init_multi_out(codec);
8893         alc268_auto_init_hp_out(codec);
8894         alc268_auto_init_mono_speaker_out(codec);
8895         alc268_auto_init_analog_input(codec);
8896 }
8897
8898 /*
8899  * configuration and preset
8900  */
8901 static const char *alc268_models[ALC268_MODEL_LAST] = {
8902         [ALC268_3ST]            = "3stack",
8903         [ALC268_TOSHIBA]        = "toshiba",
8904         [ALC268_ACER]           = "acer",
8905         [ALC268_AUTO]           = "auto",
8906 };
8907
8908 static struct snd_pci_quirk alc268_cfg_tbl[] = {
8909         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
8910         SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA),
8911         SND_PCI_QUIRK(0x103c, 0x30cc, "TOSHIBA", ALC268_TOSHIBA),
8912         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
8913         {}
8914 };
8915
8916 static struct alc_config_preset alc268_presets[] = {
8917         [ALC268_3ST] = {
8918                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer },
8919                 .init_verbs = { alc268_base_init_verbs },
8920                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
8921                 .dac_nids = alc268_dac_nids,
8922                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
8923                 .adc_nids = alc268_adc_nids_alt,
8924                 .hp_nid = 0x03,
8925                 .dig_out_nid = ALC268_DIGOUT_NID,
8926                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
8927                 .channel_mode = alc268_modes,
8928                 .input_mux = &alc268_capture_source,
8929         },
8930         [ALC268_TOSHIBA] = {
8931                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer },
8932                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
8933                                 alc268_toshiba_verbs },
8934                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
8935                 .dac_nids = alc268_dac_nids,
8936                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
8937                 .adc_nids = alc268_adc_nids_alt,
8938                 .hp_nid = 0x03,
8939                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
8940                 .channel_mode = alc268_modes,
8941                 .input_mux = &alc268_capture_source,
8942                 .input_mux = &alc268_capture_source,
8943                 .unsol_event = alc268_toshiba_unsol_event,
8944                 .init_hook = alc268_toshiba_automute,
8945         },
8946         [ALC268_ACER] = {
8947                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer },
8948                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
8949                                 alc268_acer_verbs },
8950                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
8951                 .dac_nids = alc268_dac_nids,
8952                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
8953                 .adc_nids = alc268_adc_nids_alt,
8954                 .hp_nid = 0x02,
8955                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
8956                 .channel_mode = alc268_modes,
8957                 .input_mux = &alc268_capture_source,
8958                 .unsol_event = alc268_acer_unsol_event,
8959         },
8960 };
8961
8962 static int patch_alc268(struct hda_codec *codec)
8963 {
8964         struct alc_spec *spec;
8965         int board_config;
8966         int err;
8967
8968         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
8969         if (spec == NULL)
8970                 return -ENOMEM;
8971
8972         codec->spec = spec;
8973
8974         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
8975                                                   alc268_models,
8976                                                   alc268_cfg_tbl);
8977
8978         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
8979                 printk(KERN_INFO "hda_codec: Unknown model for ALC268, "
8980                        "trying auto-probe from BIOS...\n");
8981                 board_config = ALC268_AUTO;
8982         }
8983
8984         if (board_config == ALC268_AUTO) {
8985                 /* automatic parse from the BIOS config */
8986                 err = alc268_parse_auto_config(codec);
8987                 if (err < 0) {
8988                         alc_free(codec);
8989                         return err;
8990                 } else if (!err) {
8991                         printk(KERN_INFO
8992                                "hda_codec: Cannot set up configuration "
8993                                "from BIOS.  Using base mode...\n");
8994                         board_config = ALC268_3ST;
8995                 }
8996         }
8997
8998         if (board_config != ALC268_AUTO)
8999                 setup_preset(spec, &alc268_presets[board_config]);
9000
9001         spec->stream_name_analog = "ALC268 Analog";
9002         spec->stream_analog_playback = &alc268_pcm_analog_playback;
9003         spec->stream_analog_capture = &alc268_pcm_analog_capture;
9004
9005         spec->stream_name_digital = "ALC268 Digital";
9006         spec->stream_digital_playback = &alc268_pcm_digital_playback;
9007
9008         if (board_config == ALC268_AUTO) {
9009                 if (!spec->adc_nids && spec->input_mux) {
9010                         /* check whether NID 0x07 is valid */
9011                         unsigned int wcap = get_wcaps(codec, 0x07);
9012
9013                         /* get type */
9014                         wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
9015                         if (wcap != AC_WID_AUD_IN) {
9016                                 spec->adc_nids = alc268_adc_nids_alt;
9017                                 spec->num_adc_nids =
9018                                         ARRAY_SIZE(alc268_adc_nids_alt);
9019                                 spec->mixers[spec->num_mixers] =
9020                                         alc268_capture_alt_mixer;
9021                                 spec->num_mixers++;
9022                         } else {
9023                                 spec->adc_nids = alc268_adc_nids;
9024                                 spec->num_adc_nids =
9025                                         ARRAY_SIZE(alc268_adc_nids);
9026                                 spec->mixers[spec->num_mixers] =
9027                                         alc268_capture_mixer;
9028                                 spec->num_mixers++;
9029                         }
9030                 }
9031         }
9032         codec->patch_ops = alc_patch_ops;
9033         if (board_config == ALC268_AUTO)
9034                 spec->init_hook = alc268_auto_init;
9035                 
9036         return 0;
9037 }
9038
9039 /*
9040  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
9041  */
9042
9043 /*
9044  * set the path ways for 2 channel output
9045  * need to set the codec line out and mic 1 pin widgets to inputs
9046  */
9047 static struct hda_verb alc861_threestack_ch2_init[] = {
9048         /* set pin widget 1Ah (line in) for input */
9049         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
9050         /* set pin widget 18h (mic1/2) for input, for mic also enable
9051          * the vref
9052          */
9053         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9054
9055         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
9056 #if 0
9057         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
9058         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
9059 #endif
9060         { } /* end */
9061 };
9062 /*
9063  * 6ch mode
9064  * need to set the codec line out and mic 1 pin widgets to outputs
9065  */
9066 static struct hda_verb alc861_threestack_ch6_init[] = {
9067         /* set pin widget 1Ah (line in) for output (Back Surround)*/
9068         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9069         /* set pin widget 18h (mic1) for output (CLFE)*/
9070         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9071
9072         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
9073         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
9074
9075         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
9076 #if 0
9077         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
9078         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
9079 #endif
9080         { } /* end */
9081 };
9082
9083 static struct hda_channel_mode alc861_threestack_modes[2] = {
9084         { 2, alc861_threestack_ch2_init },
9085         { 6, alc861_threestack_ch6_init },
9086 };
9087 /* Set mic1 as input and unmute the mixer */
9088 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
9089         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9090         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
9091         { } /* end */
9092 };
9093 /* Set mic1 as output and mute mixer */
9094 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
9095         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9096         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
9097         { } /* end */
9098 };
9099
9100 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
9101         { 2, alc861_uniwill_m31_ch2_init },
9102         { 4, alc861_uniwill_m31_ch4_init },
9103 };
9104
9105 /* Set mic1 and line-in as input and unmute the mixer */
9106 static struct hda_verb alc861_asus_ch2_init[] = {
9107         /* set pin widget 1Ah (line in) for input */
9108         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
9109         /* set pin widget 18h (mic1/2) for input, for mic also enable
9110          * the vref
9111          */
9112         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9113
9114         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
9115 #if 0
9116         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
9117         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
9118 #endif
9119         { } /* end */
9120 };
9121 /* Set mic1 nad line-in as output and mute mixer */
9122 static struct hda_verb alc861_asus_ch6_init[] = {
9123         /* set pin widget 1Ah (line in) for output (Back Surround)*/
9124         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9125         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
9126         /* set pin widget 18h (mic1) for output (CLFE)*/
9127         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9128         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
9129         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
9130         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
9131
9132         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
9133 #if 0
9134         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
9135         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
9136 #endif
9137         { } /* end */
9138 };
9139
9140 static struct hda_channel_mode alc861_asus_modes[2] = {
9141         { 2, alc861_asus_ch2_init },
9142         { 6, alc861_asus_ch6_init },
9143 };
9144
9145 /* patch-ALC861 */
9146
9147 static struct snd_kcontrol_new alc861_base_mixer[] = {
9148         /* output mixer control */
9149         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
9150         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
9151         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
9152         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
9153         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
9154
9155         /*Input mixer control */
9156         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
9157            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
9158         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
9159         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
9160         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
9161         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
9162         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
9163         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
9164         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
9165         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
9166
9167         /* Capture mixer control */
9168         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
9169         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
9170         {
9171                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9172                 .name = "Capture Source",
9173                 .count = 1,
9174                 .info = alc_mux_enum_info,
9175                 .get = alc_mux_enum_get,
9176                 .put = alc_mux_enum_put,
9177         },
9178         { } /* end */
9179 };
9180
9181 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
9182         /* output mixer control */
9183         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
9184         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
9185         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
9186         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
9187         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
9188
9189         /* Input mixer control */
9190         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
9191            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
9192         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
9193         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
9194         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
9195         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
9196         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
9197         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
9198         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
9199         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
9200
9201         /* Capture mixer control */
9202         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
9203         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
9204         {
9205                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9206                 .name = "Capture Source",
9207                 .count = 1,
9208                 .info = alc_mux_enum_info,
9209                 .get = alc_mux_enum_get,
9210                 .put = alc_mux_enum_put,
9211         },
9212         {
9213                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9214                 .name = "Channel Mode",
9215                 .info = alc_ch_mode_info,
9216                 .get = alc_ch_mode_get,
9217                 .put = alc_ch_mode_put,
9218                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
9219         },
9220         { } /* end */
9221 };
9222
9223 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
9224         /* output mixer control */
9225         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
9226         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
9227         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
9228         
9229         /*Capture mixer control */
9230         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
9231         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
9232         {
9233                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9234                 .name = "Capture Source",
9235                 .count = 1,
9236                 .info = alc_mux_enum_info,
9237                 .get = alc_mux_enum_get,
9238                 .put = alc_mux_enum_put,
9239         },
9240
9241         { } /* end */
9242 };
9243
9244 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
9245         /* output mixer control */
9246         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
9247         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
9248         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
9249         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
9250         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
9251
9252         /* Input mixer control */
9253         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
9254            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
9255         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
9256         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
9257         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
9258         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
9259         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
9260         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
9261         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
9262         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
9263
9264         /* Capture mixer control */
9265         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
9266         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
9267         {
9268                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9269                 .name = "Capture Source",
9270                 .count = 1,
9271                 .info = alc_mux_enum_info,
9272                 .get = alc_mux_enum_get,
9273                 .put = alc_mux_enum_put,
9274         },
9275         {
9276                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9277                 .name = "Channel Mode",
9278                 .info = alc_ch_mode_info,
9279                 .get = alc_ch_mode_get,
9280                 .put = alc_ch_mode_put,
9281                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
9282         },
9283         { } /* end */
9284 };
9285
9286 static struct snd_kcontrol_new alc861_asus_mixer[] = {
9287         /* output mixer control */
9288         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
9289         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
9290         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
9291         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
9292         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
9293
9294         /* Input mixer control */
9295         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
9296         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9297         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
9298         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
9299         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
9300         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
9301         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
9302         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
9303         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
9304         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
9305
9306         /* Capture mixer control */
9307         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
9308         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
9309         {
9310                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9311                 .name = "Capture Source",
9312                 .count = 1,
9313                 .info = alc_mux_enum_info,
9314                 .get = alc_mux_enum_get,
9315                 .put = alc_mux_enum_put,
9316         },
9317         {
9318                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9319                 .name = "Channel Mode",
9320                 .info = alc_ch_mode_info,
9321                 .get = alc_ch_mode_get,
9322                 .put = alc_ch_mode_put,
9323                 .private_value = ARRAY_SIZE(alc861_asus_modes),
9324         },
9325         { }
9326 };
9327
9328 /* additional mixer */
9329 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
9330         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
9331         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
9332         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x23, 0x0, HDA_OUTPUT),
9333         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x23, 0x0, HDA_OUTPUT),
9334         { }
9335 };
9336
9337 /*
9338  * generic initialization of ADC, input mixers and output mixers
9339  */
9340 static struct hda_verb alc861_base_init_verbs[] = {
9341         /*
9342          * Unmute ADC0 and set the default input to mic-in
9343          */
9344         /* port-A for surround (rear panel) */
9345         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9346         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
9347         /* port-B for mic-in (rear panel) with vref */
9348         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9349         /* port-C for line-in (rear panel) */
9350         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
9351         /* port-D for Front */
9352         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9353         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
9354         /* port-E for HP out (front panel) */
9355         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
9356         /* route front PCM to HP */
9357         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
9358         /* port-F for mic-in (front panel) with vref */
9359         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9360         /* port-G for CLFE (rear panel) */
9361         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9362         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
9363         /* port-H for side (rear panel) */
9364         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9365         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
9366         /* CD-in */
9367         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
9368         /* route front mic to ADC1*/
9369         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9370         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9371         
9372         /* Unmute DAC0~3 & spdif out*/
9373         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9374         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9375         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9376         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9377         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9378         
9379         /* Unmute Mixer 14 (mic) 1c (Line in)*/
9380         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9381         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9382         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9383         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9384         
9385         /* Unmute Stereo Mixer 15 */
9386         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9387         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9388         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9389         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
9390
9391         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9392         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9393         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9394         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9395         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9396         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9397         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9398         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9399         /* hp used DAC 3 (Front) */
9400         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
9401         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9402
9403         { }
9404 };
9405
9406 static struct hda_verb alc861_threestack_init_verbs[] = {
9407         /*
9408          * Unmute ADC0 and set the default input to mic-in
9409          */
9410         /* port-A for surround (rear panel) */
9411         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
9412         /* port-B for mic-in (rear panel) with vref */
9413         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9414         /* port-C for line-in (rear panel) */
9415         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
9416         /* port-D for Front */
9417         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9418         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
9419         /* port-E for HP out (front panel) */
9420         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
9421         /* route front PCM to HP */
9422         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
9423         /* port-F for mic-in (front panel) with vref */
9424         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9425         /* port-G for CLFE (rear panel) */
9426         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
9427         /* port-H for side (rear panel) */
9428         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
9429         /* CD-in */
9430         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
9431         /* route front mic to ADC1*/
9432         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9433         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9434         /* Unmute DAC0~3 & spdif out*/
9435         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9436         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9437         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9438         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9439         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9440         
9441         /* Unmute Mixer 14 (mic) 1c (Line in)*/
9442         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9443         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9444         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9445         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9446         
9447         /* Unmute Stereo Mixer 15 */
9448         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9449         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9450         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9451         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
9452
9453         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9454         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9455         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9456         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9457         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9458         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9459         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9460         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9461         /* hp used DAC 3 (Front) */
9462         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
9463         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9464         { }
9465 };
9466
9467 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
9468         /*
9469          * Unmute ADC0 and set the default input to mic-in
9470          */
9471         /* port-A for surround (rear panel) */
9472         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
9473         /* port-B for mic-in (rear panel) with vref */
9474         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9475         /* port-C for line-in (rear panel) */
9476         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
9477         /* port-D for Front */
9478         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9479         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
9480         /* port-E for HP out (front panel) */
9481         /* this has to be set to VREF80 */
9482         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9483         /* route front PCM to HP */
9484         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
9485         /* port-F for mic-in (front panel) with vref */
9486         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9487         /* port-G for CLFE (rear panel) */
9488         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
9489         /* port-H for side (rear panel) */
9490         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
9491         /* CD-in */
9492         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
9493         /* route front mic to ADC1*/
9494         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9495         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9496         /* Unmute DAC0~3 & spdif out*/
9497         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9498         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9499         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9500         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9501         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9502         
9503         /* Unmute Mixer 14 (mic) 1c (Line in)*/
9504         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9505         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9506         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9507         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9508         
9509         /* Unmute Stereo Mixer 15 */
9510         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9511         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9512         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9513         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
9514
9515         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9516         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9517         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9518         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9519         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9520         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9521         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9522         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9523         /* hp used DAC 3 (Front) */
9524         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
9525         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9526         { }
9527 };
9528
9529 static struct hda_verb alc861_asus_init_verbs[] = {
9530         /*
9531          * Unmute ADC0 and set the default input to mic-in
9532          */
9533         /* port-A for surround (rear panel)
9534          * according to codec#0 this is the HP jack
9535          */
9536         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
9537         /* route front PCM to HP */
9538         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
9539         /* port-B for mic-in (rear panel) with vref */
9540         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9541         /* port-C for line-in (rear panel) */
9542         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
9543         /* port-D for Front */
9544         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9545         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
9546         /* port-E for HP out (front panel) */
9547         /* this has to be set to VREF80 */
9548         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9549         /* route front PCM to HP */
9550         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
9551         /* port-F for mic-in (front panel) with vref */
9552         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9553         /* port-G for CLFE (rear panel) */
9554         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9555         /* port-H for side (rear panel) */
9556         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9557         /* CD-in */
9558         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
9559         /* route front mic to ADC1*/
9560         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9561         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9562         /* Unmute DAC0~3 & spdif out*/
9563         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9564         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9565         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9566         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9567         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9568         /* Unmute Mixer 14 (mic) 1c (Line in)*/
9569         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9570         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9571         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9572         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9573         
9574         /* Unmute Stereo Mixer 15 */
9575         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9576         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9577         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9578         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
9579
9580         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9581         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9582         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9583         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9584         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9585         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9586         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9587         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9588         /* hp used DAC 3 (Front) */
9589         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
9590         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9591         { }
9592 };
9593
9594 /* additional init verbs for ASUS laptops */
9595 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
9596         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
9597         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
9598         { }
9599 };
9600
9601 /*
9602  * generic initialization of ADC, input mixers and output mixers
9603  */
9604 static struct hda_verb alc861_auto_init_verbs[] = {
9605         /*
9606          * Unmute ADC0 and set the default input to mic-in
9607          */
9608         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
9609         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9610         
9611         /* Unmute DAC0~3 & spdif out*/
9612         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9613         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9614         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9615         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9616         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9617         
9618         /* Unmute Mixer 14 (mic) 1c (Line in)*/
9619         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9620         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9621         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9622         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9623         
9624         /* Unmute Stereo Mixer 15 */
9625         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9626         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9627         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9628         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
9629
9630         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9631         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9632         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9633         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9634         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9635         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9636         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9637         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9638
9639         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9640         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9641         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9642         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
9643         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9644         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9645         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9646         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
9647
9648         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
9649
9650         { }
9651 };
9652
9653 static struct hda_verb alc861_toshiba_init_verbs[] = {
9654         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9655
9656         { }
9657 };
9658
9659 /* toggle speaker-output according to the hp-jack state */
9660 static void alc861_toshiba_automute(struct hda_codec *codec)
9661 {
9662         unsigned int present;
9663
9664         present = snd_hda_codec_read(codec, 0x0f, 0,
9665                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9666         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
9667                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
9668         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
9669                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
9670 }
9671
9672 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
9673                                        unsigned int res)
9674 {
9675         if ((res >> 26) == ALC880_HP_EVENT)
9676                 alc861_toshiba_automute(codec);
9677 }
9678
9679 /* pcm configuration: identiacal with ALC880 */
9680 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
9681 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
9682 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
9683 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
9684
9685
9686 #define ALC861_DIGOUT_NID       0x07
9687
9688 static struct hda_channel_mode alc861_8ch_modes[1] = {
9689         { 8, NULL }
9690 };
9691
9692 static hda_nid_t alc861_dac_nids[4] = {
9693         /* front, surround, clfe, side */
9694         0x03, 0x06, 0x05, 0x04
9695 };
9696
9697 static hda_nid_t alc660_dac_nids[3] = {
9698         /* front, clfe, surround */
9699         0x03, 0x05, 0x06
9700 };
9701
9702 static hda_nid_t alc861_adc_nids[1] = {
9703         /* ADC0-2 */
9704         0x08,
9705 };
9706
9707 static struct hda_input_mux alc861_capture_source = {
9708         .num_items = 5,
9709         .items = {
9710                 { "Mic", 0x0 },
9711                 { "Front Mic", 0x3 },
9712                 { "Line", 0x1 },
9713                 { "CD", 0x4 },
9714                 { "Mixer", 0x5 },
9715         },
9716 };
9717
9718 /* fill in the dac_nids table from the parsed pin configuration */
9719 static int alc861_auto_fill_dac_nids(struct alc_spec *spec,
9720                                      const struct auto_pin_cfg *cfg)
9721 {
9722         int i;
9723         hda_nid_t nid;
9724
9725         spec->multiout.dac_nids = spec->private_dac_nids;
9726         for (i = 0; i < cfg->line_outs; i++) {
9727                 nid = cfg->line_out_pins[i];
9728                 if (nid) {
9729                         if (i >= ARRAY_SIZE(alc861_dac_nids))
9730                                 continue;
9731                         spec->multiout.dac_nids[i] = alc861_dac_nids[i];
9732                 }
9733         }
9734         spec->multiout.num_dacs = cfg->line_outs;
9735         return 0;
9736 }
9737
9738 /* add playback controls from the parsed DAC table */
9739 static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
9740                                              const struct auto_pin_cfg *cfg)
9741 {
9742         char name[32];
9743         static const char *chname[4] = {
9744                 "Front", "Surround", NULL /*CLFE*/, "Side"
9745         };
9746         hda_nid_t nid;
9747         int i, idx, err;
9748
9749         for (i = 0; i < cfg->line_outs; i++) {
9750                 nid = spec->multiout.dac_nids[i];
9751                 if (!nid)
9752                         continue;
9753                 if (nid == 0x05) {
9754                         /* Center/LFE */
9755                         err = add_control(spec, ALC_CTL_BIND_MUTE,
9756                                           "Center Playback Switch",
9757                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
9758                                                               HDA_OUTPUT));
9759                         if (err < 0)
9760                                 return err;
9761                         err = add_control(spec, ALC_CTL_BIND_MUTE,
9762                                           "LFE Playback Switch",
9763                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
9764                                                               HDA_OUTPUT));
9765                         if (err < 0)
9766                                 return err;
9767                 } else {
9768                         for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1;
9769                              idx++)
9770                                 if (nid == alc861_dac_nids[idx])
9771                                         break;
9772                         sprintf(name, "%s Playback Switch", chname[idx]);
9773                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
9774                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
9775                                                               HDA_OUTPUT));
9776                         if (err < 0)
9777                                 return err;
9778                 }
9779         }
9780         return 0;
9781 }
9782
9783 static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
9784 {
9785         int err;
9786         hda_nid_t nid;
9787
9788         if (!pin)
9789                 return 0;
9790
9791         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
9792                 nid = 0x03;
9793                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9794                                   "Headphone Playback Switch",
9795                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
9796                 if (err < 0)
9797                         return err;
9798                 spec->multiout.hp_nid = nid;
9799         }
9800         return 0;
9801 }
9802
9803 /* create playback/capture controls for input pins */
9804 static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec,
9805                                                 const struct auto_pin_cfg *cfg)
9806 {
9807         struct hda_input_mux *imux = &spec->private_imux;
9808         int i, err, idx, idx1;
9809
9810         for (i = 0; i < AUTO_PIN_LAST; i++) {
9811                 switch (cfg->input_pins[i]) {
9812                 case 0x0c:
9813                         idx1 = 1;
9814                         idx = 2;        /* Line In */
9815                         break;
9816                 case 0x0f:
9817                         idx1 = 2;
9818                         idx = 2;        /* Line In */
9819                         break;
9820                 case 0x0d:
9821                         idx1 = 0;
9822                         idx = 1;        /* Mic In */
9823                         break;
9824                 case 0x10:
9825                         idx1 = 3;
9826                         idx = 1;        /* Mic In */
9827                         break;
9828                 case 0x11:
9829                         idx1 = 4;
9830                         idx = 0;        /* CD */
9831                         break;
9832                 default:
9833                         continue;
9834                 }
9835
9836                 err = new_analog_input(spec, cfg->input_pins[i],
9837                                        auto_pin_cfg_labels[i], idx, 0x15);
9838                 if (err < 0)
9839                         return err;
9840
9841                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
9842                 imux->items[imux->num_items].index = idx1;
9843                 imux->num_items++;
9844         }
9845         return 0;
9846 }
9847
9848 static struct snd_kcontrol_new alc861_capture_mixer[] = {
9849         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
9850         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
9851
9852         {
9853                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9854                 /* The multiple "Capture Source" controls confuse alsamixer
9855                  * So call somewhat different..
9856                  *FIXME: the controls appear in the "playback" view!
9857                  */
9858                 /* .name = "Capture Source", */
9859                 .name = "Input Source",
9860                 .count = 1,
9861                 .info = alc_mux_enum_info,
9862                 .get = alc_mux_enum_get,
9863                 .put = alc_mux_enum_put,
9864         },
9865         { } /* end */
9866 };
9867
9868 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
9869                                               hda_nid_t nid,
9870                                               int pin_type, int dac_idx)
9871 {
9872         /* set as output */
9873
9874         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
9875                             pin_type);
9876         snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE,
9877                             AMP_OUT_UNMUTE);
9878
9879 }
9880
9881 static void alc861_auto_init_multi_out(struct hda_codec *codec)
9882 {
9883         struct alc_spec *spec = codec->spec;
9884         int i;
9885
9886         alc_subsystem_id(codec, 0x0e, 0x0f, 0x0b);
9887         for (i = 0; i < spec->autocfg.line_outs; i++) {
9888                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
9889                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
9890                 if (nid)
9891                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
9892                                                           spec->multiout.dac_nids[i]);
9893         }
9894 }
9895
9896 static void alc861_auto_init_hp_out(struct hda_codec *codec)
9897 {
9898         struct alc_spec *spec = codec->spec;
9899         hda_nid_t pin;
9900
9901         pin = spec->autocfg.hp_pins[0];
9902         if (pin) /* connect to front */
9903                 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
9904                                                   spec->multiout.dac_nids[0]);
9905 }
9906
9907 static void alc861_auto_init_analog_input(struct hda_codec *codec)
9908 {
9909         struct alc_spec *spec = codec->spec;
9910         int i;
9911
9912         for (i = 0; i < AUTO_PIN_LAST; i++) {
9913                 hda_nid_t nid = spec->autocfg.input_pins[i];
9914                 if (nid >= 0x0c && nid <= 0x11) {
9915                         snd_hda_codec_write(codec, nid, 0,
9916                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
9917                                             i <= AUTO_PIN_FRONT_MIC ?
9918                                             PIN_VREF80 : PIN_IN);
9919                 }
9920         }
9921 }
9922
9923 /* parse the BIOS configuration and set up the alc_spec */
9924 /* return 1 if successful, 0 if the proper config is not found,
9925  * or a negative error code
9926  */
9927 static int alc861_parse_auto_config(struct hda_codec *codec)
9928 {
9929         struct alc_spec *spec = codec->spec;
9930         int err;
9931         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
9932
9933         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
9934                                            alc861_ignore);
9935         if (err < 0)
9936                 return err;
9937         if (!spec->autocfg.line_outs)
9938                 return 0; /* can't find valid BIOS pin config */
9939
9940         err = alc861_auto_fill_dac_nids(spec, &spec->autocfg);
9941         if (err < 0)
9942                 return err;
9943         err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg);
9944         if (err < 0)
9945                 return err;
9946         err = alc861_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
9947         if (err < 0)
9948                 return err;
9949         err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg);
9950         if (err < 0)
9951                 return err;
9952
9953         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
9954
9955         if (spec->autocfg.dig_out_pin)
9956                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
9957
9958         if (spec->kctl_alloc)
9959                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
9960
9961         spec->init_verbs[spec->num_init_verbs++] = alc861_auto_init_verbs;
9962
9963         spec->num_mux_defs = 1;
9964         spec->input_mux = &spec->private_imux;
9965
9966         spec->adc_nids = alc861_adc_nids;
9967         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
9968         spec->mixers[spec->num_mixers] = alc861_capture_mixer;
9969         spec->num_mixers++;
9970
9971         return 1;
9972 }
9973
9974 /* additional initialization for auto-configuration model */
9975 static void alc861_auto_init(struct hda_codec *codec)
9976 {
9977         alc861_auto_init_multi_out(codec);
9978         alc861_auto_init_hp_out(codec);
9979         alc861_auto_init_analog_input(codec);
9980 }
9981
9982 #ifdef CONFIG_SND_HDA_POWER_SAVE
9983 static struct hda_amp_list alc861_loopbacks[] = {
9984         { 0x15, HDA_INPUT, 0 },
9985         { 0x15, HDA_INPUT, 1 },
9986         { 0x15, HDA_INPUT, 2 },
9987         { 0x15, HDA_INPUT, 3 },
9988         { } /* end */
9989 };
9990 #endif
9991
9992
9993 /*
9994  * configuration and preset
9995  */
9996 static const char *alc861_models[ALC861_MODEL_LAST] = {
9997         [ALC861_3ST]            = "3stack",
9998         [ALC660_3ST]            = "3stack-660",
9999         [ALC861_3ST_DIG]        = "3stack-dig",
10000         [ALC861_6ST_DIG]        = "6stack-dig",
10001         [ALC861_UNIWILL_M31]    = "uniwill-m31",
10002         [ALC861_TOSHIBA]        = "toshiba",
10003         [ALC861_ASUS]           = "asus",
10004         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
10005         [ALC861_AUTO]           = "auto",
10006 };
10007
10008 static struct snd_pci_quirk alc861_cfg_tbl[] = {
10009         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
10010         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
10011         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
10012         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
10013         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
10014         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
10015         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
10016         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
10017         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
10018          *        Any other models that need this preset?
10019          */
10020         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
10021         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
10022         SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31),
10023         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
10024         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
10025         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
10026         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
10027         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
10028         {}
10029 };
10030
10031 static struct alc_config_preset alc861_presets[] = {
10032         [ALC861_3ST] = {
10033                 .mixers = { alc861_3ST_mixer },
10034                 .init_verbs = { alc861_threestack_init_verbs },
10035                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
10036                 .dac_nids = alc861_dac_nids,
10037                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
10038                 .channel_mode = alc861_threestack_modes,
10039                 .need_dac_fix = 1,
10040                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
10041                 .adc_nids = alc861_adc_nids,
10042                 .input_mux = &alc861_capture_source,
10043         },
10044         [ALC861_3ST_DIG] = {
10045                 .mixers = { alc861_base_mixer },
10046                 .init_verbs = { alc861_threestack_init_verbs },
10047                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
10048                 .dac_nids = alc861_dac_nids,
10049                 .dig_out_nid = ALC861_DIGOUT_NID,
10050                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
10051                 .channel_mode = alc861_threestack_modes,
10052                 .need_dac_fix = 1,
10053                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
10054                 .adc_nids = alc861_adc_nids,
10055                 .input_mux = &alc861_capture_source,
10056         },
10057         [ALC861_6ST_DIG] = {
10058                 .mixers = { alc861_base_mixer },
10059                 .init_verbs = { alc861_base_init_verbs },
10060                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
10061                 .dac_nids = alc861_dac_nids,
10062                 .dig_out_nid = ALC861_DIGOUT_NID,
10063                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
10064                 .channel_mode = alc861_8ch_modes,
10065                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
10066                 .adc_nids = alc861_adc_nids,
10067                 .input_mux = &alc861_capture_source,
10068         },
10069         [ALC660_3ST] = {
10070                 .mixers = { alc861_3ST_mixer },
10071                 .init_verbs = { alc861_threestack_init_verbs },
10072                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
10073                 .dac_nids = alc660_dac_nids,
10074                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
10075                 .channel_mode = alc861_threestack_modes,
10076                 .need_dac_fix = 1,
10077                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
10078                 .adc_nids = alc861_adc_nids,
10079                 .input_mux = &alc861_capture_source,
10080         },
10081         [ALC861_UNIWILL_M31] = {
10082                 .mixers = { alc861_uniwill_m31_mixer },
10083                 .init_verbs = { alc861_uniwill_m31_init_verbs },
10084                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
10085                 .dac_nids = alc861_dac_nids,
10086                 .dig_out_nid = ALC861_DIGOUT_NID,
10087                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
10088                 .channel_mode = alc861_uniwill_m31_modes,
10089                 .need_dac_fix = 1,
10090                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
10091                 .adc_nids = alc861_adc_nids,
10092                 .input_mux = &alc861_capture_source,
10093         },
10094         [ALC861_TOSHIBA] = {
10095                 .mixers = { alc861_toshiba_mixer },
10096                 .init_verbs = { alc861_base_init_verbs,
10097                                 alc861_toshiba_init_verbs },
10098                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
10099                 .dac_nids = alc861_dac_nids,
10100                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
10101                 .channel_mode = alc883_3ST_2ch_modes,
10102                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
10103                 .adc_nids = alc861_adc_nids,
10104                 .input_mux = &alc861_capture_source,
10105                 .unsol_event = alc861_toshiba_unsol_event,
10106                 .init_hook = alc861_toshiba_automute,
10107         },
10108         [ALC861_ASUS] = {
10109                 .mixers = { alc861_asus_mixer },
10110                 .init_verbs = { alc861_asus_init_verbs },
10111                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
10112                 .dac_nids = alc861_dac_nids,
10113                 .dig_out_nid = ALC861_DIGOUT_NID,
10114                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
10115                 .channel_mode = alc861_asus_modes,
10116                 .need_dac_fix = 1,
10117                 .hp_nid = 0x06,
10118                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
10119                 .adc_nids = alc861_adc_nids,
10120                 .input_mux = &alc861_capture_source,
10121         },
10122         [ALC861_ASUS_LAPTOP] = {
10123                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
10124                 .init_verbs = { alc861_asus_init_verbs,
10125                                 alc861_asus_laptop_init_verbs },
10126                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
10127                 .dac_nids = alc861_dac_nids,
10128                 .dig_out_nid = ALC861_DIGOUT_NID,
10129                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
10130                 .channel_mode = alc883_3ST_2ch_modes,
10131                 .need_dac_fix = 1,
10132                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
10133                 .adc_nids = alc861_adc_nids,
10134                 .input_mux = &alc861_capture_source,
10135         },
10136 };
10137
10138
10139 static int patch_alc861(struct hda_codec *codec)
10140 {
10141         struct alc_spec *spec;
10142         int board_config;
10143         int err;
10144
10145         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
10146         if (spec == NULL)
10147                 return -ENOMEM;
10148
10149         codec->spec = spec;
10150
10151         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
10152                                                   alc861_models,
10153                                                   alc861_cfg_tbl);
10154
10155         if (board_config < 0) {
10156                 printk(KERN_INFO "hda_codec: Unknown model for ALC861, "
10157                        "trying auto-probe from BIOS...\n");
10158                 board_config = ALC861_AUTO;
10159         }
10160
10161         if (board_config == ALC861_AUTO) {
10162                 /* automatic parse from the BIOS config */
10163                 err = alc861_parse_auto_config(codec);
10164                 if (err < 0) {
10165                         alc_free(codec);
10166                         return err;
10167                 } else if (!err) {
10168                         printk(KERN_INFO
10169                                "hda_codec: Cannot set up configuration "
10170                                "from BIOS.  Using base mode...\n");
10171                    board_config = ALC861_3ST_DIG;
10172                 }
10173         }
10174
10175         if (board_config != ALC861_AUTO)
10176                 setup_preset(spec, &alc861_presets[board_config]);
10177
10178         spec->stream_name_analog = "ALC861 Analog";
10179         spec->stream_analog_playback = &alc861_pcm_analog_playback;
10180         spec->stream_analog_capture = &alc861_pcm_analog_capture;
10181
10182         spec->stream_name_digital = "ALC861 Digital";
10183         spec->stream_digital_playback = &alc861_pcm_digital_playback;
10184         spec->stream_digital_capture = &alc861_pcm_digital_capture;
10185
10186         codec->patch_ops = alc_patch_ops;
10187         if (board_config == ALC861_AUTO)
10188                 spec->init_hook = alc861_auto_init;
10189 #ifdef CONFIG_SND_HDA_POWER_SAVE
10190         if (!spec->loopback.amplist)
10191                 spec->loopback.amplist = alc861_loopbacks;
10192 #endif
10193                 
10194         return 0;
10195 }
10196
10197 /*
10198  * ALC861-VD support
10199  *
10200  * Based on ALC882
10201  *
10202  * In addition, an independent DAC
10203  */
10204 #define ALC861VD_DIGOUT_NID     0x06
10205
10206 static hda_nid_t alc861vd_dac_nids[4] = {
10207         /* front, surr, clfe, side surr */
10208         0x02, 0x03, 0x04, 0x05
10209 };
10210
10211 /* dac_nids for ALC660vd are in a different order - according to
10212  * Realtek's driver.
10213  * This should probably tesult in a different mixer for 6stack models
10214  * of ALC660vd codecs, but for now there is only 3stack mixer
10215  * - and it is the same as in 861vd.
10216  * adc_nids in ALC660vd are (is) the same as in 861vd
10217  */
10218 static hda_nid_t alc660vd_dac_nids[3] = {
10219         /* front, rear, clfe, rear_surr */
10220         0x02, 0x04, 0x03
10221 };
10222
10223 static hda_nid_t alc861vd_adc_nids[1] = {
10224         /* ADC0 */
10225         0x09,
10226 };
10227
10228 /* input MUX */
10229 /* FIXME: should be a matrix-type input source selection */
10230 static struct hda_input_mux alc861vd_capture_source = {
10231         .num_items = 4,
10232         .items = {
10233                 { "Mic", 0x0 },
10234                 { "Front Mic", 0x1 },
10235                 { "Line", 0x2 },
10236                 { "CD", 0x4 },
10237         },
10238 };
10239
10240 static struct hda_input_mux alc861vd_dallas_capture_source = {
10241         .num_items = 3,
10242         .items = {
10243                 { "Front Mic", 0x0 },
10244                 { "ATAPI Mic", 0x1 },
10245                 { "Line In", 0x5 },
10246         },
10247 };
10248
10249 static struct hda_input_mux alc861vd_hp_capture_source = {
10250         .num_items = 2,
10251         .items = {
10252                 { "Front Mic", 0x0 },
10253                 { "ATAPI Mic", 0x1 },
10254         },
10255 };
10256
10257 #define alc861vd_mux_enum_info alc_mux_enum_info
10258 #define alc861vd_mux_enum_get alc_mux_enum_get
10259
10260 static int alc861vd_mux_enum_put(struct snd_kcontrol *kcontrol,
10261                                 struct snd_ctl_elem_value *ucontrol)
10262 {
10263         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10264         struct alc_spec *spec = codec->spec;
10265         const struct hda_input_mux *imux = spec->input_mux;
10266         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
10267         static hda_nid_t capture_mixers[1] = { 0x22 };
10268         hda_nid_t nid = capture_mixers[adc_idx];
10269         unsigned int *cur_val = &spec->cur_mux[adc_idx];
10270         unsigned int i, idx;
10271
10272         idx = ucontrol->value.enumerated.item[0];
10273         if (idx >= imux->num_items)
10274                 idx = imux->num_items - 1;
10275         if (*cur_val == idx)
10276                 return 0;
10277         for (i = 0; i < imux->num_items; i++) {
10278                 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
10279                 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
10280                                          imux->items[i].index,
10281                                          HDA_AMP_MUTE, v);
10282         }
10283         *cur_val = idx;
10284         return 1;
10285 }
10286
10287 /*
10288  * 2ch mode
10289  */
10290 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
10291         { 2, NULL }
10292 };
10293
10294 /*
10295  * 6ch mode
10296  */
10297 static struct hda_verb alc861vd_6stack_ch6_init[] = {
10298         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
10299         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10300         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10301         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10302         { } /* end */
10303 };
10304
10305 /*
10306  * 8ch mode
10307  */
10308 static struct hda_verb alc861vd_6stack_ch8_init[] = {
10309         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10310         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10311         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10312         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10313         { } /* end */
10314 };
10315
10316 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
10317         { 6, alc861vd_6stack_ch6_init },
10318         { 8, alc861vd_6stack_ch8_init },
10319 };
10320
10321 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
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         },
10329         { } /* end */
10330 };
10331
10332 static struct snd_kcontrol_new alc861vd_capture_mixer[] = {
10333         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
10334         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
10335
10336         {
10337                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10338                 /* The multiple "Capture Source" controls confuse alsamixer
10339                  * So call somewhat different..
10340                  *FIXME: the controls appear in the "playback" view!
10341                  */
10342                 /* .name = "Capture Source", */
10343                 .name = "Input Source",
10344                 .count = 1,
10345                 .info = alc861vd_mux_enum_info,
10346                 .get = alc861vd_mux_enum_get,
10347                 .put = alc861vd_mux_enum_put,
10348         },
10349         { } /* end */
10350 };
10351
10352 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
10353  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
10354  */
10355 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
10356         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10357         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
10358
10359         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
10360         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
10361
10362         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
10363                                 HDA_OUTPUT),
10364         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
10365                                 HDA_OUTPUT),
10366         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
10367         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
10368
10369         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
10370         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
10371
10372         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10373
10374         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10375         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10376         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10377
10378         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10379         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10380         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10381
10382         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10383         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10384
10385         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10386         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10387
10388         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
10389         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
10390
10391         { } /* end */
10392 };
10393
10394 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
10395         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10396         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
10397
10398         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10399
10400         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10401         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10402         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10403
10404         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10405         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10406         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10407
10408         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10409         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10410
10411         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10412         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10413
10414         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
10415         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
10416
10417         { } /* end */
10418 };
10419
10420 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
10421         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10422         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
10423         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10424
10425         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10426
10427         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10428         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10429         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10430
10431         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10432         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10433         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10434
10435         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10436         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10437
10438         { } /* end */
10439 };
10440
10441 /* Pin assignment: Front=0x14, HP = 0x15,
10442  *                 Front Mic=0x18, ATAPI Mic = 0x19, Line In = 0x1d
10443  */
10444 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
10445         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10446         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
10447         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
10448         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
10449         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10450         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10451         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10452         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10453         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x05, HDA_INPUT),
10454         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x05, HDA_INPUT),
10455         { } /* end */
10456 };
10457
10458 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
10459  *                 Front Mic=0x18, ATAPI Mic = 0x19,
10460  */
10461 static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
10462         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10463         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
10464         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
10465         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
10466         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10467         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10468         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10469         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10470         
10471         { } /* end */
10472 };
10473
10474 /*
10475  * generic initialization of ADC, input mixers and output mixers
10476  */
10477 static struct hda_verb alc861vd_volume_init_verbs[] = {
10478         /*
10479          * Unmute ADC0 and set the default input to mic-in
10480          */
10481         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10482         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10483
10484         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
10485          * the analog-loopback mixer widget
10486          */
10487         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10488         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10489         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10490         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10491         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10492         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10493
10494         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
10495         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10496         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10497         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10498         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
10499
10500         /*
10501          * Set up output mixers (0x02 - 0x05)
10502          */
10503         /* set vol=0 to output mixers */
10504         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10505         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10506         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10507         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10508
10509         /* set up input amps for analog loopback */
10510         /* Amp Indices: DAC = 0, mixer = 1 */
10511         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10512         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10513         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10514         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10515         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10516         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10517         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10518         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10519
10520         { }
10521 };
10522
10523 /*
10524  * 3-stack pin configuration:
10525  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
10526  */
10527 static struct hda_verb alc861vd_3stack_init_verbs[] = {
10528         /*
10529          * Set pin mode and muting
10530          */
10531         /* set front pin widgets 0x14 for output */
10532         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10533         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10534         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
10535
10536         /* Mic (rear) pin: input vref at 80% */
10537         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10538         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10539         /* Front Mic pin: input vref at 80% */
10540         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10541         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10542         /* Line In pin: input */
10543         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10544         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10545         /* Line-2 In: Headphone output (output 0 - 0x0c) */
10546         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10547         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10548         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10549         /* CD pin widget for input */
10550         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10551
10552         { }
10553 };
10554
10555 /*
10556  * 6-stack pin configuration:
10557  */
10558 static struct hda_verb alc861vd_6stack_init_verbs[] = {
10559         /*
10560          * Set pin mode and muting
10561          */
10562         /* set front pin widgets 0x14 for output */
10563         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10564         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10565         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
10566
10567         /* Rear Pin: output 1 (0x0d) */
10568         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10569         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10570         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
10571         /* CLFE Pin: output 2 (0x0e) */
10572         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10573         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10574         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
10575         /* Side Pin: output 3 (0x0f) */
10576         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10577         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10578         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
10579
10580         /* Mic (rear) pin: input vref at 80% */
10581         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10582         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10583         /* Front Mic pin: input vref at 80% */
10584         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10585         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10586         /* Line In pin: input */
10587         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10588         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10589         /* Line-2 In: Headphone output (output 0 - 0x0c) */
10590         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10591         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10592         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10593         /* CD pin widget for input */
10594         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10595
10596         { }
10597 };
10598
10599 static struct hda_verb alc861vd_eapd_verbs[] = {
10600         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
10601         { }
10602 };
10603
10604 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
10605         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10606         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10607         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10608         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10609         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT}, 
10610         {}
10611 };
10612
10613 /* toggle speaker-output according to the hp-jack state */
10614 static void alc861vd_lenovo_hp_automute(struct hda_codec *codec)
10615 {
10616         unsigned int present;
10617         unsigned char bits;
10618
10619         present = snd_hda_codec_read(codec, 0x1b, 0,
10620                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10621         bits = present ? HDA_AMP_MUTE : 0;
10622         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10623                                  HDA_AMP_MUTE, bits);
10624 }
10625
10626 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
10627 {
10628         unsigned int present;
10629         unsigned char bits;
10630
10631         present = snd_hda_codec_read(codec, 0x18, 0,
10632                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10633         bits = present ? HDA_AMP_MUTE : 0;
10634         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
10635                                  HDA_AMP_MUTE, bits);
10636 }
10637
10638 static void alc861vd_lenovo_automute(struct hda_codec *codec)
10639 {
10640         alc861vd_lenovo_hp_automute(codec);
10641         alc861vd_lenovo_mic_automute(codec);
10642 }
10643
10644 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
10645                                         unsigned int res)
10646 {
10647         switch (res >> 26) {
10648         case ALC880_HP_EVENT:
10649                 alc861vd_lenovo_hp_automute(codec);
10650                 break;
10651         case ALC880_MIC_EVENT:
10652                 alc861vd_lenovo_mic_automute(codec);
10653                 break;
10654         }
10655 }
10656
10657 static struct hda_verb alc861vd_dallas_verbs[] = {
10658         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10659         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10660         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10661         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10662
10663         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10664         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10665         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10666         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10667         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10668         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10669         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10670         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10671         
10672         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10673         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10674         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10675         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10676         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10677         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10678         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10679         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10680
10681         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
10682         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10683         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
10684         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10685         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10686         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10687         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10688         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10689
10690         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10691         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10692         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10693         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10694
10695         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10696         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},  
10697         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10698
10699         { } /* end */
10700 };
10701
10702 /* toggle speaker-output according to the hp-jack state */
10703 static void alc861vd_dallas_automute(struct hda_codec *codec)
10704 {
10705         unsigned int present;
10706
10707         present = snd_hda_codec_read(codec, 0x15, 0,
10708                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10709         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10710                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
10711 }
10712
10713 static void alc861vd_dallas_unsol_event(struct hda_codec *codec, unsigned int res)
10714 {
10715         if ((res >> 26) == ALC880_HP_EVENT)
10716                 alc861vd_dallas_automute(codec);
10717 }
10718
10719 #ifdef CONFIG_SND_HDA_POWER_SAVE
10720 #define alc861vd_loopbacks      alc880_loopbacks
10721 #endif
10722
10723 /* pcm configuration: identiacal with ALC880 */
10724 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
10725 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
10726 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
10727 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
10728
10729 /*
10730  * configuration and preset
10731  */
10732 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
10733         [ALC660VD_3ST]          = "3stack-660",
10734         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
10735         [ALC861VD_3ST]          = "3stack",
10736         [ALC861VD_3ST_DIG]      = "3stack-digout",
10737         [ALC861VD_6ST_DIG]      = "6stack-digout",
10738         [ALC861VD_LENOVO]       = "lenovo",
10739         [ALC861VD_DALLAS]       = "dallas",
10740         [ALC861VD_HP]           = "hp",
10741         [ALC861VD_AUTO]         = "auto",
10742 };
10743
10744 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
10745         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
10746         SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),
10747         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
10748         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
10749         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
10750
10751         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
10752         SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS),
10753         SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo 3000 C200", ALC861VD_LENOVO),
10754         SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo", ALC861VD_LENOVO),
10755         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
10756         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
10757         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
10758         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
10759         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
10760         {}
10761 };
10762
10763 static struct alc_config_preset alc861vd_presets[] = {
10764         [ALC660VD_3ST] = {
10765                 .mixers = { alc861vd_3st_mixer },
10766                 .init_verbs = { alc861vd_volume_init_verbs,
10767                                  alc861vd_3stack_init_verbs },
10768                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
10769                 .dac_nids = alc660vd_dac_nids,
10770                 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
10771                 .adc_nids = alc861vd_adc_nids,
10772                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
10773                 .channel_mode = alc861vd_3stack_2ch_modes,
10774                 .input_mux = &alc861vd_capture_source,
10775         },
10776         [ALC660VD_3ST_DIG] = {
10777                 .mixers = { alc861vd_3st_mixer },
10778                 .init_verbs = { alc861vd_volume_init_verbs,
10779                                  alc861vd_3stack_init_verbs },
10780                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
10781                 .dac_nids = alc660vd_dac_nids,
10782                 .dig_out_nid = ALC861VD_DIGOUT_NID,
10783                 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
10784                 .adc_nids = alc861vd_adc_nids,
10785                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
10786                 .channel_mode = alc861vd_3stack_2ch_modes,
10787                 .input_mux = &alc861vd_capture_source,
10788         },
10789         [ALC861VD_3ST] = {
10790                 .mixers = { alc861vd_3st_mixer },
10791                 .init_verbs = { alc861vd_volume_init_verbs,
10792                                  alc861vd_3stack_init_verbs },
10793                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
10794                 .dac_nids = alc861vd_dac_nids,
10795                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
10796                 .channel_mode = alc861vd_3stack_2ch_modes,
10797                 .input_mux = &alc861vd_capture_source,
10798         },
10799         [ALC861VD_3ST_DIG] = {
10800                 .mixers = { alc861vd_3st_mixer },
10801                 .init_verbs = { alc861vd_volume_init_verbs,
10802                                  alc861vd_3stack_init_verbs },
10803                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
10804                 .dac_nids = alc861vd_dac_nids,
10805                 .dig_out_nid = ALC861VD_DIGOUT_NID,
10806                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
10807                 .channel_mode = alc861vd_3stack_2ch_modes,
10808                 .input_mux = &alc861vd_capture_source,
10809         },
10810         [ALC861VD_6ST_DIG] = {
10811                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
10812                 .init_verbs = { alc861vd_volume_init_verbs,
10813                                 alc861vd_6stack_init_verbs },
10814                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
10815                 .dac_nids = alc861vd_dac_nids,
10816                 .dig_out_nid = ALC861VD_DIGOUT_NID,
10817                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
10818                 .channel_mode = alc861vd_6stack_modes,
10819                 .input_mux = &alc861vd_capture_source,
10820         },
10821         [ALC861VD_LENOVO] = {
10822                 .mixers = { alc861vd_lenovo_mixer },
10823                 .init_verbs = { alc861vd_volume_init_verbs,
10824                                 alc861vd_3stack_init_verbs,
10825                                 alc861vd_eapd_verbs,
10826                                 alc861vd_lenovo_unsol_verbs },
10827                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
10828                 .dac_nids = alc660vd_dac_nids,
10829                 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
10830                 .adc_nids = alc861vd_adc_nids,
10831                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
10832                 .channel_mode = alc861vd_3stack_2ch_modes,
10833                 .input_mux = &alc861vd_capture_source,
10834                 .unsol_event = alc861vd_lenovo_unsol_event,
10835                 .init_hook = alc861vd_lenovo_automute,
10836         },
10837         [ALC861VD_DALLAS] = {
10838                 .mixers = { alc861vd_dallas_mixer },
10839                 .init_verbs = { alc861vd_dallas_verbs },
10840                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
10841                 .dac_nids = alc861vd_dac_nids,
10842                 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
10843                 .adc_nids = alc861vd_adc_nids,
10844                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
10845                 .channel_mode = alc861vd_3stack_2ch_modes,
10846                 .input_mux = &alc861vd_dallas_capture_source,
10847                 .unsol_event = alc861vd_dallas_unsol_event,
10848                 .init_hook = alc861vd_dallas_automute,
10849         },
10850         [ALC861VD_HP] = {
10851                 .mixers = { alc861vd_hp_mixer },
10852                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
10853                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
10854                 .dac_nids = alc861vd_dac_nids,
10855                 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
10856                 .dig_out_nid = ALC861VD_DIGOUT_NID,
10857                 .adc_nids = alc861vd_adc_nids,
10858                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
10859                 .channel_mode = alc861vd_3stack_2ch_modes,
10860                 .input_mux = &alc861vd_hp_capture_source,
10861                 .unsol_event = alc861vd_dallas_unsol_event,
10862                 .init_hook = alc861vd_dallas_automute,
10863         },              
10864 };
10865
10866 /*
10867  * BIOS auto configuration
10868  */
10869 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
10870                                 hda_nid_t nid, int pin_type, int dac_idx)
10871 {
10872         /* set as output */
10873         snd_hda_codec_write(codec, nid, 0,
10874                                 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
10875         snd_hda_codec_write(codec, nid, 0,
10876                                 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
10877 }
10878
10879 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
10880 {
10881         struct alc_spec *spec = codec->spec;
10882         int i;
10883
10884         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
10885         for (i = 0; i <= HDA_SIDE; i++) {
10886                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
10887                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
10888                 if (nid)
10889                         alc861vd_auto_set_output_and_unmute(codec, nid,
10890                                                             pin_type, i);
10891         }
10892 }
10893
10894
10895 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
10896 {
10897         struct alc_spec *spec = codec->spec;
10898         hda_nid_t pin;
10899
10900         pin = spec->autocfg.hp_pins[0];
10901         if (pin) /* connect to front and  use dac 0 */
10902                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
10903 }
10904
10905 #define alc861vd_is_input_pin(nid)      alc880_is_input_pin(nid)
10906 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
10907
10908 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
10909 {
10910         struct alc_spec *spec = codec->spec;
10911         int i;
10912
10913         for (i = 0; i < AUTO_PIN_LAST; i++) {
10914                 hda_nid_t nid = spec->autocfg.input_pins[i];
10915                 if (alc861vd_is_input_pin(nid)) {
10916                         snd_hda_codec_write(codec, nid, 0,
10917                                         AC_VERB_SET_PIN_WIDGET_CONTROL,
10918                                         i <= AUTO_PIN_FRONT_MIC ?
10919                                                         PIN_VREF80 : PIN_IN);
10920                         if (nid != ALC861VD_PIN_CD_NID)
10921                                 snd_hda_codec_write(codec, nid, 0,
10922                                                 AC_VERB_SET_AMP_GAIN_MUTE,
10923                                                 AMP_OUT_MUTE);
10924                 }
10925         }
10926 }
10927
10928 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
10929 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
10930
10931 /* add playback controls from the parsed DAC table */
10932 /* Based on ALC880 version. But ALC861VD has separate,
10933  * different NIDs for mute/unmute switch and volume control */
10934 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
10935                                              const struct auto_pin_cfg *cfg)
10936 {
10937         char name[32];
10938         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
10939         hda_nid_t nid_v, nid_s;
10940         int i, err;
10941
10942         for (i = 0; i < cfg->line_outs; i++) {
10943                 if (!spec->multiout.dac_nids[i])
10944                         continue;
10945                 nid_v = alc861vd_idx_to_mixer_vol(
10946                                 alc880_dac_to_idx(
10947                                         spec->multiout.dac_nids[i]));
10948                 nid_s = alc861vd_idx_to_mixer_switch(
10949                                 alc880_dac_to_idx(
10950                                         spec->multiout.dac_nids[i]));
10951
10952                 if (i == 2) {
10953                         /* Center/LFE */
10954                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10955                                           "Center Playback Volume",
10956                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
10957                                                               HDA_OUTPUT));
10958                         if (err < 0)
10959                                 return err;
10960                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10961                                           "LFE Playback Volume",
10962                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
10963                                                               HDA_OUTPUT));
10964                         if (err < 0)
10965                                 return err;
10966                         err = add_control(spec, ALC_CTL_BIND_MUTE,
10967                                           "Center Playback Switch",
10968                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
10969                                                               HDA_INPUT));
10970                         if (err < 0)
10971                                 return err;
10972                         err = add_control(spec, ALC_CTL_BIND_MUTE,
10973                                           "LFE Playback Switch",
10974                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
10975                                                               HDA_INPUT));
10976                         if (err < 0)
10977                                 return err;
10978                 } else {
10979                         sprintf(name, "%s Playback Volume", chname[i]);
10980                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
10981                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
10982                                                               HDA_OUTPUT));
10983                         if (err < 0)
10984                                 return err;
10985                         sprintf(name, "%s Playback Switch", chname[i]);
10986                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
10987                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
10988                                                               HDA_INPUT));
10989                         if (err < 0)
10990                                 return err;
10991                 }
10992         }
10993         return 0;
10994 }
10995
10996 /* add playback controls for speaker and HP outputs */
10997 /* Based on ALC880 version. But ALC861VD has separate,
10998  * different NIDs for mute/unmute switch and volume control */
10999 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
11000                                         hda_nid_t pin, const char *pfx)
11001 {
11002         hda_nid_t nid_v, nid_s;
11003         int err;
11004         char name[32];
11005
11006         if (!pin)
11007                 return 0;
11008
11009         if (alc880_is_fixed_pin(pin)) {
11010                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
11011                 /* specify the DAC as the extra output */
11012                 if (!spec->multiout.hp_nid)
11013                         spec->multiout.hp_nid = nid_v;
11014                 else
11015                         spec->multiout.extra_out_nid[0] = nid_v;
11016                 /* control HP volume/switch on the output mixer amp */
11017                 nid_v = alc861vd_idx_to_mixer_vol(
11018                                 alc880_fixed_pin_idx(pin));
11019                 nid_s = alc861vd_idx_to_mixer_switch(
11020                                 alc880_fixed_pin_idx(pin));
11021
11022                 sprintf(name, "%s Playback Volume", pfx);
11023                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11024                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
11025                 if (err < 0)
11026                         return err;
11027                 sprintf(name, "%s Playback Switch", pfx);
11028                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
11029                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
11030                 if (err < 0)
11031                         return err;
11032         } else if (alc880_is_multi_pin(pin)) {
11033                 /* set manual connection */
11034                 /* we have only a switch on HP-out PIN */
11035                 sprintf(name, "%s Playback Switch", pfx);
11036                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
11037                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
11038                 if (err < 0)
11039                         return err;
11040         }
11041         return 0;
11042 }
11043
11044 /* parse the BIOS configuration and set up the alc_spec
11045  * return 1 if successful, 0 if the proper config is not found,
11046  * or a negative error code
11047  * Based on ALC880 version - had to change it to override
11048  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
11049 static int alc861vd_parse_auto_config(struct hda_codec *codec)
11050 {
11051         struct alc_spec *spec = codec->spec;
11052         int err;
11053         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
11054
11055         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11056                                            alc861vd_ignore);
11057         if (err < 0)
11058                 return err;
11059         if (!spec->autocfg.line_outs)
11060                 return 0; /* can't find valid BIOS pin config */
11061
11062         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
11063         if (err < 0)
11064                 return err;
11065         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
11066         if (err < 0)
11067                 return err;
11068         err = alc861vd_auto_create_extra_out(spec,
11069                                              spec->autocfg.speaker_pins[0],
11070                                              "Speaker");
11071         if (err < 0)
11072                 return err;
11073         err = alc861vd_auto_create_extra_out(spec,
11074                                              spec->autocfg.hp_pins[0],
11075                                              "Headphone");
11076         if (err < 0)
11077                 return err;
11078         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
11079         if (err < 0)
11080                 return err;
11081
11082         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
11083
11084         if (spec->autocfg.dig_out_pin)
11085                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
11086
11087         if (spec->kctl_alloc)
11088                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
11089
11090         spec->init_verbs[spec->num_init_verbs++]
11091                 = alc861vd_volume_init_verbs;
11092
11093         spec->num_mux_defs = 1;
11094         spec->input_mux = &spec->private_imux;
11095
11096         return 1;
11097 }
11098
11099 /* additional initialization for auto-configuration model */
11100 static void alc861vd_auto_init(struct hda_codec *codec)
11101 {
11102         alc861vd_auto_init_multi_out(codec);
11103         alc861vd_auto_init_hp_out(codec);
11104         alc861vd_auto_init_analog_input(codec);
11105 }
11106
11107 static int patch_alc861vd(struct hda_codec *codec)
11108 {
11109         struct alc_spec *spec;
11110         int err, board_config;
11111
11112         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
11113         if (spec == NULL)
11114                 return -ENOMEM;
11115
11116         codec->spec = spec;
11117
11118         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
11119                                                   alc861vd_models,
11120                                                   alc861vd_cfg_tbl);
11121
11122         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
11123                 printk(KERN_INFO "hda_codec: Unknown model for ALC660VD/"
11124                         "ALC861VD, trying auto-probe from BIOS...\n");
11125                 board_config = ALC861VD_AUTO;
11126         }
11127
11128         if (board_config == ALC861VD_AUTO) {
11129                 /* automatic parse from the BIOS config */
11130                 err = alc861vd_parse_auto_config(codec);
11131                 if (err < 0) {
11132                         alc_free(codec);
11133                         return err;
11134                 } else if (!err) {
11135                         printk(KERN_INFO
11136                                "hda_codec: Cannot set up configuration "
11137                                "from BIOS.  Using base mode...\n");
11138                         board_config = ALC861VD_3ST;
11139                 }
11140         }
11141
11142         if (board_config != ALC861VD_AUTO)
11143                 setup_preset(spec, &alc861vd_presets[board_config]);
11144
11145         spec->stream_name_analog = "ALC861VD Analog";
11146         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
11147         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
11148
11149         spec->stream_name_digital = "ALC861VD Digital";
11150         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
11151         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
11152
11153         spec->adc_nids = alc861vd_adc_nids;
11154         spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
11155
11156         spec->mixers[spec->num_mixers] = alc861vd_capture_mixer;
11157         spec->num_mixers++;
11158
11159         codec->patch_ops = alc_patch_ops;
11160
11161         if (board_config == ALC861VD_AUTO)
11162                 spec->init_hook = alc861vd_auto_init;
11163 #ifdef CONFIG_SND_HDA_POWER_SAVE
11164         if (!spec->loopback.amplist)
11165                 spec->loopback.amplist = alc861vd_loopbacks;
11166 #endif
11167
11168         return 0;
11169 }
11170
11171 /*
11172  * ALC662 support
11173  *
11174  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
11175  * configuration.  Each pin widget can choose any input DACs and a mixer.
11176  * Each ADC is connected from a mixer of all inputs.  This makes possible
11177  * 6-channel independent captures.
11178  *
11179  * In addition, an independent DAC for the multi-playback (not used in this
11180  * driver yet).
11181  */
11182 #define ALC662_DIGOUT_NID       0x06
11183 #define ALC662_DIGIN_NID        0x0a
11184
11185 static hda_nid_t alc662_dac_nids[4] = {
11186         /* front, rear, clfe, rear_surr */
11187         0x02, 0x03, 0x04
11188 };
11189
11190 static hda_nid_t alc662_adc_nids[1] = {
11191         /* ADC1-2 */
11192         0x09,
11193 };
11194 /* input MUX */
11195 /* FIXME: should be a matrix-type input source selection */
11196
11197 static struct hda_input_mux alc662_capture_source = {
11198         .num_items = 4,
11199         .items = {
11200                 { "Mic", 0x0 },
11201                 { "Front Mic", 0x1 },
11202                 { "Line", 0x2 },
11203                 { "CD", 0x4 },
11204         },
11205 };
11206
11207 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
11208         .num_items = 2,
11209         .items = {
11210                 { "Mic", 0x1 },
11211                 { "Line", 0x2 },
11212         },
11213 };
11214 #define alc662_mux_enum_info alc_mux_enum_info
11215 #define alc662_mux_enum_get alc_mux_enum_get
11216
11217 static int alc662_mux_enum_put(struct snd_kcontrol *kcontrol,
11218                                struct snd_ctl_elem_value *ucontrol)
11219 {
11220         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
11221         struct alc_spec *spec = codec->spec;
11222         const struct hda_input_mux *imux = spec->input_mux;
11223         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
11224         static hda_nid_t capture_mixers[2] = { 0x23, 0x22 };
11225         hda_nid_t nid = capture_mixers[adc_idx];
11226         unsigned int *cur_val = &spec->cur_mux[adc_idx];
11227         unsigned int i, idx;
11228
11229         idx = ucontrol->value.enumerated.item[0];
11230         if (idx >= imux->num_items)
11231                 idx = imux->num_items - 1;
11232         if (*cur_val == idx)
11233                 return 0;
11234         for (i = 0; i < imux->num_items; i++) {
11235                 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
11236                 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
11237                                          imux->items[i].index,
11238                                          HDA_AMP_MUTE, v);
11239         }
11240         *cur_val = idx;
11241         return 1;
11242 }
11243 /*
11244  * 2ch mode
11245  */
11246 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
11247         { 2, NULL }
11248 };
11249
11250 /*
11251  * 2ch mode
11252  */
11253 static struct hda_verb alc662_3ST_ch2_init[] = {
11254         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
11255         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
11256         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
11257         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
11258         { } /* end */
11259 };
11260
11261 /*
11262  * 6ch mode
11263  */
11264 static struct hda_verb alc662_3ST_ch6_init[] = {
11265         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11266         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11267         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
11268         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11269         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11270         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
11271         { } /* end */
11272 };
11273
11274 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
11275         { 2, alc662_3ST_ch2_init },
11276         { 6, alc662_3ST_ch6_init },
11277 };
11278
11279 /*
11280  * 2ch mode
11281  */
11282 static struct hda_verb alc662_sixstack_ch6_init[] = {
11283         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11284         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11285         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11286         { } /* end */
11287 };
11288
11289 /*
11290  * 6ch mode
11291  */
11292 static struct hda_verb alc662_sixstack_ch8_init[] = {
11293         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11294         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11295         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11296         { } /* end */
11297 };
11298
11299 static struct hda_channel_mode alc662_5stack_modes[2] = {
11300         { 2, alc662_sixstack_ch6_init },
11301         { 6, alc662_sixstack_ch8_init },
11302 };
11303
11304 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
11305  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
11306  */
11307
11308 static struct snd_kcontrol_new alc662_base_mixer[] = {
11309         /* output mixer control */
11310         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
11311         HDA_CODEC_MUTE("Front Playback Switch", 0x02, 0x0, HDA_OUTPUT),
11312         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
11313         HDA_CODEC_MUTE("Surround Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11314         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
11315         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
11316         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
11317         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
11318         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
11319
11320         /*Input mixer control */
11321         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
11322         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
11323         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
11324         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
11325         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
11326         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
11327         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
11328         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
11329
11330         /* Capture mixer control */
11331         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
11332         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
11333         {
11334                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11335                 .name = "Capture Source",
11336                 .count = 1,
11337                 .info = alc_mux_enum_info,
11338                 .get = alc_mux_enum_get,
11339                 .put = alc_mux_enum_put,
11340         },
11341         { } /* end */
11342 };
11343
11344 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
11345         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11346         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
11347         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
11348         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
11349         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
11350         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
11351         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11352         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11353         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11354         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
11355         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
11356         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
11357         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
11358         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
11359         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
11360         {
11361                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11362                 /* .name = "Capture Source", */
11363                 .name = "Input Source",
11364                 .count = 1,
11365                 .info = alc662_mux_enum_info,
11366                 .get = alc662_mux_enum_get,
11367                 .put = alc662_mux_enum_put,
11368         },
11369         { } /* end */
11370 };
11371
11372 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
11373         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11374         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
11375         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11376         HDA_BIND_MUTE("Surround Playback Switch", 0x03, 2, HDA_INPUT),
11377         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
11378         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
11379         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
11380         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
11381         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
11382         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
11383         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
11384         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
11385         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11386         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11387         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11388         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
11389         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
11390         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
11391         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
11392         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
11393         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
11394         {
11395                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11396                 /* .name = "Capture Source", */
11397                 .name = "Input Source",
11398                 .count = 1,
11399                 .info = alc662_mux_enum_info,
11400                 .get = alc662_mux_enum_get,
11401                 .put = alc662_mux_enum_put,
11402         },
11403         { } /* end */
11404 };
11405
11406 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
11407         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11408         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
11409         HDA_CODEC_VOLUME("iSpeaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11410         HDA_BIND_MUTE("iSpeaker Playback Switch", 0x03, 2, HDA_INPUT),
11411         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
11412         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
11413         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11414         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
11415         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
11416         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
11417         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
11418         {
11419                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11420                 /* .name = "Capture Source", */
11421                 .name = "Input Source",
11422                 .count = 1,
11423                 .info = alc662_mux_enum_info,
11424                 .get = alc662_mux_enum_get,
11425                 .put = alc662_mux_enum_put,
11426         },
11427         { } /* end */
11428 };
11429
11430 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
11431         {
11432                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11433                 .name = "Channel Mode",
11434                 .info = alc_ch_mode_info,
11435                 .get = alc_ch_mode_get,
11436                 .put = alc_ch_mode_put,
11437         },
11438         { } /* end */
11439 };
11440
11441 static struct hda_verb alc662_init_verbs[] = {
11442         /* ADC: mute amp left and right */
11443         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11444         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
11445         /* Front mixer: unmute input/output amp left and right (volume = 0) */
11446
11447         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11448         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11449         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11450         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11451         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11452
11453         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11454         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11455         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11456         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11457         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11458         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11459
11460         /* Front Pin: output 0 (0x0c) */
11461         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11462         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11463
11464         /* Rear Pin: output 1 (0x0d) */
11465         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11466         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11467
11468         /* CLFE Pin: output 2 (0x0e) */
11469         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11470         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11471
11472         /* Mic (rear) pin: input vref at 80% */
11473         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11474         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11475         /* Front Mic pin: input vref at 80% */
11476         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11477         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11478         /* Line In pin: input */
11479         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11480         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11481         /* Line-2 In: Headphone output (output 0 - 0x0c) */
11482         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11483         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11484         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
11485         /* CD pin widget for input */
11486         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11487
11488         /* FIXME: use matrix-type input source selection */
11489         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
11490         /* Input mixer */
11491         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11492         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11493         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11494         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
11495         { }
11496 };
11497
11498 static struct hda_verb alc662_sue_init_verbs[] = {
11499         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
11500         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
11501         {}
11502 };
11503
11504 /*
11505  * generic initialization of ADC, input mixers and output mixers
11506  */
11507 static struct hda_verb alc662_auto_init_verbs[] = {
11508         /*
11509          * Unmute ADC and set the default input to mic-in
11510          */
11511         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
11512         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11513
11514         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
11515          * mixer widget
11516          * Note: PASD motherboards uses the Line In 2 as the input for front
11517          * panel mic (mic 2)
11518          */
11519         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11520         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11521         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11522         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11523         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11524         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11525
11526         /*
11527          * Set up output mixers (0x0c - 0x0f)
11528          */
11529         /* set vol=0 to output mixers */
11530         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11531         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11532         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11533
11534         /* set up input amps for analog loopback */
11535         /* Amp Indices: DAC = 0, mixer = 1 */
11536         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11537         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11538         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11539         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11540         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11541         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11542
11543
11544         /* FIXME: use matrix-type input source selection */
11545         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
11546         /* Input mixer */
11547         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11548         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11549         { }
11550 };
11551
11552 /* capture mixer elements */
11553 static struct snd_kcontrol_new alc662_capture_mixer[] = {
11554         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
11555         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
11556         {
11557                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11558                 /* The multiple "Capture Source" controls confuse alsamixer
11559                  * So call somewhat different..
11560                  * FIXME: the controls appear in the "playback" view!
11561                  */
11562                 /* .name = "Capture Source", */
11563                 .name = "Input Source",
11564                 .count = 1,
11565                 .info = alc882_mux_enum_info,
11566                 .get = alc882_mux_enum_get,
11567                 .put = alc882_mux_enum_put,
11568         },
11569         { } /* end */
11570 };
11571
11572 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
11573 {
11574         unsigned int present;
11575         unsigned char bits;
11576
11577         present = snd_hda_codec_read(codec, 0x14, 0,
11578                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11579         bits = present ? HDA_AMP_MUTE : 0;
11580         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
11581                                  HDA_AMP_MUTE, bits);
11582 }
11583
11584 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
11585 {
11586         unsigned int present;
11587         unsigned char bits;
11588
11589         present = snd_hda_codec_read(codec, 0x1b, 0,
11590                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11591         bits = present ? HDA_AMP_MUTE : 0;
11592         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
11593                                  HDA_AMP_MUTE, bits);
11594         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
11595                                  HDA_AMP_MUTE, bits);
11596 }
11597
11598 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
11599                                            unsigned int res)
11600 {
11601         if ((res >> 26) == ALC880_HP_EVENT)
11602                 alc662_lenovo_101e_all_automute(codec);
11603         if ((res >> 26) == ALC880_FRONT_EVENT)
11604                 alc662_lenovo_101e_ispeaker_automute(codec);
11605 }
11606
11607 #ifdef CONFIG_SND_HDA_POWER_SAVE
11608 #define alc662_loopbacks        alc880_loopbacks
11609 #endif
11610
11611
11612 /* pcm configuration: identiacal with ALC880 */
11613 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
11614 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
11615 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
11616 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
11617
11618 /*
11619  * configuration and preset
11620  */
11621 static const char *alc662_models[ALC662_MODEL_LAST] = {
11622         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
11623         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
11624         [ALC662_3ST_6ch]        = "3stack-6ch",
11625         [ALC662_5ST_DIG]        = "6stack-dig",
11626         [ALC662_LENOVO_101E]    = "lenovo-101e",
11627         [ALC662_AUTO]           = "auto",
11628 };
11629
11630 static struct snd_pci_quirk alc662_cfg_tbl[] = {
11631         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
11632         {}
11633 };
11634
11635 static struct alc_config_preset alc662_presets[] = {
11636         [ALC662_3ST_2ch_DIG] = {
11637                 .mixers = { alc662_3ST_2ch_mixer },
11638                 .init_verbs = { alc662_init_verbs },
11639                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
11640                 .dac_nids = alc662_dac_nids,
11641                 .dig_out_nid = ALC662_DIGOUT_NID,
11642                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
11643                 .adc_nids = alc662_adc_nids,
11644                 .dig_in_nid = ALC662_DIGIN_NID,
11645                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
11646                 .channel_mode = alc662_3ST_2ch_modes,
11647                 .input_mux = &alc662_capture_source,
11648         },
11649         [ALC662_3ST_6ch_DIG] = {
11650                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
11651                 .init_verbs = { alc662_init_verbs },
11652                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
11653                 .dac_nids = alc662_dac_nids,
11654                 .dig_out_nid = ALC662_DIGOUT_NID,
11655                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
11656                 .adc_nids = alc662_adc_nids,
11657                 .dig_in_nid = ALC662_DIGIN_NID,
11658                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
11659                 .channel_mode = alc662_3ST_6ch_modes,
11660                 .need_dac_fix = 1,
11661                 .input_mux = &alc662_capture_source,
11662         },
11663         [ALC662_3ST_6ch] = {
11664                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
11665                 .init_verbs = { alc662_init_verbs },
11666                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
11667                 .dac_nids = alc662_dac_nids,
11668                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
11669                 .adc_nids = alc662_adc_nids,
11670                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
11671                 .channel_mode = alc662_3ST_6ch_modes,
11672                 .need_dac_fix = 1,
11673                 .input_mux = &alc662_capture_source,
11674         },
11675         [ALC662_5ST_DIG] = {
11676                 .mixers = { alc662_base_mixer, alc662_chmode_mixer },
11677                 .init_verbs = { alc662_init_verbs },
11678                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
11679                 .dac_nids = alc662_dac_nids,
11680                 .dig_out_nid = ALC662_DIGOUT_NID,
11681                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
11682                 .adc_nids = alc662_adc_nids,
11683                 .dig_in_nid = ALC662_DIGIN_NID,
11684                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
11685                 .channel_mode = alc662_5stack_modes,
11686                 .input_mux = &alc662_capture_source,
11687         },
11688         [ALC662_LENOVO_101E] = {
11689                 .mixers = { alc662_lenovo_101e_mixer },
11690                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
11691                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
11692                 .dac_nids = alc662_dac_nids,
11693                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
11694                 .adc_nids = alc662_adc_nids,
11695                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
11696                 .channel_mode = alc662_3ST_2ch_modes,
11697                 .input_mux = &alc662_lenovo_101e_capture_source,
11698                 .unsol_event = alc662_lenovo_101e_unsol_event,
11699                 .init_hook = alc662_lenovo_101e_all_automute,
11700         },
11701
11702 };
11703
11704
11705 /*
11706  * BIOS auto configuration
11707  */
11708
11709 /* add playback controls from the parsed DAC table */
11710 static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec,
11711                                              const struct auto_pin_cfg *cfg)
11712 {
11713         char name[32];
11714         static const char *chname[4] = {
11715                 "Front", "Surround", NULL /*CLFE*/, "Side"
11716         };
11717         hda_nid_t nid;
11718         int i, err;
11719
11720         for (i = 0; i < cfg->line_outs; i++) {
11721                 if (!spec->multiout.dac_nids[i])
11722                         continue;
11723                 nid = alc880_idx_to_mixer(i);
11724                 if (i == 2) {
11725                         /* Center/LFE */
11726                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
11727                                           "Center Playback Volume",
11728                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
11729                                                               HDA_OUTPUT));
11730                         if (err < 0)
11731                                 return err;
11732                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
11733                                           "LFE Playback Volume",
11734                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
11735                                                               HDA_OUTPUT));
11736                         if (err < 0)
11737                                 return err;
11738                         err = add_control(spec, ALC_CTL_BIND_MUTE,
11739                                           "Center Playback Switch",
11740                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
11741                                                               HDA_INPUT));
11742                         if (err < 0)
11743                                 return err;
11744                         err = add_control(spec, ALC_CTL_BIND_MUTE,
11745                                           "LFE Playback Switch",
11746                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
11747                                                               HDA_INPUT));
11748                         if (err < 0)
11749                                 return err;
11750                 } else {
11751                         sprintf(name, "%s Playback Volume", chname[i]);
11752                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11753                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
11754                                                               HDA_OUTPUT));
11755                         if (err < 0)
11756                                 return err;
11757                         sprintf(name, "%s Playback Switch", chname[i]);
11758                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
11759                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
11760                                                               HDA_INPUT));
11761                         if (err < 0)
11762                                 return err;
11763                 }
11764         }
11765         return 0;
11766 }
11767
11768 /* add playback controls for speaker and HP outputs */
11769 static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
11770                                         const char *pfx)
11771 {
11772         hda_nid_t nid;
11773         int err;
11774         char name[32];
11775
11776         if (!pin)
11777                 return 0;
11778
11779         if (alc880_is_fixed_pin(pin)) {
11780                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
11781                 /* printk("DAC nid=%x\n",nid); */
11782                 /* specify the DAC as the extra output */
11783                 if (!spec->multiout.hp_nid)
11784                         spec->multiout.hp_nid = nid;
11785                 else
11786                         spec->multiout.extra_out_nid[0] = nid;
11787                 /* control HP volume/switch on the output mixer amp */
11788                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
11789                 sprintf(name, "%s Playback Volume", pfx);
11790                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11791                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
11792                 if (err < 0)
11793                         return err;
11794                 sprintf(name, "%s Playback Switch", pfx);
11795                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
11796                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
11797                 if (err < 0)
11798                         return err;
11799         } else if (alc880_is_multi_pin(pin)) {
11800                 /* set manual connection */
11801                 /* we have only a switch on HP-out PIN */
11802                 sprintf(name, "%s Playback Switch", pfx);
11803                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
11804                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
11805                 if (err < 0)
11806                         return err;
11807         }
11808         return 0;
11809 }
11810
11811 /* create playback/capture controls for input pins */
11812 static int alc662_auto_create_analog_input_ctls(struct alc_spec *spec,
11813                                                 const struct auto_pin_cfg *cfg)
11814 {
11815         struct hda_input_mux *imux = &spec->private_imux;
11816         int i, err, idx;
11817
11818         for (i = 0; i < AUTO_PIN_LAST; i++) {
11819                 if (alc880_is_input_pin(cfg->input_pins[i])) {
11820                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
11821                         err = new_analog_input(spec, cfg->input_pins[i],
11822                                                auto_pin_cfg_labels[i],
11823                                                idx, 0x0b);
11824                         if (err < 0)
11825                                 return err;
11826                         imux->items[imux->num_items].label =
11827                                 auto_pin_cfg_labels[i];
11828                         imux->items[imux->num_items].index =
11829                                 alc880_input_pin_idx(cfg->input_pins[i]);
11830                         imux->num_items++;
11831                 }
11832         }
11833         return 0;
11834 }
11835
11836 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
11837                                               hda_nid_t nid, int pin_type,
11838                                               int dac_idx)
11839 {
11840         /* set as output */
11841         snd_hda_codec_write(codec, nid, 0,
11842                             AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
11843         snd_hda_codec_write(codec, nid, 0,
11844                             AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
11845         /* need the manual connection? */
11846         if (alc880_is_multi_pin(nid)) {
11847                 struct alc_spec *spec = codec->spec;
11848                 int idx = alc880_multi_pin_idx(nid);
11849                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
11850                                     AC_VERB_SET_CONNECT_SEL,
11851                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
11852         }
11853 }
11854
11855 static void alc662_auto_init_multi_out(struct hda_codec *codec)
11856 {
11857         struct alc_spec *spec = codec->spec;
11858         int i;
11859
11860         for (i = 0; i <= HDA_SIDE; i++) {
11861                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
11862                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
11863                 if (nid)
11864                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
11865                                                           i);
11866         }
11867 }
11868
11869 static void alc662_auto_init_hp_out(struct hda_codec *codec)
11870 {
11871         struct alc_spec *spec = codec->spec;
11872         hda_nid_t pin;
11873
11874         pin = spec->autocfg.hp_pins[0];
11875         if (pin) /* connect to front */
11876                 /* use dac 0 */
11877                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
11878 }
11879
11880 #define alc662_is_input_pin(nid)        alc880_is_input_pin(nid)
11881 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
11882
11883 static void alc662_auto_init_analog_input(struct hda_codec *codec)
11884 {
11885         struct alc_spec *spec = codec->spec;
11886         int i;
11887
11888         for (i = 0; i < AUTO_PIN_LAST; i++) {
11889                 hda_nid_t nid = spec->autocfg.input_pins[i];
11890                 if (alc662_is_input_pin(nid)) {
11891                         snd_hda_codec_write(codec, nid, 0,
11892                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
11893                                             (i <= AUTO_PIN_FRONT_MIC ?
11894                                              PIN_VREF80 : PIN_IN));
11895                         if (nid != ALC662_PIN_CD_NID)
11896                                 snd_hda_codec_write(codec, nid, 0,
11897                                                     AC_VERB_SET_AMP_GAIN_MUTE,
11898                                                     AMP_OUT_MUTE);
11899                 }
11900         }
11901 }
11902
11903 static int alc662_parse_auto_config(struct hda_codec *codec)
11904 {
11905         struct alc_spec *spec = codec->spec;
11906         int err;
11907         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
11908
11909         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11910                                            alc662_ignore);
11911         if (err < 0)
11912                 return err;
11913         if (!spec->autocfg.line_outs)
11914                 return 0; /* can't find valid BIOS pin config */
11915
11916         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
11917         if (err < 0)
11918                 return err;
11919         err = alc662_auto_create_multi_out_ctls(spec, &spec->autocfg);
11920         if (err < 0)
11921                 return err;
11922         err = alc662_auto_create_extra_out(spec,
11923                                            spec->autocfg.speaker_pins[0],
11924                                            "Speaker");
11925         if (err < 0)
11926                 return err;
11927         err = alc662_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
11928                                            "Headphone");
11929         if (err < 0)
11930                 return err;
11931         err = alc662_auto_create_analog_input_ctls(spec, &spec->autocfg);
11932         if (err < 0)
11933                 return err;
11934
11935         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
11936
11937         if (spec->autocfg.dig_out_pin)
11938                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
11939
11940         if (spec->kctl_alloc)
11941                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
11942
11943         spec->num_mux_defs = 1;
11944         spec->input_mux = &spec->private_imux;
11945         
11946         spec->init_verbs[spec->num_init_verbs++] = alc662_auto_init_verbs;
11947         spec->mixers[spec->num_mixers] = alc662_capture_mixer;
11948         spec->num_mixers++;
11949         return 1;
11950 }
11951
11952 /* additional initialization for auto-configuration model */
11953 static void alc662_auto_init(struct hda_codec *codec)
11954 {
11955         alc662_auto_init_multi_out(codec);
11956         alc662_auto_init_hp_out(codec);
11957         alc662_auto_init_analog_input(codec);
11958 }
11959
11960 static int patch_alc662(struct hda_codec *codec)
11961 {
11962         struct alc_spec *spec;
11963         int err, board_config;
11964
11965         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
11966         if (!spec)
11967                 return -ENOMEM;
11968
11969         codec->spec = spec;
11970
11971         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
11972                                                   alc662_models,
11973                                                   alc662_cfg_tbl);
11974         if (board_config < 0) {
11975                 printk(KERN_INFO "hda_codec: Unknown model for ALC662, "
11976                        "trying auto-probe from BIOS...\n");
11977                 board_config = ALC662_AUTO;
11978         }
11979
11980         if (board_config == ALC662_AUTO) {
11981                 /* automatic parse from the BIOS config */
11982                 err = alc662_parse_auto_config(codec);
11983                 if (err < 0) {
11984                         alc_free(codec);
11985                         return err;
11986                 } else if (!err) {
11987                         printk(KERN_INFO
11988                                "hda_codec: Cannot set up configuration "
11989                                "from BIOS.  Using base mode...\n");
11990                         board_config = ALC662_3ST_2ch_DIG;
11991                 }
11992         }
11993
11994         if (board_config != ALC662_AUTO)
11995                 setup_preset(spec, &alc662_presets[board_config]);
11996
11997         spec->stream_name_analog = "ALC662 Analog";
11998         spec->stream_analog_playback = &alc662_pcm_analog_playback;
11999         spec->stream_analog_capture = &alc662_pcm_analog_capture;
12000
12001         spec->stream_name_digital = "ALC662 Digital";
12002         spec->stream_digital_playback = &alc662_pcm_digital_playback;
12003         spec->stream_digital_capture = &alc662_pcm_digital_capture;
12004
12005         if (!spec->adc_nids && spec->input_mux) {
12006                 spec->adc_nids = alc662_adc_nids;
12007                 spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
12008         }
12009
12010         codec->patch_ops = alc_patch_ops;
12011         if (board_config == ALC662_AUTO)
12012                 spec->init_hook = alc662_auto_init;
12013 #ifdef CONFIG_SND_HDA_POWER_SAVE
12014         if (!spec->loopback.amplist)
12015                 spec->loopback.amplist = alc662_loopbacks;
12016 #endif
12017
12018         return 0;
12019 }
12020
12021 /*
12022  * patch entries
12023  */
12024 struct hda_codec_preset snd_hda_preset_realtek[] = {
12025         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
12026         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
12027         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
12028         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
12029           .patch = patch_alc861 },
12030         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
12031         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
12032         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
12033         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
12034           .patch = patch_alc883 },
12035         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
12036           .patch = patch_alc662 },
12037         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
12038         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
12039         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
12040         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
12041         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
12042         {} /* terminator */
12043 };