]> git.karo-electronics.de Git - karo-tx-linux.git/blob - sound/pci/hda/patch_realtek.c
3557865dde3897af9870a51d7c95fc5b947461c8
[karo-tx-linux.git] / sound / pci / hda / patch_realtek.c
1 /*
2  * Universal Interface for Intel High Definition Audio Codec
3  *
4  * HD audio interface patch for ALC 260/880/882 codecs
5  *
6  * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7  *                    PeiSen Hou <pshou@realtek.com.tw>
8  *                    Takashi Iwai <tiwai@suse.de>
9  *                    Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
10  *
11  *  This driver is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This driver is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
24  */
25
26 #include <sound/driver.h>
27 #include <linux/init.h>
28 #include <linux/delay.h>
29 #include <linux/slab.h>
30 #include <linux/pci.h>
31 #include <sound/core.h>
32 #include "hda_codec.h"
33 #include "hda_local.h"
34
35 #define ALC880_FRONT_EVENT              0x01
36 #define ALC880_DCVOL_EVENT              0x02
37 #define ALC880_HP_EVENT                 0x04
38 #define ALC880_MIC_EVENT                0x08
39
40 /* ALC880 board config type */
41 enum {
42         ALC880_3ST,
43         ALC880_3ST_DIG,
44         ALC880_5ST,
45         ALC880_5ST_DIG,
46         ALC880_W810,
47         ALC880_Z71V,
48         ALC880_6ST,
49         ALC880_6ST_DIG,
50         ALC880_F1734,
51         ALC880_ASUS,
52         ALC880_ASUS_DIG,
53         ALC880_ASUS_W1V,
54         ALC880_ASUS_DIG2,
55         ALC880_FUJITSU,
56         ALC880_UNIWILL_DIG,
57         ALC880_UNIWILL,
58         ALC880_UNIWILL_P53,
59         ALC880_CLEVO,
60         ALC880_TCL_S700,
61         ALC880_LG,
62         ALC880_LG_LW,
63 #ifdef CONFIG_SND_DEBUG
64         ALC880_TEST,
65 #endif
66         ALC880_AUTO,
67         ALC880_MODEL_LAST /* last tag */
68 };
69
70 /* ALC260 models */
71 enum {
72         ALC260_BASIC,
73         ALC260_HP,
74         ALC260_HP_3013,
75         ALC260_FUJITSU_S702X,
76         ALC260_ACER,
77         ALC260_WILL,
78         ALC260_REPLACER_672V,
79 #ifdef CONFIG_SND_DEBUG
80         ALC260_TEST,
81 #endif
82         ALC260_AUTO,
83         ALC260_MODEL_LAST /* last tag */
84 };
85
86 /* ALC262 models */
87 enum {
88         ALC262_BASIC,
89         ALC262_HIPPO,
90         ALC262_HIPPO_1,
91         ALC262_FUJITSU,
92         ALC262_HP_BPC,
93         ALC262_HP_BPC_D7000_WL,
94         ALC262_HP_BPC_D7000_WF,
95         ALC262_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                 .dig_out_nid = ALC880_DIGOUT_NID,
2879                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
2880                 .channel_mode = alc880_2_jack_modes,
2881                 .input_mux = &alc880_capture_source,
2882                 .unsol_event = alc880_uniwill_p53_unsol_event,
2883                 .init_hook = alc880_uniwill_p53_hp_automute,
2884         },
2885         [ALC880_CLEVO] = {
2886                 .mixers = { alc880_three_stack_mixer },
2887                 .init_verbs = { alc880_volume_init_verbs,
2888                                 alc880_pin_clevo_init_verbs },
2889                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2890                 .dac_nids = alc880_dac_nids,
2891                 .hp_nid = 0x03,
2892                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
2893                 .channel_mode = alc880_threestack_modes,
2894                 .need_dac_fix = 1,
2895                 .input_mux = &alc880_capture_source,
2896         },
2897         [ALC880_LG] = {
2898                 .mixers = { alc880_lg_mixer },
2899                 .init_verbs = { alc880_volume_init_verbs,
2900                                 alc880_lg_init_verbs },
2901                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
2902                 .dac_nids = alc880_lg_dac_nids,
2903                 .dig_out_nid = ALC880_DIGOUT_NID,
2904                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
2905                 .channel_mode = alc880_lg_ch_modes,
2906                 .need_dac_fix = 1,
2907                 .input_mux = &alc880_lg_capture_source,
2908                 .unsol_event = alc880_lg_unsol_event,
2909                 .init_hook = alc880_lg_automute,
2910 #ifdef CONFIG_SND_HDA_POWER_SAVE
2911                 .loopbacks = alc880_lg_loopbacks,
2912 #endif
2913         },
2914         [ALC880_LG_LW] = {
2915                 .mixers = { alc880_lg_lw_mixer },
2916                 .init_verbs = { alc880_volume_init_verbs,
2917                                 alc880_lg_lw_init_verbs },
2918                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2919                 .dac_nids = alc880_dac_nids,
2920                 .dig_out_nid = ALC880_DIGOUT_NID,
2921                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
2922                 .channel_mode = alc880_lg_lw_modes,
2923                 .input_mux = &alc880_lg_lw_capture_source,
2924                 .unsol_event = alc880_lg_lw_unsol_event,
2925                 .init_hook = alc880_lg_lw_automute,
2926         },
2927 #ifdef CONFIG_SND_DEBUG
2928         [ALC880_TEST] = {
2929                 .mixers = { alc880_test_mixer },
2930                 .init_verbs = { alc880_test_init_verbs },
2931                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
2932                 .dac_nids = alc880_test_dac_nids,
2933                 .dig_out_nid = ALC880_DIGOUT_NID,
2934                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
2935                 .channel_mode = alc880_test_modes,
2936                 .input_mux = &alc880_test_capture_source,
2937         },
2938 #endif
2939 };
2940
2941 /*
2942  * Automatic parse of I/O pins from the BIOS configuration
2943  */
2944
2945 #define NUM_CONTROL_ALLOC       32
2946 #define NUM_VERB_ALLOC          32
2947
2948 enum {
2949         ALC_CTL_WIDGET_VOL,
2950         ALC_CTL_WIDGET_MUTE,
2951         ALC_CTL_BIND_MUTE,
2952 };
2953 static struct snd_kcontrol_new alc880_control_templates[] = {
2954         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2955         HDA_CODEC_MUTE(NULL, 0, 0, 0),
2956         HDA_BIND_MUTE(NULL, 0, 0, 0),
2957 };
2958
2959 /* add dynamic controls */
2960 static int add_control(struct alc_spec *spec, int type, const char *name,
2961                        unsigned long val)
2962 {
2963         struct snd_kcontrol_new *knew;
2964
2965         if (spec->num_kctl_used >= spec->num_kctl_alloc) {
2966                 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
2967
2968                 /* array + terminator */
2969                 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL);
2970                 if (!knew)
2971                         return -ENOMEM;
2972                 if (spec->kctl_alloc) {
2973                         memcpy(knew, spec->kctl_alloc,
2974                                sizeof(*knew) * spec->num_kctl_alloc);
2975                         kfree(spec->kctl_alloc);
2976                 }
2977                 spec->kctl_alloc = knew;
2978                 spec->num_kctl_alloc = num;
2979         }
2980
2981         knew = &spec->kctl_alloc[spec->num_kctl_used];
2982         *knew = alc880_control_templates[type];
2983         knew->name = kstrdup(name, GFP_KERNEL);
2984         if (!knew->name)
2985                 return -ENOMEM;
2986         knew->private_value = val;
2987         spec->num_kctl_used++;
2988         return 0;
2989 }
2990
2991 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
2992 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
2993 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
2994 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
2995 #define alc880_is_input_pin(nid)        ((nid) >= 0x18)
2996 #define alc880_input_pin_idx(nid)       ((nid) - 0x18)
2997 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
2998 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
2999 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
3000 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
3001 #define ALC880_PIN_CD_NID               0x1c
3002
3003 /* fill in the dac_nids table from the parsed pin configuration */
3004 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
3005                                      const struct auto_pin_cfg *cfg)
3006 {
3007         hda_nid_t nid;
3008         int assigned[4];
3009         int i, j;
3010
3011         memset(assigned, 0, sizeof(assigned));
3012         spec->multiout.dac_nids = spec->private_dac_nids;
3013
3014         /* check the pins hardwired to audio widget */
3015         for (i = 0; i < cfg->line_outs; i++) {
3016                 nid = cfg->line_out_pins[i];
3017                 if (alc880_is_fixed_pin(nid)) {
3018                         int idx = alc880_fixed_pin_idx(nid);
3019                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
3020                         assigned[idx] = 1;
3021                 }
3022         }
3023         /* left pins can be connect to any audio widget */
3024         for (i = 0; i < cfg->line_outs; i++) {
3025                 nid = cfg->line_out_pins[i];
3026                 if (alc880_is_fixed_pin(nid))
3027                         continue;
3028                 /* search for an empty channel */
3029                 for (j = 0; j < cfg->line_outs; j++) {
3030                         if (!assigned[j]) {
3031                                 spec->multiout.dac_nids[i] =
3032                                         alc880_idx_to_dac(j);
3033                                 assigned[j] = 1;
3034                                 break;
3035                         }
3036                 }
3037         }
3038         spec->multiout.num_dacs = cfg->line_outs;
3039         return 0;
3040 }
3041
3042 /* add playback controls from the parsed DAC table */
3043 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
3044                                              const struct auto_pin_cfg *cfg)
3045 {
3046         char name[32];
3047         static const char *chname[4] = {
3048                 "Front", "Surround", NULL /*CLFE*/, "Side"
3049         };
3050         hda_nid_t nid;
3051         int i, err;
3052
3053         for (i = 0; i < cfg->line_outs; i++) {
3054                 if (!spec->multiout.dac_nids[i])
3055                         continue;
3056                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
3057                 if (i == 2) {
3058                         /* Center/LFE */
3059                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3060                                           "Center Playback Volume",
3061                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
3062                                                               HDA_OUTPUT));
3063                         if (err < 0)
3064                                 return err;
3065                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3066                                           "LFE Playback Volume",
3067                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
3068                                                               HDA_OUTPUT));
3069                         if (err < 0)
3070                                 return err;
3071                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3072                                           "Center Playback Switch",
3073                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
3074                                                               HDA_INPUT));
3075                         if (err < 0)
3076                                 return err;
3077                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3078                                           "LFE Playback Switch",
3079                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
3080                                                               HDA_INPUT));
3081                         if (err < 0)
3082                                 return err;
3083                 } else {
3084                         sprintf(name, "%s Playback Volume", chname[i]);
3085                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3086                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3087                                                               HDA_OUTPUT));
3088                         if (err < 0)
3089                                 return err;
3090                         sprintf(name, "%s Playback Switch", chname[i]);
3091                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3092                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
3093                                                               HDA_INPUT));
3094                         if (err < 0)
3095                                 return err;
3096                 }
3097         }
3098         return 0;
3099 }
3100
3101 /* add playback controls for speaker and HP outputs */
3102 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
3103                                         const char *pfx)
3104 {
3105         hda_nid_t nid;
3106         int err;
3107         char name[32];
3108
3109         if (!pin)
3110                 return 0;
3111
3112         if (alc880_is_fixed_pin(pin)) {
3113                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
3114                 /* specify the DAC as the extra output */
3115                 if (!spec->multiout.hp_nid)
3116                         spec->multiout.hp_nid = nid;
3117                 else
3118                         spec->multiout.extra_out_nid[0] = nid;
3119                 /* control HP volume/switch on the output mixer amp */
3120                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
3121                 sprintf(name, "%s Playback Volume", pfx);
3122                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3123                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3124                 if (err < 0)
3125                         return err;
3126                 sprintf(name, "%s Playback Switch", pfx);
3127                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3128                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
3129                 if (err < 0)
3130                         return err;
3131         } else if (alc880_is_multi_pin(pin)) {
3132                 /* set manual connection */
3133                 /* we have only a switch on HP-out PIN */
3134                 sprintf(name, "%s Playback Switch", pfx);
3135                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3136                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3137                 if (err < 0)
3138                         return err;
3139         }
3140         return 0;
3141 }
3142
3143 /* create input playback/capture controls for the given pin */
3144 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
3145                             const char *ctlname,
3146                             int idx, hda_nid_t mix_nid)
3147 {
3148         char name[32];
3149         int err;
3150
3151         sprintf(name, "%s Playback Volume", ctlname);
3152         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3153                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3154         if (err < 0)
3155                 return err;
3156         sprintf(name, "%s Playback Switch", ctlname);
3157         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3158                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3159         if (err < 0)
3160                 return err;
3161         return 0;
3162 }
3163
3164 /* create playback/capture controls for input pins */
3165 static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
3166                                                 const struct auto_pin_cfg *cfg)
3167 {
3168         struct hda_input_mux *imux = &spec->private_imux;
3169         int i, err, idx;
3170
3171         for (i = 0; i < AUTO_PIN_LAST; i++) {
3172                 if (alc880_is_input_pin(cfg->input_pins[i])) {
3173                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
3174                         err = new_analog_input(spec, cfg->input_pins[i],
3175                                                auto_pin_cfg_labels[i],
3176                                                idx, 0x0b);
3177                         if (err < 0)
3178                                 return err;
3179                         imux->items[imux->num_items].label =
3180                                 auto_pin_cfg_labels[i];
3181                         imux->items[imux->num_items].index =
3182                                 alc880_input_pin_idx(cfg->input_pins[i]);
3183                         imux->num_items++;
3184                 }
3185         }
3186         return 0;
3187 }
3188
3189 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
3190                                               hda_nid_t nid, int pin_type,
3191                                               int dac_idx)
3192 {
3193         /* set as output */
3194         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3195                             pin_type);
3196         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3197                             AMP_OUT_UNMUTE);
3198         /* need the manual connection? */
3199         if (alc880_is_multi_pin(nid)) {
3200                 struct alc_spec *spec = codec->spec;
3201                 int idx = alc880_multi_pin_idx(nid);
3202                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
3203                                     AC_VERB_SET_CONNECT_SEL,
3204                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
3205         }
3206 }
3207
3208 static int get_pin_type(int line_out_type)
3209 {
3210         if (line_out_type == AUTO_PIN_HP_OUT)
3211                 return PIN_HP;
3212         else
3213                 return PIN_OUT;
3214 }
3215
3216 static void alc880_auto_init_multi_out(struct hda_codec *codec)
3217 {
3218         struct alc_spec *spec = codec->spec;
3219         int i;
3220         
3221         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
3222         for (i = 0; i < spec->autocfg.line_outs; i++) {
3223                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3224                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3225                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
3226         }
3227 }
3228
3229 static void alc880_auto_init_extra_out(struct hda_codec *codec)
3230 {
3231         struct alc_spec *spec = codec->spec;
3232         hda_nid_t pin;
3233
3234         pin = spec->autocfg.speaker_pins[0];
3235         if (pin) /* connect to front */
3236                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
3237         pin = spec->autocfg.hp_pins[0];
3238         if (pin) /* connect to front */
3239                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
3240 }
3241
3242 static void alc880_auto_init_analog_input(struct hda_codec *codec)
3243 {
3244         struct alc_spec *spec = codec->spec;
3245         int i;
3246
3247         for (i = 0; i < AUTO_PIN_LAST; i++) {
3248                 hda_nid_t nid = spec->autocfg.input_pins[i];
3249                 if (alc880_is_input_pin(nid)) {
3250                         snd_hda_codec_write(codec, nid, 0,
3251                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
3252                                             i <= AUTO_PIN_FRONT_MIC ?
3253                                             PIN_VREF80 : PIN_IN);
3254                         if (nid != ALC880_PIN_CD_NID)
3255                                 snd_hda_codec_write(codec, nid, 0,
3256                                                     AC_VERB_SET_AMP_GAIN_MUTE,
3257                                                     AMP_OUT_MUTE);
3258                 }
3259         }
3260 }
3261
3262 /* parse the BIOS configuration and set up the alc_spec */
3263 /* return 1 if successful, 0 if the proper config is not found,
3264  * or a negative error code
3265  */
3266 static int alc880_parse_auto_config(struct hda_codec *codec)
3267 {
3268         struct alc_spec *spec = codec->spec;
3269         int err;
3270         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
3271
3272         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
3273                                            alc880_ignore);
3274         if (err < 0)
3275                 return err;
3276         if (!spec->autocfg.line_outs)
3277                 return 0; /* can't find valid BIOS pin config */
3278
3279         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
3280         if (err < 0)
3281                 return err;
3282         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
3283         if (err < 0)
3284                 return err;
3285         err = alc880_auto_create_extra_out(spec,
3286                                            spec->autocfg.speaker_pins[0],
3287                                            "Speaker");
3288         if (err < 0)
3289                 return err;
3290         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
3291                                            "Headphone");
3292         if (err < 0)
3293                 return err;
3294         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
3295         if (err < 0)
3296                 return err;
3297
3298         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3299
3300         if (spec->autocfg.dig_out_pin)
3301                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
3302         if (spec->autocfg.dig_in_pin)
3303                 spec->dig_in_nid = ALC880_DIGIN_NID;
3304
3305         if (spec->kctl_alloc)
3306                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
3307
3308         spec->init_verbs[spec->num_init_verbs++] = alc880_volume_init_verbs;
3309
3310         spec->num_mux_defs = 1;
3311         spec->input_mux = &spec->private_imux;
3312
3313         return 1;
3314 }
3315
3316 /* additional initialization for auto-configuration model */
3317 static void alc880_auto_init(struct hda_codec *codec)
3318 {
3319         alc880_auto_init_multi_out(codec);
3320         alc880_auto_init_extra_out(codec);
3321         alc880_auto_init_analog_input(codec);
3322 }
3323
3324 /*
3325  * OK, here we have finally the patch for ALC880
3326  */
3327
3328 static int patch_alc880(struct hda_codec *codec)
3329 {
3330         struct alc_spec *spec;
3331         int board_config;
3332         int err;
3333
3334         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3335         if (spec == NULL)
3336                 return -ENOMEM;
3337
3338         codec->spec = spec;
3339
3340         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
3341                                                   alc880_models,
3342                                                   alc880_cfg_tbl);
3343         if (board_config < 0) {
3344                 printk(KERN_INFO "hda_codec: Unknown model for ALC880, "
3345                        "trying auto-probe from BIOS...\n");
3346                 board_config = ALC880_AUTO;
3347         }
3348
3349         if (board_config == ALC880_AUTO) {
3350                 /* automatic parse from the BIOS config */
3351                 err = alc880_parse_auto_config(codec);
3352                 if (err < 0) {
3353                         alc_free(codec);
3354                         return err;
3355                 } else if (!err) {
3356                         printk(KERN_INFO
3357                                "hda_codec: Cannot set up configuration "
3358                                "from BIOS.  Using 3-stack mode...\n");
3359                         board_config = ALC880_3ST;
3360                 }
3361         }
3362
3363         if (board_config != ALC880_AUTO)
3364                 setup_preset(spec, &alc880_presets[board_config]);
3365
3366         spec->stream_name_analog = "ALC880 Analog";
3367         spec->stream_analog_playback = &alc880_pcm_analog_playback;
3368         spec->stream_analog_capture = &alc880_pcm_analog_capture;
3369
3370         spec->stream_name_digital = "ALC880 Digital";
3371         spec->stream_digital_playback = &alc880_pcm_digital_playback;
3372         spec->stream_digital_capture = &alc880_pcm_digital_capture;
3373
3374         if (!spec->adc_nids && spec->input_mux) {
3375                 /* check whether NID 0x07 is valid */
3376                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
3377                 /* get type */
3378                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
3379                 if (wcap != AC_WID_AUD_IN) {
3380                         spec->adc_nids = alc880_adc_nids_alt;
3381                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
3382                         spec->mixers[spec->num_mixers] =
3383                                 alc880_capture_alt_mixer;
3384                         spec->num_mixers++;
3385                 } else {
3386                         spec->adc_nids = alc880_adc_nids;
3387                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
3388                         spec->mixers[spec->num_mixers] = alc880_capture_mixer;
3389                         spec->num_mixers++;
3390                 }
3391         }
3392
3393         codec->patch_ops = alc_patch_ops;
3394         if (board_config == ALC880_AUTO)
3395                 spec->init_hook = alc880_auto_init;
3396 #ifdef CONFIG_SND_HDA_POWER_SAVE
3397         if (!spec->loopback.amplist)
3398                 spec->loopback.amplist = alc880_loopbacks;
3399 #endif
3400
3401         return 0;
3402 }
3403
3404
3405 /*
3406  * ALC260 support
3407  */
3408
3409 static hda_nid_t alc260_dac_nids[1] = {
3410         /* front */
3411         0x02,
3412 };
3413
3414 static hda_nid_t alc260_adc_nids[1] = {
3415         /* ADC0 */
3416         0x04,
3417 };
3418
3419 static hda_nid_t alc260_adc_nids_alt[1] = {
3420         /* ADC1 */
3421         0x05,
3422 };
3423
3424 static hda_nid_t alc260_hp_adc_nids[2] = {
3425         /* ADC1, 0 */
3426         0x05, 0x04
3427 };
3428
3429 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
3430  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
3431  */
3432 static hda_nid_t alc260_dual_adc_nids[2] = {
3433         /* ADC0, ADC1 */
3434         0x04, 0x05
3435 };
3436
3437 #define ALC260_DIGOUT_NID       0x03
3438 #define ALC260_DIGIN_NID        0x06
3439
3440 static struct hda_input_mux alc260_capture_source = {
3441         .num_items = 4,
3442         .items = {
3443                 { "Mic", 0x0 },
3444                 { "Front Mic", 0x1 },
3445                 { "Line", 0x2 },
3446                 { "CD", 0x4 },
3447         },
3448 };
3449
3450 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
3451  * headphone jack and the internal CD lines since these are the only pins at
3452  * which audio can appear.  For flexibility, also allow the option of
3453  * recording the mixer output on the second ADC (ADC0 doesn't have a
3454  * connection to the mixer output).
3455  */
3456 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
3457         {
3458                 .num_items = 3,
3459                 .items = {
3460                         { "Mic/Line", 0x0 },
3461                         { "CD", 0x4 },
3462                         { "Headphone", 0x2 },
3463                 },
3464         },
3465         {
3466                 .num_items = 4,
3467                 .items = {
3468                         { "Mic/Line", 0x0 },
3469                         { "CD", 0x4 },
3470                         { "Headphone", 0x2 },
3471                         { "Mixer", 0x5 },
3472                 },
3473         },
3474
3475 };
3476
3477 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
3478  * the Fujitsu S702x, but jacks are marked differently.
3479  */
3480 static struct hda_input_mux alc260_acer_capture_sources[2] = {
3481         {
3482                 .num_items = 4,
3483                 .items = {
3484                         { "Mic", 0x0 },
3485                         { "Line", 0x2 },
3486                         { "CD", 0x4 },
3487                         { "Headphone", 0x5 },
3488                 },
3489         },
3490         {
3491                 .num_items = 5,
3492                 .items = {
3493                         { "Mic", 0x0 },
3494                         { "Line", 0x2 },
3495                         { "CD", 0x4 },
3496                         { "Headphone", 0x6 },
3497                         { "Mixer", 0x5 },
3498                 },
3499         },
3500 };
3501 /*
3502  * This is just place-holder, so there's something for alc_build_pcms to look
3503  * at when it calculates the maximum number of channels. ALC260 has no mixer
3504  * element which allows changing the channel mode, so the verb list is
3505  * never used.
3506  */
3507 static struct hda_channel_mode alc260_modes[1] = {
3508         { 2, NULL },
3509 };
3510
3511
3512 /* Mixer combinations
3513  *
3514  * basic: base_output + input + pc_beep + capture
3515  * HP: base_output + input + capture_alt
3516  * HP_3013: hp_3013 + input + capture
3517  * fujitsu: fujitsu + capture
3518  * acer: acer + capture
3519  */
3520
3521 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
3522         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3523         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
3524         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
3525         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
3526         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
3527         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
3528         { } /* end */
3529 };
3530
3531 static struct snd_kcontrol_new alc260_input_mixer[] = {
3532         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3533         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3534         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
3535         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
3536         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
3537         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
3538         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
3539         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
3540         { } /* end */
3541 };
3542
3543 static struct snd_kcontrol_new alc260_pc_beep_mixer[] = {
3544         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT),
3545         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT),
3546         { } /* end */
3547 };
3548
3549 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
3550         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
3551         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
3552         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
3553         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
3554         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3555         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
3556         HDA_CODEC_VOLUME_MONO("iSpeaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
3557         HDA_CODEC_MUTE_MONO("iSpeaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
3558         { } /* end */
3559 };
3560
3561 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12, 
3562  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
3563  */
3564 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
3565         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3566         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
3567         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
3568         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3569         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3570         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
3571         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
3572         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
3573         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
3574         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
3575         HDA_CODEC_VOLUME("Internal Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
3576         HDA_BIND_MUTE("Internal Speaker Playback Switch", 0x09, 2, HDA_INPUT),
3577         { } /* end */
3578 };
3579
3580 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
3581  * versions of the ALC260 don't act on requests to enable mic bias from NID
3582  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
3583  * datasheet doesn't mention this restriction.  At this stage it's not clear
3584  * whether this behaviour is intentional or is a hardware bug in chip
3585  * revisions available in early 2006.  Therefore for now allow the
3586  * "Headphone Jack Mode" control to span all choices, but if it turns out
3587  * that the lack of mic bias for this NID is intentional we could change the
3588  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
3589  *
3590  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
3591  * don't appear to make the mic bias available from the "line" jack, even
3592  * though the NID used for this jack (0x14) can supply it.  The theory is
3593  * that perhaps Acer have included blocking capacitors between the ALC260
3594  * and the output jack.  If this turns out to be the case for all such
3595  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
3596  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
3597  *
3598  * The C20x Tablet series have a mono internal speaker which is controlled
3599  * via the chip's Mono sum widget and pin complex, so include the necessary
3600  * controls for such models.  On models without a "mono speaker" the control
3601  * won't do anything.
3602  */
3603 static struct snd_kcontrol_new alc260_acer_mixer[] = {
3604         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3605         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
3606         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
3607         HDA_CODEC_VOLUME_MONO("Mono Speaker Playback Volume", 0x0a, 1, 0x0,
3608                               HDA_OUTPUT),
3609         HDA_BIND_MUTE_MONO("Mono Speaker Playback Switch", 0x0a, 1, 2,
3610                            HDA_INPUT),
3611         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3612         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3613         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
3614         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
3615         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
3616         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
3617         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
3618         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
3619         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
3620         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
3621         { } /* end */
3622 };
3623
3624 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
3625  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
3626  */
3627 static struct snd_kcontrol_new alc260_will_mixer[] = {
3628         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3629         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
3630         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
3631         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
3632         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
3633         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
3634         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
3635         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
3636         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3637         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3638         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
3639         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
3640         { } /* end */
3641 };
3642
3643 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
3644  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
3645  */
3646 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
3647         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3648         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
3649         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
3650         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
3651         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
3652         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
3653         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
3654         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
3655         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
3656         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
3657         { } /* end */
3658 };
3659
3660 /* capture mixer elements */
3661 static struct snd_kcontrol_new alc260_capture_mixer[] = {
3662         HDA_CODEC_VOLUME("Capture Volume", 0x04, 0x0, HDA_INPUT),
3663         HDA_CODEC_MUTE("Capture Switch", 0x04, 0x0, HDA_INPUT),
3664         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x05, 0x0, HDA_INPUT),
3665         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x05, 0x0, HDA_INPUT),
3666         {
3667                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3668                 /* The multiple "Capture Source" controls confuse alsamixer
3669                  * So call somewhat different..
3670                  * FIXME: the controls appear in the "playback" view!
3671                  */
3672                 /* .name = "Capture Source", */
3673                 .name = "Input Source",
3674                 .count = 2,
3675                 .info = alc_mux_enum_info,
3676                 .get = alc_mux_enum_get,
3677                 .put = alc_mux_enum_put,
3678         },
3679         { } /* end */
3680 };
3681
3682 static struct snd_kcontrol_new alc260_capture_alt_mixer[] = {
3683         HDA_CODEC_VOLUME("Capture Volume", 0x05, 0x0, HDA_INPUT),
3684         HDA_CODEC_MUTE("Capture Switch", 0x05, 0x0, HDA_INPUT),
3685         {
3686                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3687                 /* The multiple "Capture Source" controls confuse alsamixer
3688                  * So call somewhat different..
3689                  * FIXME: the controls appear in the "playback" view!
3690                  */
3691                 /* .name = "Capture Source", */
3692                 .name = "Input Source",
3693                 .count = 1,
3694                 .info = alc_mux_enum_info,
3695                 .get = alc_mux_enum_get,
3696                 .put = alc_mux_enum_put,
3697         },
3698         { } /* end */
3699 };
3700
3701 /*
3702  * initialization verbs
3703  */
3704 static struct hda_verb alc260_init_verbs[] = {
3705         /* Line In pin widget for input */
3706         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3707         /* CD pin widget for input */
3708         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3709         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3710         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3711         /* Mic2 (front panel) pin widget for input and vref at 80% */
3712         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3713         /* LINE-2 is used for line-out in rear */
3714         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3715         /* select line-out */
3716         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
3717         /* LINE-OUT pin */
3718         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3719         /* enable HP */
3720         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3721         /* enable Mono */
3722         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3723         /* mute capture amp left and right */
3724         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3725         /* set connection select to line in (default select for this ADC) */
3726         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
3727         /* mute capture amp left and right */
3728         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3729         /* set connection select to line in (default select for this ADC) */
3730         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
3731         /* set vol=0 Line-Out mixer amp left and right */
3732         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3733         /* unmute pin widget amp left and right (no gain on this amp) */
3734         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3735         /* set vol=0 HP mixer amp left and right */
3736         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3737         /* unmute pin widget amp left and right (no gain on this amp) */
3738         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3739         /* set vol=0 Mono mixer amp left and right */
3740         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3741         /* unmute pin widget amp left and right (no gain on this amp) */
3742         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3743         /* unmute LINE-2 out pin */
3744         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3745         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
3746          * Line In 2 = 0x03
3747          */
3748         /* mute analog inputs */
3749         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3750         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3751         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3752         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3753         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3754         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
3755         /* mute Front out path */
3756         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3757         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3758         /* mute Headphone out path */
3759         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3760         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3761         /* mute Mono out path */
3762         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3763         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3764         { }
3765 };
3766
3767 #if 0 /* should be identical with alc260_init_verbs? */
3768 static struct hda_verb alc260_hp_init_verbs[] = {
3769         /* Headphone and output */
3770         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
3771         /* mono output */
3772         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3773         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3774         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
3775         /* Mic2 (front panel) pin widget for input and vref at 80% */
3776         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
3777         /* Line In pin widget for input */
3778         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3779         /* Line-2 pin widget for output */
3780         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3781         /* CD pin widget for input */
3782         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3783         /* unmute amp left and right */
3784         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
3785         /* set connection select to line in (default select for this ADC) */
3786         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
3787         /* unmute Line-Out mixer amp left and right (volume = 0) */
3788         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
3789         /* mute pin widget amp left and right (no gain on this amp) */
3790         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
3791         /* unmute HP mixer amp left and right (volume = 0) */
3792         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
3793         /* mute pin widget amp left and right (no gain on this amp) */
3794         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
3795         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
3796          * Line In 2 = 0x03
3797          */
3798         /* mute analog inputs */
3799         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3800         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3801         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3802         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3803         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3804         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
3805         /* Unmute Front out path */
3806         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3807         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3808         /* Unmute Headphone out path */
3809         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3810         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3811         /* Unmute Mono out path */
3812         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3813         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3814         { }
3815 };
3816 #endif
3817
3818 static struct hda_verb alc260_hp_3013_init_verbs[] = {
3819         /* Line out and output */
3820         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3821         /* mono output */
3822         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3823         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3824         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
3825         /* Mic2 (front panel) pin widget for input and vref at 80% */
3826         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
3827         /* Line In pin widget for input */
3828         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3829         /* Headphone pin widget for output */
3830         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
3831         /* CD pin widget for input */
3832         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3833         /* unmute amp left and right */
3834         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
3835         /* set connection select to line in (default select for this ADC) */
3836         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
3837         /* unmute Line-Out mixer amp left and right (volume = 0) */
3838         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
3839         /* mute pin widget amp left and right (no gain on this amp) */
3840         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
3841         /* unmute HP mixer amp left and right (volume = 0) */
3842         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
3843         /* mute pin widget amp left and right (no gain on this amp) */
3844         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
3845         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
3846          * Line In 2 = 0x03
3847          */
3848         /* mute analog inputs */
3849         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3850         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3851         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3852         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3853         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3854         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
3855         /* Unmute Front out path */
3856         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3857         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3858         /* Unmute Headphone out path */
3859         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3860         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3861         /* Unmute Mono out path */
3862         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3863         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3864         { }
3865 };
3866
3867 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
3868  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
3869  * audio = 0x16, internal speaker = 0x10.
3870  */
3871 static struct hda_verb alc260_fujitsu_init_verbs[] = {
3872         /* Disable all GPIOs */
3873         {0x01, AC_VERB_SET_GPIO_MASK, 0},
3874         /* Internal speaker is connected to headphone pin */
3875         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3876         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
3877         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3878         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
3879         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3880         /* Ensure all other unused pins are disabled and muted. */
3881         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3882         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3883         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3884         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3885         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3886         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3887         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3888         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3889
3890         /* Disable digital (SPDIF) pins */
3891         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
3892         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
3893
3894         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus 
3895          * when acting as an output.
3896          */
3897         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
3898
3899         /* Start with output sum widgets muted and their output gains at min */
3900         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3901         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3902         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3903         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3904         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3905         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3906         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3907         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3908         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3909
3910         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
3911         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3912         /* Unmute Line1 pin widget output buffer since it starts as an output.
3913          * If the pin mode is changed by the user the pin mode control will
3914          * take care of enabling the pin's input/output buffers as needed.
3915          * Therefore there's no need to enable the input buffer at this
3916          * stage.
3917          */
3918         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3919         /* Unmute input buffer of pin widget used for Line-in (no equiv 
3920          * mixer ctrl)
3921          */
3922         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3923
3924         /* Mute capture amp left and right */
3925         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3926         /* Set ADC connection select to match default mixer setting - line 
3927          * in (on mic1 pin)
3928          */
3929         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
3930
3931         /* Do the same for the second ADC: mute capture input amp and
3932          * set ADC connection to line in (on mic1 pin)
3933          */
3934         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3935         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
3936
3937         /* Mute all inputs to mixer widget (even unconnected ones) */
3938         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
3939         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
3940         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
3941         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
3942         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
3943         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
3944         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
3945         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
3946
3947         { }
3948 };
3949
3950 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
3951  * similar laptops (adapted from Fujitsu init verbs).
3952  */
3953 static struct hda_verb alc260_acer_init_verbs[] = {
3954         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
3955          * the headphone jack.  Turn this on and rely on the standard mute
3956          * methods whenever the user wants to turn these outputs off.
3957          */
3958         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
3959         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
3960         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
3961         /* Internal speaker/Headphone jack is connected to Line-out pin */
3962         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3963         /* Internal microphone/Mic jack is connected to Mic1 pin */
3964         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
3965         /* Line In jack is connected to Line1 pin */
3966         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3967         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
3968         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3969         /* Ensure all other unused pins are disabled and muted. */
3970         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3971         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3972         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3973         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3974         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3975         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3976         /* Disable digital (SPDIF) pins */
3977         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
3978         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
3979
3980         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum 
3981          * bus when acting as outputs.
3982          */
3983         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
3984         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
3985
3986         /* Start with output sum widgets muted and their output gains at min */
3987         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3988         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3989         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3990         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3991         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3992         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3993         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3994         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3995         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3996
3997         /* Unmute Line-out pin widget amp left and right
3998          * (no equiv mixer ctrl)
3999          */
4000         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4001         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
4002         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4003         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
4004          * inputs. If the pin mode is changed by the user the pin mode control
4005          * will take care of enabling the pin's input/output buffers as needed.
4006          * Therefore there's no need to enable the input buffer at this
4007          * stage.
4008          */
4009         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4010         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4011
4012         /* Mute capture amp left and right */
4013         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4014         /* Set ADC connection select to match default mixer setting - mic
4015          * (on mic1 pin)
4016          */
4017         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4018
4019         /* Do similar with the second ADC: mute capture input amp and
4020          * set ADC connection to mic to match ALSA's default state.
4021          */
4022         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4023         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4024
4025         /* Mute all inputs to mixer widget (even unconnected ones) */
4026         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4027         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4028         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4029         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4030         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4031         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4032         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4033         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4034
4035         { }
4036 };
4037
4038 static struct hda_verb alc260_will_verbs[] = {
4039         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4040         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
4041         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
4042         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4043         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
4044         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
4045         {}
4046 };
4047
4048 static struct hda_verb alc260_replacer_672v_verbs[] = {
4049         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4050         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
4051         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
4052
4053         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
4054         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4055         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4056
4057         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4058         {}
4059 };
4060
4061 /* toggle speaker-output according to the hp-jack state */
4062 static void alc260_replacer_672v_automute(struct hda_codec *codec)
4063 {
4064         unsigned int present;
4065
4066         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
4067         present = snd_hda_codec_read(codec, 0x0f, 0,
4068                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
4069         if (present) {
4070                 snd_hda_codec_write_cache(codec, 0x01, 0,
4071                                           AC_VERB_SET_GPIO_DATA, 1);
4072                 snd_hda_codec_write_cache(codec, 0x0f, 0,
4073                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4074                                           PIN_HP);
4075         } else {
4076                 snd_hda_codec_write_cache(codec, 0x01, 0,
4077                                           AC_VERB_SET_GPIO_DATA, 0);
4078                 snd_hda_codec_write_cache(codec, 0x0f, 0,
4079                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4080                                           PIN_OUT);
4081         }
4082 }
4083
4084 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
4085                                        unsigned int res)
4086 {
4087         if ((res >> 26) == ALC880_HP_EVENT)
4088                 alc260_replacer_672v_automute(codec);
4089 }
4090
4091 /* Test configuration for debugging, modelled after the ALC880 test
4092  * configuration.
4093  */
4094 #ifdef CONFIG_SND_DEBUG
4095 static hda_nid_t alc260_test_dac_nids[1] = {
4096         0x02,
4097 };
4098 static hda_nid_t alc260_test_adc_nids[2] = {
4099         0x04, 0x05,
4100 };
4101 /* For testing the ALC260, each input MUX needs its own definition since
4102  * the signal assignments are different.  This assumes that the first ADC 
4103  * is NID 0x04.
4104  */
4105 static struct hda_input_mux alc260_test_capture_sources[2] = {
4106         {
4107                 .num_items = 7,
4108                 .items = {
4109                         { "MIC1 pin", 0x0 },
4110                         { "MIC2 pin", 0x1 },
4111                         { "LINE1 pin", 0x2 },
4112                         { "LINE2 pin", 0x3 },
4113                         { "CD pin", 0x4 },
4114                         { "LINE-OUT pin", 0x5 },
4115                         { "HP-OUT pin", 0x6 },
4116                 },
4117         },
4118         {
4119                 .num_items = 8,
4120                 .items = {
4121                         { "MIC1 pin", 0x0 },
4122                         { "MIC2 pin", 0x1 },
4123                         { "LINE1 pin", 0x2 },
4124                         { "LINE2 pin", 0x3 },
4125                         { "CD pin", 0x4 },
4126                         { "Mixer", 0x5 },
4127                         { "LINE-OUT pin", 0x6 },
4128                         { "HP-OUT pin", 0x7 },
4129                 },
4130         },
4131 };
4132 static struct snd_kcontrol_new alc260_test_mixer[] = {
4133         /* Output driver widgets */
4134         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4135         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4136         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4137         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
4138         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4139         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
4140
4141         /* Modes for retasking pin widgets
4142          * Note: the ALC260 doesn't seem to act on requests to enable mic
4143          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
4144          * mention this restriction.  At this stage it's not clear whether
4145          * this behaviour is intentional or is a hardware bug in chip
4146          * revisions available at least up until early 2006.  Therefore for
4147          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
4148          * choices, but if it turns out that the lack of mic bias for these
4149          * NIDs is intentional we could change their modes from
4150          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4151          */
4152         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
4153         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
4154         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
4155         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
4156         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
4157         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
4158
4159         /* Loopback mixer controls */
4160         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
4161         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
4162         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
4163         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
4164         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
4165         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
4166         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
4167         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
4168         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4169         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4170         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4171         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4172         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
4173         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
4174         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
4175         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
4176
4177         /* Controls for GPIO pins, assuming they are configured as outputs */
4178         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
4179         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
4180         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
4181         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
4182
4183         /* Switches to allow the digital IO pins to be enabled.  The datasheet
4184          * is ambigious as to which NID is which; testing on laptops which
4185          * make this output available should provide clarification. 
4186          */
4187         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
4188         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
4189
4190         { } /* end */
4191 };
4192 static struct hda_verb alc260_test_init_verbs[] = {
4193         /* Enable all GPIOs as outputs with an initial value of 0 */
4194         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
4195         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4196         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
4197
4198         /* Enable retasking pins as output, initially without power amp */
4199         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4200         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4201         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4202         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4203         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4204         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4205
4206         /* Disable digital (SPDIF) pins initially, but users can enable
4207          * them via a mixer switch.  In the case of SPDIF-out, this initverb
4208          * payload also sets the generation to 0, output to be in "consumer"
4209          * PCM format, copyright asserted, no pre-emphasis and no validity
4210          * control.
4211          */
4212         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4213         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4214
4215         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the 
4216          * OUT1 sum bus when acting as an output.
4217          */
4218         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
4219         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
4220         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4221         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
4222
4223         /* Start with output sum widgets muted and their output gains at min */
4224         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4225         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4226         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4227         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4228         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4229         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4230         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4231         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4232         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4233
4234         /* Unmute retasking pin widget output buffers since the default
4235          * state appears to be output.  As the pin mode is changed by the
4236          * user the pin mode control will take care of enabling the pin's
4237          * input/output buffers as needed.
4238          */
4239         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4240         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4241         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4242         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4243         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4244         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4245         /* Also unmute the mono-out pin widget */
4246         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4247
4248         /* Mute capture amp left and right */
4249         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4250         /* Set ADC connection select to match default mixer setting (mic1
4251          * pin)
4252          */
4253         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4254
4255         /* Do the same for the second ADC: mute capture input amp and
4256          * set ADC connection to mic1 pin
4257          */
4258         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4259         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4260
4261         /* Mute all inputs to mixer widget (even unconnected ones) */
4262         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4263         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4264         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4265         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4266         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4267         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4268         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4269         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4270
4271         { }
4272 };
4273 #endif
4274
4275 static struct hda_pcm_stream alc260_pcm_analog_playback = {
4276         .substreams = 1,
4277         .channels_min = 2,
4278         .channels_max = 2,
4279 };
4280
4281 static struct hda_pcm_stream alc260_pcm_analog_capture = {
4282         .substreams = 1,
4283         .channels_min = 2,
4284         .channels_max = 2,
4285 };
4286
4287 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
4288 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
4289
4290 /*
4291  * for BIOS auto-configuration
4292  */
4293
4294 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
4295                                         const char *pfx)
4296 {
4297         hda_nid_t nid_vol;
4298         unsigned long vol_val, sw_val;
4299         char name[32];
4300         int err;
4301
4302         if (nid >= 0x0f && nid < 0x11) {
4303                 nid_vol = nid - 0x7;
4304                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
4305                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
4306         } else if (nid == 0x11) {
4307                 nid_vol = nid - 0x7;
4308                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
4309                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
4310         } else if (nid >= 0x12 && nid <= 0x15) {
4311                 nid_vol = 0x08;
4312                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
4313                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
4314         } else
4315                 return 0; /* N/A */
4316         
4317         snprintf(name, sizeof(name), "%s Playback Volume", pfx);
4318         err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val);
4319         if (err < 0)
4320                 return err;
4321         snprintf(name, sizeof(name), "%s Playback Switch", pfx);
4322         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val);
4323         if (err < 0)
4324                 return err;
4325         return 1;
4326 }
4327
4328 /* add playback controls from the parsed DAC table */
4329 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
4330                                              const struct auto_pin_cfg *cfg)
4331 {
4332         hda_nid_t nid;
4333         int err;
4334
4335         spec->multiout.num_dacs = 1;
4336         spec->multiout.dac_nids = spec->private_dac_nids;
4337         spec->multiout.dac_nids[0] = 0x02;
4338
4339         nid = cfg->line_out_pins[0];
4340         if (nid) {
4341                 err = alc260_add_playback_controls(spec, nid, "Front");
4342                 if (err < 0)
4343                         return err;
4344         }
4345
4346         nid = cfg->speaker_pins[0];
4347         if (nid) {
4348                 err = alc260_add_playback_controls(spec, nid, "Speaker");
4349                 if (err < 0)
4350                         return err;
4351         }
4352
4353         nid = cfg->hp_pins[0];
4354         if (nid) {
4355                 err = alc260_add_playback_controls(spec, nid, "Headphone");
4356                 if (err < 0)
4357                         return err;
4358         }
4359         return 0;
4360 }
4361
4362 /* create playback/capture controls for input pins */
4363 static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec,
4364                                                 const struct auto_pin_cfg *cfg)
4365 {
4366         struct hda_input_mux *imux = &spec->private_imux;
4367         int i, err, idx;
4368
4369         for (i = 0; i < AUTO_PIN_LAST; i++) {
4370                 if (cfg->input_pins[i] >= 0x12) {
4371                         idx = cfg->input_pins[i] - 0x12;
4372                         err = new_analog_input(spec, cfg->input_pins[i],
4373                                                auto_pin_cfg_labels[i], idx,
4374                                                0x07);
4375                         if (err < 0)
4376                                 return err;
4377                         imux->items[imux->num_items].label =
4378                                 auto_pin_cfg_labels[i];
4379                         imux->items[imux->num_items].index = idx;
4380                         imux->num_items++;
4381                 }
4382                 if (cfg->input_pins[i] >= 0x0f && cfg->input_pins[i] <= 0x10){
4383                         idx = cfg->input_pins[i] - 0x09;
4384                         err = new_analog_input(spec, cfg->input_pins[i],
4385                                                auto_pin_cfg_labels[i], idx,
4386                                                0x07);
4387                         if (err < 0)
4388                                 return err;
4389                         imux->items[imux->num_items].label =
4390                                 auto_pin_cfg_labels[i];
4391                         imux->items[imux->num_items].index = idx;
4392                         imux->num_items++;
4393                 }
4394         }
4395         return 0;
4396 }
4397
4398 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
4399                                               hda_nid_t nid, int pin_type,
4400                                               int sel_idx)
4401 {
4402         /* set as output */
4403         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4404                             pin_type);
4405         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4406                             AMP_OUT_UNMUTE);
4407         /* need the manual connection? */
4408         if (nid >= 0x12) {
4409                 int idx = nid - 0x12;
4410                 snd_hda_codec_write(codec, idx + 0x0b, 0,
4411                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
4412         }
4413 }
4414
4415 static void alc260_auto_init_multi_out(struct hda_codec *codec)
4416 {
4417         struct alc_spec *spec = codec->spec;
4418         hda_nid_t nid;
4419
4420         alc_subsystem_id(codec, 0x10, 0x15, 0x0f);
4421         nid = spec->autocfg.line_out_pins[0];
4422         if (nid) {
4423                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
4424                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
4425         }
4426         
4427         nid = spec->autocfg.speaker_pins[0];
4428         if (nid)
4429                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
4430
4431         nid = spec->autocfg.hp_pins[0];
4432         if (nid)
4433                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
4434 }
4435
4436 #define ALC260_PIN_CD_NID               0x16
4437 static void alc260_auto_init_analog_input(struct hda_codec *codec)
4438 {
4439         struct alc_spec *spec = codec->spec;
4440         int i;
4441
4442         for (i = 0; i < AUTO_PIN_LAST; i++) {
4443                 hda_nid_t nid = spec->autocfg.input_pins[i];
4444                 if (nid >= 0x12) {
4445                         snd_hda_codec_write(codec, nid, 0,
4446                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
4447                                             i <= AUTO_PIN_FRONT_MIC ?
4448                                             PIN_VREF80 : PIN_IN);
4449                         if (nid != ALC260_PIN_CD_NID)
4450                                 snd_hda_codec_write(codec, nid, 0,
4451                                                     AC_VERB_SET_AMP_GAIN_MUTE,
4452                                                     AMP_OUT_MUTE);
4453                 }
4454         }
4455 }
4456
4457 /*
4458  * generic initialization of ADC, input mixers and output mixers
4459  */
4460 static struct hda_verb alc260_volume_init_verbs[] = {
4461         /*
4462          * Unmute ADC0-1 and set the default input to mic-in
4463          */
4464         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4465         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4466         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4467         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4468         
4469         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4470          * mixer widget
4471          * Note: PASD motherboards uses the Line In 2 as the input for
4472          * front panel mic (mic 2)
4473          */
4474         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
4475         /* mute analog inputs */
4476         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4477         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4478         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4479         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4480         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4481
4482         /*
4483          * Set up output mixers (0x08 - 0x0a)
4484          */
4485         /* set vol=0 to output mixers */
4486         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4487         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4488         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4489         /* set up input amps for analog loopback */
4490         /* Amp Indices: DAC = 0, mixer = 1 */
4491         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4492         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4493         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4494         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4495         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4496         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4497         
4498         { }
4499 };
4500
4501 static int alc260_parse_auto_config(struct hda_codec *codec)
4502 {
4503         struct alc_spec *spec = codec->spec;
4504         unsigned int wcap;
4505         int err;
4506         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
4507
4508         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
4509                                            alc260_ignore);
4510         if (err < 0)
4511                 return err;
4512         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
4513         if (err < 0)
4514                 return err;
4515         if (!spec->kctl_alloc)
4516                 return 0; /* can't find valid BIOS pin config */
4517         err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg);
4518         if (err < 0)
4519                 return err;
4520
4521         spec->multiout.max_channels = 2;
4522
4523         if (spec->autocfg.dig_out_pin)
4524                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
4525         if (spec->kctl_alloc)
4526                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
4527
4528         spec->init_verbs[spec->num_init_verbs++] = alc260_volume_init_verbs;
4529
4530         spec->num_mux_defs = 1;
4531         spec->input_mux = &spec->private_imux;
4532
4533         /* check whether NID 0x04 is valid */
4534         wcap = get_wcaps(codec, 0x04);
4535         wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */
4536         if (wcap != AC_WID_AUD_IN) {
4537                 spec->adc_nids = alc260_adc_nids_alt;
4538                 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
4539                 spec->mixers[spec->num_mixers] = alc260_capture_alt_mixer;
4540         } else {
4541                 spec->adc_nids = alc260_adc_nids;
4542                 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
4543                 spec->mixers[spec->num_mixers] = alc260_capture_mixer;
4544         }
4545         spec->num_mixers++;
4546
4547         return 1;
4548 }
4549
4550 /* additional initialization for auto-configuration model */
4551 static void alc260_auto_init(struct hda_codec *codec)
4552 {
4553         alc260_auto_init_multi_out(codec);
4554         alc260_auto_init_analog_input(codec);
4555 }
4556
4557 #ifdef CONFIG_SND_HDA_POWER_SAVE
4558 static struct hda_amp_list alc260_loopbacks[] = {
4559         { 0x07, HDA_INPUT, 0 },
4560         { 0x07, HDA_INPUT, 1 },
4561         { 0x07, HDA_INPUT, 2 },
4562         { 0x07, HDA_INPUT, 3 },
4563         { 0x07, HDA_INPUT, 4 },
4564         { } /* end */
4565 };
4566 #endif
4567
4568 /*
4569  * ALC260 configurations
4570  */
4571 static const char *alc260_models[ALC260_MODEL_LAST] = {
4572         [ALC260_BASIC]          = "basic",
4573         [ALC260_HP]             = "hp",
4574         [ALC260_HP_3013]        = "hp-3013",
4575         [ALC260_FUJITSU_S702X]  = "fujitsu",
4576         [ALC260_ACER]           = "acer",
4577         [ALC260_WILL]           = "will",
4578         [ALC260_REPLACER_672V]  = "replacer",
4579 #ifdef CONFIG_SND_DEBUG
4580         [ALC260_TEST]           = "test",
4581 #endif
4582         [ALC260_AUTO]           = "auto",
4583 };
4584
4585 static struct snd_pci_quirk alc260_cfg_tbl[] = {
4586         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
4587         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
4588         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
4589         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013),
4590         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
4591         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP),
4592         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_3013),
4593         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
4594         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
4595         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
4596         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
4597         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
4598         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
4599         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
4600         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
4601         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
4602         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
4603         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
4604         {}
4605 };
4606
4607 static struct alc_config_preset alc260_presets[] = {
4608         [ALC260_BASIC] = {
4609                 .mixers = { alc260_base_output_mixer,
4610                             alc260_input_mixer,
4611                             alc260_pc_beep_mixer,
4612                             alc260_capture_mixer },
4613                 .init_verbs = { alc260_init_verbs },
4614                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4615                 .dac_nids = alc260_dac_nids,
4616                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
4617                 .adc_nids = alc260_adc_nids,
4618                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4619                 .channel_mode = alc260_modes,
4620                 .input_mux = &alc260_capture_source,
4621         },
4622         [ALC260_HP] = {
4623                 .mixers = { alc260_base_output_mixer,
4624                             alc260_input_mixer,
4625                             alc260_capture_alt_mixer },
4626                 .init_verbs = { alc260_init_verbs },
4627                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4628                 .dac_nids = alc260_dac_nids,
4629                 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
4630                 .adc_nids = alc260_hp_adc_nids,
4631                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4632                 .channel_mode = alc260_modes,
4633                 .input_mux = &alc260_capture_source,
4634         },
4635         [ALC260_HP_3013] = {
4636                 .mixers = { alc260_hp_3013_mixer,
4637                             alc260_input_mixer,
4638                             alc260_capture_alt_mixer },
4639                 .init_verbs = { alc260_hp_3013_init_verbs },
4640                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4641                 .dac_nids = alc260_dac_nids,
4642                 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
4643                 .adc_nids = alc260_hp_adc_nids,
4644                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4645                 .channel_mode = alc260_modes,
4646                 .input_mux = &alc260_capture_source,
4647         },
4648         [ALC260_FUJITSU_S702X] = {
4649                 .mixers = { alc260_fujitsu_mixer,
4650                             alc260_capture_mixer },
4651                 .init_verbs = { alc260_fujitsu_init_verbs },
4652                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4653                 .dac_nids = alc260_dac_nids,
4654                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
4655                 .adc_nids = alc260_dual_adc_nids,
4656                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4657                 .channel_mode = alc260_modes,
4658                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
4659                 .input_mux = alc260_fujitsu_capture_sources,
4660         },
4661         [ALC260_ACER] = {
4662                 .mixers = { alc260_acer_mixer,
4663                             alc260_capture_mixer },
4664                 .init_verbs = { alc260_acer_init_verbs },
4665                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4666                 .dac_nids = alc260_dac_nids,
4667                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
4668                 .adc_nids = alc260_dual_adc_nids,
4669                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4670                 .channel_mode = alc260_modes,
4671                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
4672                 .input_mux = alc260_acer_capture_sources,
4673         },
4674         [ALC260_WILL] = {
4675                 .mixers = { alc260_will_mixer,
4676                             alc260_capture_mixer },
4677                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
4678                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4679                 .dac_nids = alc260_dac_nids,
4680                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
4681                 .adc_nids = alc260_adc_nids,
4682                 .dig_out_nid = ALC260_DIGOUT_NID,
4683                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4684                 .channel_mode = alc260_modes,
4685                 .input_mux = &alc260_capture_source,
4686         },
4687         [ALC260_REPLACER_672V] = {
4688                 .mixers = { alc260_replacer_672v_mixer,
4689                             alc260_capture_mixer },
4690                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
4691                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4692                 .dac_nids = alc260_dac_nids,
4693                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
4694                 .adc_nids = alc260_adc_nids,
4695                 .dig_out_nid = ALC260_DIGOUT_NID,
4696                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4697                 .channel_mode = alc260_modes,
4698                 .input_mux = &alc260_capture_source,
4699                 .unsol_event = alc260_replacer_672v_unsol_event,
4700                 .init_hook = alc260_replacer_672v_automute,
4701         },
4702 #ifdef CONFIG_SND_DEBUG
4703         [ALC260_TEST] = {
4704                 .mixers = { alc260_test_mixer,
4705                             alc260_capture_mixer },
4706                 .init_verbs = { alc260_test_init_verbs },
4707                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
4708                 .dac_nids = alc260_test_dac_nids,
4709                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
4710                 .adc_nids = alc260_test_adc_nids,
4711                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4712                 .channel_mode = alc260_modes,
4713                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
4714                 .input_mux = alc260_test_capture_sources,
4715         },
4716 #endif
4717 };
4718
4719 static int patch_alc260(struct hda_codec *codec)
4720 {
4721         struct alc_spec *spec;
4722         int err, board_config;
4723
4724         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4725         if (spec == NULL)
4726                 return -ENOMEM;
4727
4728         codec->spec = spec;
4729
4730         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
4731                                                   alc260_models,
4732                                                   alc260_cfg_tbl);
4733         if (board_config < 0) {
4734                 snd_printd(KERN_INFO "hda_codec: Unknown model for ALC260, "
4735                            "trying auto-probe from BIOS...\n");
4736                 board_config = ALC260_AUTO;
4737         }
4738
4739         if (board_config == ALC260_AUTO) {
4740                 /* automatic parse from the BIOS config */
4741                 err = alc260_parse_auto_config(codec);
4742                 if (err < 0) {
4743                         alc_free(codec);
4744                         return err;
4745                 } else if (!err) {
4746                         printk(KERN_INFO
4747                                "hda_codec: Cannot set up configuration "
4748                                "from BIOS.  Using base mode...\n");
4749                         board_config = ALC260_BASIC;
4750                 }
4751         }
4752
4753         if (board_config != ALC260_AUTO)
4754                 setup_preset(spec, &alc260_presets[board_config]);
4755
4756         spec->stream_name_analog = "ALC260 Analog";
4757         spec->stream_analog_playback = &alc260_pcm_analog_playback;
4758         spec->stream_analog_capture = &alc260_pcm_analog_capture;
4759
4760         spec->stream_name_digital = "ALC260 Digital";
4761         spec->stream_digital_playback = &alc260_pcm_digital_playback;
4762         spec->stream_digital_capture = &alc260_pcm_digital_capture;
4763
4764         codec->patch_ops = alc_patch_ops;
4765         if (board_config == ALC260_AUTO)
4766                 spec->init_hook = alc260_auto_init;
4767 #ifdef CONFIG_SND_HDA_POWER_SAVE
4768         if (!spec->loopback.amplist)
4769                 spec->loopback.amplist = alc260_loopbacks;
4770 #endif
4771
4772         return 0;
4773 }
4774
4775
4776 /*
4777  * ALC882 support
4778  *
4779  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4780  * configuration.  Each pin widget can choose any input DACs and a mixer.
4781  * Each ADC is connected from a mixer of all inputs.  This makes possible
4782  * 6-channel independent captures.
4783  *
4784  * In addition, an independent DAC for the multi-playback (not used in this
4785  * driver yet).
4786  */
4787 #define ALC882_DIGOUT_NID       0x06
4788 #define ALC882_DIGIN_NID        0x0a
4789
4790 static struct hda_channel_mode alc882_ch_modes[1] = {
4791         { 8, NULL }
4792 };
4793
4794 static hda_nid_t alc882_dac_nids[4] = {
4795         /* front, rear, clfe, rear_surr */
4796         0x02, 0x03, 0x04, 0x05
4797 };
4798
4799 /* identical with ALC880 */
4800 #define alc882_adc_nids         alc880_adc_nids
4801 #define alc882_adc_nids_alt     alc880_adc_nids_alt
4802
4803 /* input MUX */
4804 /* FIXME: should be a matrix-type input source selection */
4805
4806 static struct hda_input_mux alc882_capture_source = {
4807         .num_items = 4,
4808         .items = {
4809                 { "Mic", 0x0 },
4810                 { "Front Mic", 0x1 },
4811                 { "Line", 0x2 },
4812                 { "CD", 0x4 },
4813         },
4814 };
4815 #define alc882_mux_enum_info alc_mux_enum_info
4816 #define alc882_mux_enum_get alc_mux_enum_get
4817
4818 static int alc882_mux_enum_put(struct snd_kcontrol *kcontrol,
4819                                struct snd_ctl_elem_value *ucontrol)
4820 {
4821         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4822         struct alc_spec *spec = codec->spec;
4823         const struct hda_input_mux *imux = spec->input_mux;
4824         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
4825         static hda_nid_t capture_mixers[3] = { 0x24, 0x23, 0x22 };
4826         hda_nid_t nid = capture_mixers[adc_idx];
4827         unsigned int *cur_val = &spec->cur_mux[adc_idx];
4828         unsigned int i, idx;
4829
4830         idx = ucontrol->value.enumerated.item[0];
4831         if (idx >= imux->num_items)
4832                 idx = imux->num_items - 1;
4833         if (*cur_val == idx)
4834                 return 0;
4835         for (i = 0; i < imux->num_items; i++) {
4836                 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
4837                 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
4838                                          imux->items[i].index,
4839                                          HDA_AMP_MUTE, v);
4840         }
4841         *cur_val = idx;
4842         return 1;
4843 }
4844
4845 /*
4846  * 2ch mode
4847  */
4848 static struct hda_verb alc882_3ST_ch2_init[] = {
4849         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
4850         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
4851         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
4852         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
4853         { } /* end */
4854 };
4855
4856 /*
4857  * 6ch mode
4858  */
4859 static struct hda_verb alc882_3ST_ch6_init[] = {
4860         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4861         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
4862         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
4863         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4864         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
4865         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
4866         { } /* end */
4867 };
4868
4869 static struct hda_channel_mode alc882_3ST_6ch_modes[2] = {
4870         { 2, alc882_3ST_ch2_init },
4871         { 6, alc882_3ST_ch6_init },
4872 };
4873
4874 /*
4875  * 6ch mode
4876  */
4877 static struct hda_verb alc882_sixstack_ch6_init[] = {
4878         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
4879         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4880         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4881         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4882         { } /* end */
4883 };
4884
4885 /*
4886  * 8ch mode
4887  */
4888 static struct hda_verb alc882_sixstack_ch8_init[] = {
4889         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4890         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4891         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4892         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4893         { } /* end */
4894 };
4895
4896 static struct hda_channel_mode alc882_sixstack_modes[2] = {
4897         { 6, alc882_sixstack_ch6_init },
4898         { 8, alc882_sixstack_ch8_init },
4899 };
4900
4901 /*
4902  * macbook pro ALC885 can switch LineIn to LineOut without loosing Mic
4903  */
4904
4905 /*
4906  * 2ch mode
4907  */
4908 static struct hda_verb alc885_mbp_ch2_init[] = {
4909         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
4910         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4911         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4912         { } /* end */
4913 };
4914
4915 /*
4916  * 6ch mode
4917  */
4918 static struct hda_verb alc885_mbp_ch6_init[] = {
4919         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4920         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4921         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
4922         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4923         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4924         { } /* end */
4925 };
4926
4927 static struct hda_channel_mode alc885_mbp_6ch_modes[2] = {
4928         { 2, alc885_mbp_ch2_init },
4929         { 6, alc885_mbp_ch6_init },
4930 };
4931
4932
4933 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
4934  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
4935  */
4936 static struct snd_kcontrol_new alc882_base_mixer[] = {
4937         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
4938         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
4939         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
4940         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
4941         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
4942         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
4943         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
4944         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
4945         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
4946         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
4947         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
4948         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
4949         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
4950         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
4951         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
4952         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
4953         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
4954         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
4955         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
4956         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
4957         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
4958         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
4959         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
4960         { } /* end */
4961 };
4962
4963 static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
4964         HDA_CODEC_VOLUME("Master Volume", 0x0c, 0x00, HDA_OUTPUT),
4965         HDA_BIND_MUTE   ("Master Switch", 0x0c, 0x02, HDA_INPUT),
4966         HDA_CODEC_MUTE  ("Speaker Switch", 0x14, 0x00, HDA_OUTPUT),
4967         HDA_CODEC_VOLUME("Line Out Volume", 0x0d,0x00, HDA_OUTPUT),
4968         HDA_CODEC_VOLUME("Line In Playback Volume", 0x0b, 0x02, HDA_INPUT),
4969         HDA_CODEC_MUTE  ("Line In Playback Switch", 0x0b, 0x02, HDA_INPUT),
4970         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
4971         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
4972         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0x00, HDA_INPUT),
4973         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
4974         { } /* end */
4975 };
4976 static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
4977         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
4978         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
4979         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
4980         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
4981         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
4982         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
4983         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
4984         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
4985         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
4986         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
4987         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
4988         { } /* end */
4989 };
4990
4991 static struct snd_kcontrol_new alc882_targa_mixer[] = {
4992         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
4993         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
4994         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
4995         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
4996         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
4997         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
4998         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
4999         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5000         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5001         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5002         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5003         { } /* end */
5004 };
5005
5006 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
5007  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
5008  */
5009 static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
5010         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5011         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
5012         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5013         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
5014         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5015         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5016         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5017         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5018         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
5019         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
5020         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5021         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5022         { } /* end */
5023 };
5024
5025 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
5026         {
5027                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5028                 .name = "Channel Mode",
5029                 .info = alc_ch_mode_info,
5030                 .get = alc_ch_mode_get,
5031                 .put = alc_ch_mode_put,
5032         },
5033         { } /* end */
5034 };
5035
5036 static struct hda_verb alc882_init_verbs[] = {
5037         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5038         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5039         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5040         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5041         /* Rear mixer */
5042         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5043         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5044         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5045         /* CLFE mixer */
5046         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5047         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5048         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5049         /* Side mixer */
5050         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5051         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5052         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5053
5054         /* Front Pin: output 0 (0x0c) */
5055         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5056         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5057         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5058         /* Rear Pin: output 1 (0x0d) */
5059         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5060         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5061         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5062         /* CLFE Pin: output 2 (0x0e) */
5063         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5064         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5065         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
5066         /* Side Pin: output 3 (0x0f) */
5067         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5068         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5069         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
5070         /* Mic (rear) pin: input vref at 80% */
5071         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5072         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5073         /* Front Mic pin: input vref at 80% */
5074         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5075         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5076         /* Line In pin: input */
5077         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5078         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5079         /* Line-2 In: Headphone output (output 0 - 0x0c) */
5080         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5081         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5082         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
5083         /* CD pin widget for input */
5084         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5085
5086         /* FIXME: use matrix-type input source selection */
5087         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5088         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5089         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5090         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5091         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5092         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5093         /* Input mixer2 */
5094         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5095         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5096         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5097         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5098         /* Input mixer3 */
5099         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5100         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5101         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5102         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5103         /* ADC1: mute amp left and right */
5104         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5105         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5106         /* ADC2: mute amp left and right */
5107         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5108         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5109         /* ADC3: mute amp left and right */
5110         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5111         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5112
5113         { }
5114 };
5115
5116 static struct hda_verb alc882_eapd_verbs[] = {
5117         /* change to EAPD mode */
5118         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
5119         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
5120         { }
5121 };
5122
5123 /* Mac Pro test */
5124 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
5125         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5126         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5127         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
5128         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
5129         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
5130         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT),
5131         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT),
5132         { } /* end */
5133 };
5134
5135 static struct hda_verb alc882_macpro_init_verbs[] = {
5136         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5137         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5138         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5139         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5140         /* Front Pin: output 0 (0x0c) */
5141         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5142         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5143         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
5144         /* Front Mic pin: input vref at 80% */
5145         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5146         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5147         /* Speaker:  output */
5148         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5149         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5150         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
5151         /* Headphone output (output 0 - 0x0c) */
5152         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5153         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5154         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
5155
5156         /* FIXME: use matrix-type input source selection */
5157         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5158         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5159         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5160         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5161         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5162         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5163         /* Input mixer2 */
5164         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5165         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5166         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5167         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5168         /* Input mixer3 */
5169         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5170         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5171         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5172         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5173         /* ADC1: mute amp left and right */
5174         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5175         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5176         /* ADC2: mute amp left and right */
5177         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5178         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5179         /* ADC3: mute amp left and right */
5180         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5181         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5182
5183         { }
5184 };
5185
5186 /* Macbook Pro rev3 */
5187 static struct hda_verb alc885_mbp3_init_verbs[] = {
5188         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5189         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5190         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5191         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5192         /* Rear mixer */
5193         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5194         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5195         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5196         /* Front Pin: output 0 (0x0c) */
5197         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5198         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5199         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5200         /* HP Pin: output 0 (0x0d) */
5201         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
5202         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5203         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
5204         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5205         /* Mic (rear) pin: input vref at 80% */
5206         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5207         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5208         /* Front Mic pin: input vref at 80% */
5209         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5210         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5211         /* Line In pin: use output 1 when in LineOut mode */
5212         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5213         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5214         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
5215
5216         /* FIXME: use matrix-type input source selection */
5217         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5218         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5219         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5220         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5221         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5222         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5223         /* Input mixer2 */
5224         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5225         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5226         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5227         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5228         /* Input mixer3 */
5229         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5230         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5231         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5232         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5233         /* ADC1: mute amp left and right */
5234         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5235         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5236         /* ADC2: mute amp left and right */
5237         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5238         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5239         /* ADC3: mute amp left and right */
5240         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5241         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5242
5243         { }
5244 };
5245
5246 /* iMac 24 mixer. */
5247 static struct snd_kcontrol_new alc885_imac24_mixer[] = {
5248         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
5249         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
5250         { } /* end */
5251 };
5252
5253 /* iMac 24 init verbs. */
5254 static struct hda_verb alc885_imac24_init_verbs[] = {
5255         /* Internal speakers: output 0 (0x0c) */
5256         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5257         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5258         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
5259         /* Internal speakers: output 0 (0x0c) */
5260         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5261         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5262         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
5263         /* Headphone: output 0 (0x0c) */
5264         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5265         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5266         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5267         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5268         /* Front Mic: input vref at 80% */
5269         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5270         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5271         { }
5272 };
5273
5274 /* Toggle speaker-output according to the hp-jack state */
5275 static void alc885_imac24_automute(struct hda_codec *codec)
5276 {
5277         unsigned int present;
5278
5279         present = snd_hda_codec_read(codec, 0x14, 0,
5280                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5281         snd_hda_codec_amp_stereo(codec, 0x18, HDA_OUTPUT, 0,
5282                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5283         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
5284                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5285 }
5286
5287 /* Processes unsolicited events. */
5288 static void alc885_imac24_unsol_event(struct hda_codec *codec,
5289                                       unsigned int res)
5290 {
5291         /* Headphone insertion or removal. */
5292         if ((res >> 26) == ALC880_HP_EVENT)
5293                 alc885_imac24_automute(codec);
5294 }
5295
5296 static void alc885_mbp3_automute(struct hda_codec *codec)
5297 {
5298         unsigned int present;
5299
5300         present = snd_hda_codec_read(codec, 0x15, 0,
5301                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5302         snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
5303                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5304         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
5305                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
5306
5307 }
5308 static void alc885_mbp3_unsol_event(struct hda_codec *codec,
5309                                     unsigned int res)
5310 {
5311         /* Headphone insertion or removal. */
5312         if ((res >> 26) == ALC880_HP_EVENT)
5313                 alc885_mbp3_automute(codec);
5314 }
5315
5316
5317 static struct hda_verb alc882_targa_verbs[] = {
5318         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5319         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5320
5321         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5322         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5323         
5324         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
5325         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
5326         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5327
5328         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5329         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5330         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
5331         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
5332         { } /* end */
5333 };
5334
5335 /* toggle speaker-output according to the hp-jack state */
5336 static void alc882_targa_automute(struct hda_codec *codec)
5337 {
5338         unsigned int present;
5339  
5340         present = snd_hda_codec_read(codec, 0x14, 0,
5341                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5342         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
5343                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5344         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
5345                                   present ? 1 : 3);
5346 }
5347
5348 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
5349 {
5350         /* Looks like the unsol event is incompatible with the standard
5351          * definition.  4bit tag is placed at 26 bit!
5352          */
5353         if (((res >> 26) == ALC880_HP_EVENT)) {
5354                 alc882_targa_automute(codec);
5355         }
5356 }
5357
5358 static struct hda_verb alc882_asus_a7j_verbs[] = {
5359         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5360         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5361
5362         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5363         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5364         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5365         
5366         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5367         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5368         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5369
5370         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
5371         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
5372         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5373         { } /* end */
5374 };
5375
5376 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5377 {
5378         unsigned int gpiostate, gpiomask, gpiodir;
5379
5380         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5381                                        AC_VERB_GET_GPIO_DATA, 0);
5382
5383         if (!muted)
5384                 gpiostate |= (1 << pin);
5385         else
5386                 gpiostate &= ~(1 << pin);
5387
5388         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5389                                       AC_VERB_GET_GPIO_MASK, 0);
5390         gpiomask |= (1 << pin);
5391
5392         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5393                                      AC_VERB_GET_GPIO_DIRECTION, 0);
5394         gpiodir |= (1 << pin);
5395
5396
5397         snd_hda_codec_write(codec, codec->afg, 0,
5398                             AC_VERB_SET_GPIO_MASK, gpiomask);
5399         snd_hda_codec_write(codec, codec->afg, 0,
5400                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5401
5402         msleep(1);
5403
5404         snd_hda_codec_write(codec, codec->afg, 0,
5405                             AC_VERB_SET_GPIO_DATA, gpiostate);
5406 }
5407
5408 /* set up GPIO at initialization */
5409 static void alc885_macpro_init_hook(struct hda_codec *codec)
5410 {
5411         alc882_gpio_mute(codec, 0, 0);
5412         alc882_gpio_mute(codec, 1, 0);
5413 }
5414
5415 /* set up GPIO and update auto-muting at initialization */
5416 static void alc885_imac24_init_hook(struct hda_codec *codec)
5417 {
5418         alc885_macpro_init_hook(codec);
5419         alc885_imac24_automute(codec);
5420 }
5421
5422 /*
5423  * generic initialization of ADC, input mixers and output mixers
5424  */
5425 static struct hda_verb alc882_auto_init_verbs[] = {
5426         /*
5427          * Unmute ADC0-2 and set the default input to mic-in
5428          */
5429         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5430         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5431         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5432         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5433         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5434         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5435
5436         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5437          * mixer widget
5438          * Note: PASD motherboards uses the Line In 2 as the input for
5439          * front panel mic (mic 2)
5440          */
5441         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
5442         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5443         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5444         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5445         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5446         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5447
5448         /*
5449          * Set up output mixers (0x0c - 0x0f)
5450          */
5451         /* set vol=0 to output mixers */
5452         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5453         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5454         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5455         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5456         /* set up input amps for analog loopback */
5457         /* Amp Indices: DAC = 0, mixer = 1 */
5458         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5459         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5460         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5461         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5462         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5463         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5464         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5465         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5466         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5467         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5468
5469         /* FIXME: use matrix-type input source selection */
5470         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5471         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5472         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5473         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
5474         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
5475         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
5476         /* Input mixer2 */
5477         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5478         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
5479         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
5480         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
5481         /* Input mixer3 */
5482         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5483         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
5484         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
5485         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
5486
5487         { }
5488 };
5489
5490 /* capture mixer elements */
5491 static struct snd_kcontrol_new alc882_capture_alt_mixer[] = {
5492         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
5493         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
5494         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
5495         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
5496         {
5497                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5498                 /* The multiple "Capture Source" controls confuse alsamixer
5499                  * So call somewhat different..
5500                  * FIXME: the controls appear in the "playback" view!
5501                  */
5502                 /* .name = "Capture Source", */
5503                 .name = "Input Source",
5504                 .count = 2,
5505                 .info = alc882_mux_enum_info,
5506                 .get = alc882_mux_enum_get,
5507                 .put = alc882_mux_enum_put,
5508         },
5509         { } /* end */
5510 };
5511
5512 static struct snd_kcontrol_new alc882_capture_mixer[] = {
5513         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
5514         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
5515         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
5516         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
5517         HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
5518         HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
5519         {
5520                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5521                 /* The multiple "Capture Source" controls confuse alsamixer
5522                  * So call somewhat different..
5523                  * FIXME: the controls appear in the "playback" view!
5524                  */
5525                 /* .name = "Capture Source", */
5526                 .name = "Input Source",
5527                 .count = 3,
5528                 .info = alc882_mux_enum_info,
5529                 .get = alc882_mux_enum_get,
5530                 .put = alc882_mux_enum_put,
5531         },
5532         { } /* end */
5533 };
5534
5535 #ifdef CONFIG_SND_HDA_POWER_SAVE
5536 #define alc882_loopbacks        alc880_loopbacks
5537 #endif
5538
5539 /* pcm configuration: identiacal with ALC880 */
5540 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
5541 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
5542 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
5543 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
5544
5545 /*
5546  * configuration and preset
5547  */
5548 static const char *alc882_models[ALC882_MODEL_LAST] = {
5549         [ALC882_3ST_DIG]        = "3stack-dig",
5550         [ALC882_6ST_DIG]        = "6stack-dig",
5551         [ALC882_ARIMA]          = "arima",
5552         [ALC882_W2JC]           = "w2jc",
5553         [ALC885_MACPRO]         = "macpro",
5554         [ALC885_MBP3]           = "mbp3",
5555         [ALC885_IMAC24]         = "imac24",
5556         [ALC882_AUTO]           = "auto",
5557 };
5558
5559 static struct snd_pci_quirk alc882_cfg_tbl[] = {
5560         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
5561         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
5562         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
5563         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
5564         SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA),
5565         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
5566         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
5567         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
5568         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
5569         {}
5570 };
5571
5572 static struct alc_config_preset alc882_presets[] = {
5573         [ALC882_3ST_DIG] = {
5574                 .mixers = { alc882_base_mixer },
5575                 .init_verbs = { alc882_init_verbs },
5576                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5577                 .dac_nids = alc882_dac_nids,
5578                 .dig_out_nid = ALC882_DIGOUT_NID,
5579                 .dig_in_nid = ALC882_DIGIN_NID,
5580                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
5581                 .channel_mode = alc882_ch_modes,
5582                 .need_dac_fix = 1,
5583                 .input_mux = &alc882_capture_source,
5584         },
5585         [ALC882_6ST_DIG] = {
5586                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
5587                 .init_verbs = { alc882_init_verbs },
5588                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5589                 .dac_nids = alc882_dac_nids,
5590                 .dig_out_nid = ALC882_DIGOUT_NID,
5591                 .dig_in_nid = ALC882_DIGIN_NID,
5592                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
5593                 .channel_mode = alc882_sixstack_modes,
5594                 .input_mux = &alc882_capture_source,
5595         },
5596         [ALC882_ARIMA] = {
5597                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
5598                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs },
5599                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5600                 .dac_nids = alc882_dac_nids,
5601                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
5602                 .channel_mode = alc882_sixstack_modes,
5603                 .input_mux = &alc882_capture_source,
5604         },
5605         [ALC882_W2JC] = {
5606                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
5607                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
5608                                 alc880_gpio1_init_verbs },
5609                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5610                 .dac_nids = alc882_dac_nids,
5611                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
5612                 .channel_mode = alc880_threestack_modes,
5613                 .need_dac_fix = 1,
5614                 .input_mux = &alc882_capture_source,
5615                 .dig_out_nid = ALC882_DIGOUT_NID,
5616         },
5617         [ALC885_MBP3] = {
5618                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
5619                 .init_verbs = { alc885_mbp3_init_verbs,
5620                                 alc880_gpio1_init_verbs },
5621                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5622                 .dac_nids = alc882_dac_nids,
5623                 .channel_mode = alc885_mbp_6ch_modes,
5624                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_6ch_modes),
5625                 .input_mux = &alc882_capture_source,
5626                 .dig_out_nid = ALC882_DIGOUT_NID,
5627                 .dig_in_nid = ALC882_DIGIN_NID,
5628                 .unsol_event = alc885_mbp3_unsol_event,
5629                 .init_hook = alc885_mbp3_automute,
5630         },
5631         [ALC885_MACPRO] = {
5632                 .mixers = { alc882_macpro_mixer },
5633                 .init_verbs = { alc882_macpro_init_verbs },
5634                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5635                 .dac_nids = alc882_dac_nids,
5636                 .dig_out_nid = ALC882_DIGOUT_NID,
5637                 .dig_in_nid = ALC882_DIGIN_NID,
5638                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
5639                 .channel_mode = alc882_ch_modes,
5640                 .input_mux = &alc882_capture_source,
5641                 .init_hook = alc885_macpro_init_hook,
5642         },
5643         [ALC885_IMAC24] = {
5644                 .mixers = { alc885_imac24_mixer },
5645                 .init_verbs = { alc885_imac24_init_verbs },
5646                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5647                 .dac_nids = alc882_dac_nids,
5648                 .dig_out_nid = ALC882_DIGOUT_NID,
5649                 .dig_in_nid = ALC882_DIGIN_NID,
5650                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
5651                 .channel_mode = alc882_ch_modes,
5652                 .input_mux = &alc882_capture_source,
5653                 .unsol_event = alc885_imac24_unsol_event,
5654                 .init_hook = alc885_imac24_init_hook,
5655         },
5656         [ALC882_TARGA] = {
5657                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer,
5658                             alc882_capture_mixer },
5659                 .init_verbs = { alc882_init_verbs, alc882_targa_verbs},
5660                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5661                 .dac_nids = alc882_dac_nids,
5662                 .dig_out_nid = ALC882_DIGOUT_NID,
5663                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
5664                 .adc_nids = alc882_adc_nids,
5665                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
5666                 .channel_mode = alc882_3ST_6ch_modes,
5667                 .need_dac_fix = 1,
5668                 .input_mux = &alc882_capture_source,
5669                 .unsol_event = alc882_targa_unsol_event,
5670                 .init_hook = alc882_targa_automute,
5671         },
5672         [ALC882_ASUS_A7J] = {
5673                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer,
5674                             alc882_capture_mixer },
5675                 .init_verbs = { alc882_init_verbs, alc882_asus_a7j_verbs},
5676                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5677                 .dac_nids = alc882_dac_nids,
5678                 .dig_out_nid = ALC882_DIGOUT_NID,
5679                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
5680                 .adc_nids = alc882_adc_nids,
5681                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
5682                 .channel_mode = alc882_3ST_6ch_modes,
5683                 .need_dac_fix = 1,
5684                 .input_mux = &alc882_capture_source,
5685         },      
5686 };
5687
5688
5689 /*
5690  * Pin config fixes
5691  */
5692 enum { 
5693         PINFIX_ABIT_AW9D_MAX
5694 };
5695
5696 static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
5697         { 0x15, 0x01080104 }, /* side */
5698         { 0x16, 0x01011012 }, /* rear */
5699         { 0x17, 0x01016011 }, /* clfe */
5700         { }
5701 };
5702
5703 static const struct alc_pincfg *alc882_pin_fixes[] = {
5704         [PINFIX_ABIT_AW9D_MAX] = alc882_abit_aw9d_pinfix,
5705 };
5706
5707 static struct snd_pci_quirk alc882_pinfix_tbl[] = {
5708         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
5709         {}
5710 };
5711
5712 /*
5713  * BIOS auto configuration
5714  */
5715 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
5716                                               hda_nid_t nid, int pin_type,
5717                                               int dac_idx)
5718 {
5719         /* set as output */
5720         struct alc_spec *spec = codec->spec;
5721         int idx;
5722
5723         if (spec->multiout.dac_nids[dac_idx] == 0x25)
5724                 idx = 4;
5725         else
5726                 idx = spec->multiout.dac_nids[dac_idx] - 2;
5727
5728         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5729                             pin_type);
5730         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
5731                             AMP_OUT_UNMUTE);
5732         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
5733
5734 }
5735
5736 static void alc882_auto_init_multi_out(struct hda_codec *codec)
5737 {
5738         struct alc_spec *spec = codec->spec;
5739         int i;
5740
5741         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
5742         for (i = 0; i <= HDA_SIDE; i++) {
5743                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
5744                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
5745                 if (nid)
5746                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
5747                                                           i);
5748         }
5749 }
5750
5751 static void alc882_auto_init_hp_out(struct hda_codec *codec)
5752 {
5753         struct alc_spec *spec = codec->spec;
5754         hda_nid_t pin;
5755
5756         pin = spec->autocfg.hp_pins[0];
5757         if (pin) /* connect to front */
5758                 /* use dac 0 */
5759                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
5760 }
5761
5762 #define alc882_is_input_pin(nid)        alc880_is_input_pin(nid)
5763 #define ALC882_PIN_CD_NID               ALC880_PIN_CD_NID
5764
5765 static void alc882_auto_init_analog_input(struct hda_codec *codec)
5766 {
5767         struct alc_spec *spec = codec->spec;
5768         int i;
5769
5770         for (i = 0; i < AUTO_PIN_LAST; i++) {
5771                 hda_nid_t nid = spec->autocfg.input_pins[i];
5772                 if (alc882_is_input_pin(nid)) {
5773                         snd_hda_codec_write(codec, nid, 0,
5774                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
5775                                             i <= AUTO_PIN_FRONT_MIC ?
5776                                             PIN_VREF80 : PIN_IN);
5777                         if (nid != ALC882_PIN_CD_NID)
5778                                 snd_hda_codec_write(codec, nid, 0,
5779                                                     AC_VERB_SET_AMP_GAIN_MUTE,
5780                                                     AMP_OUT_MUTE);
5781                 }
5782         }
5783 }
5784
5785 /* add mic boosts if needed */
5786 static int alc_auto_add_mic_boost(struct hda_codec *codec)
5787 {
5788         struct alc_spec *spec = codec->spec;
5789         int err;
5790         hda_nid_t nid;
5791
5792         nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
5793         if (nid) {
5794                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
5795                                   "Mic Boost",
5796                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
5797                 if (err < 0)
5798                         return err;
5799         }
5800         nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
5801         if (nid) {
5802                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
5803                                   "Front Mic Boost",
5804                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
5805                 if (err < 0)
5806                         return err;
5807         }
5808         return 0;
5809 }
5810
5811 /* almost identical with ALC880 parser... */
5812 static int alc882_parse_auto_config(struct hda_codec *codec)
5813 {
5814         struct alc_spec *spec = codec->spec;
5815         int err = alc880_parse_auto_config(codec);
5816
5817         if (err < 0)
5818                 return err;
5819         else if (!err)
5820                 return 0; /* no config found */
5821
5822         err = alc_auto_add_mic_boost(codec);
5823         if (err < 0)
5824                 return err;
5825
5826         /* hack - override the init verbs */
5827         spec->init_verbs[0] = alc882_auto_init_verbs;
5828
5829         return 1; /* config found */
5830 }
5831
5832 /* additional initialization for auto-configuration model */
5833 static void alc882_auto_init(struct hda_codec *codec)
5834 {
5835         alc882_auto_init_multi_out(codec);
5836         alc882_auto_init_hp_out(codec);
5837         alc882_auto_init_analog_input(codec);
5838 }
5839
5840 static int patch_alc882(struct hda_codec *codec)
5841 {
5842         struct alc_spec *spec;
5843         int err, board_config;
5844
5845         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5846         if (spec == NULL)
5847                 return -ENOMEM;
5848
5849         codec->spec = spec;
5850
5851         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
5852                                                   alc882_models,
5853                                                   alc882_cfg_tbl);
5854
5855         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
5856                 /* Pick up systems that don't supply PCI SSID */
5857                 switch (codec->subsystem_id) {
5858                 case 0x106b0c00: /* Mac Pro */
5859                         board_config = ALC885_MACPRO;
5860                         break;
5861                 case 0x106b1000: /* iMac 24 */
5862                         board_config = ALC885_IMAC24;
5863                         break;
5864                 case 0x106b2c00: /* Macbook Pro rev3 */
5865                         board_config = ALC885_MBP3;
5866                         break;
5867                 default:
5868                         printk(KERN_INFO "hda_codec: Unknown model for ALC882, "
5869                                          "trying auto-probe from BIOS...\n");
5870                         board_config = ALC882_AUTO;
5871                 }
5872         }
5873
5874         alc_fix_pincfg(codec, alc882_pinfix_tbl, alc882_pin_fixes);
5875
5876         if (board_config == ALC882_AUTO) {
5877                 /* automatic parse from the BIOS config */
5878                 err = alc882_parse_auto_config(codec);
5879                 if (err < 0) {
5880                         alc_free(codec);
5881                         return err;
5882                 } else if (!err) {
5883                         printk(KERN_INFO
5884                                "hda_codec: Cannot set up configuration "
5885                                "from BIOS.  Using base mode...\n");
5886                         board_config = ALC882_3ST_DIG;
5887                 }
5888         }
5889
5890         if (board_config != ALC882_AUTO)
5891                 setup_preset(spec, &alc882_presets[board_config]);
5892
5893         spec->stream_name_analog = "ALC882 Analog";
5894         spec->stream_analog_playback = &alc882_pcm_analog_playback;
5895         spec->stream_analog_capture = &alc882_pcm_analog_capture;
5896
5897         spec->stream_name_digital = "ALC882 Digital";
5898         spec->stream_digital_playback = &alc882_pcm_digital_playback;
5899         spec->stream_digital_capture = &alc882_pcm_digital_capture;
5900
5901         if (!spec->adc_nids && spec->input_mux) {
5902                 /* check whether NID 0x07 is valid */
5903                 unsigned int wcap = get_wcaps(codec, 0x07);
5904                 /* get type */
5905                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
5906                 if (wcap != AC_WID_AUD_IN) {
5907                         spec->adc_nids = alc882_adc_nids_alt;
5908                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
5909                         spec->mixers[spec->num_mixers] =
5910                                 alc882_capture_alt_mixer;
5911                         spec->num_mixers++;
5912                 } else {
5913                         spec->adc_nids = alc882_adc_nids;
5914                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
5915                         spec->mixers[spec->num_mixers] = alc882_capture_mixer;
5916                         spec->num_mixers++;
5917                 }
5918         }
5919
5920         codec->patch_ops = alc_patch_ops;
5921         if (board_config == ALC882_AUTO)
5922                 spec->init_hook = alc882_auto_init;
5923 #ifdef CONFIG_SND_HDA_POWER_SAVE
5924         if (!spec->loopback.amplist)
5925                 spec->loopback.amplist = alc882_loopbacks;
5926 #endif
5927
5928         return 0;
5929 }
5930
5931 /*
5932  * ALC883 support
5933  *
5934  * ALC883 is almost identical with ALC880 but has cleaner and more flexible
5935  * configuration.  Each pin widget can choose any input DACs and a mixer.
5936  * Each ADC is connected from a mixer of all inputs.  This makes possible
5937  * 6-channel independent captures.
5938  *
5939  * In addition, an independent DAC for the multi-playback (not used in this
5940  * driver yet).
5941  */
5942 #define ALC883_DIGOUT_NID       0x06
5943 #define ALC883_DIGIN_NID        0x0a
5944
5945 static hda_nid_t alc883_dac_nids[4] = {
5946         /* front, rear, clfe, rear_surr */
5947         0x02, 0x04, 0x03, 0x05
5948 };
5949
5950 static hda_nid_t alc883_adc_nids[2] = {
5951         /* ADC1-2 */
5952         0x08, 0x09,
5953 };
5954
5955 /* input MUX */
5956 /* FIXME: should be a matrix-type input source selection */
5957
5958 static struct hda_input_mux alc883_capture_source = {
5959         .num_items = 4,
5960         .items = {
5961                 { "Mic", 0x0 },
5962                 { "Front Mic", 0x1 },
5963                 { "Line", 0x2 },
5964                 { "CD", 0x4 },
5965         },
5966 };
5967
5968 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
5969         .num_items = 2,
5970         .items = {
5971                 { "Mic", 0x1 },
5972                 { "Line", 0x2 },
5973         },
5974 };
5975
5976 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
5977         .num_items = 4,
5978         .items = {
5979                 { "Mic", 0x0 },
5980                 { "iMic", 0x1 },
5981                 { "Line", 0x2 },
5982                 { "CD", 0x4 },
5983         },
5984 };
5985
5986 #define alc883_mux_enum_info alc_mux_enum_info
5987 #define alc883_mux_enum_get alc_mux_enum_get
5988
5989 static int alc883_mux_enum_put(struct snd_kcontrol *kcontrol,
5990                                struct snd_ctl_elem_value *ucontrol)
5991 {
5992         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5993         struct alc_spec *spec = codec->spec;
5994         const struct hda_input_mux *imux = spec->input_mux;
5995         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
5996         static hda_nid_t capture_mixers[3] = { 0x24, 0x23, 0x22 };
5997         hda_nid_t nid = capture_mixers[adc_idx];
5998         unsigned int *cur_val = &spec->cur_mux[adc_idx];
5999         unsigned int i, idx;
6000
6001         idx = ucontrol->value.enumerated.item[0];
6002         if (idx >= imux->num_items)
6003                 idx = imux->num_items - 1;
6004         if (*cur_val == idx)
6005                 return 0;
6006         for (i = 0; i < imux->num_items; i++) {
6007                 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
6008                 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
6009                                          imux->items[i].index,
6010                                          HDA_AMP_MUTE, v);
6011         }
6012         *cur_val = idx;
6013         return 1;
6014 }
6015
6016 /*
6017  * 2ch mode
6018  */
6019 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
6020         { 2, NULL }
6021 };
6022
6023 /*
6024  * 2ch mode
6025  */
6026 static struct hda_verb alc883_3ST_ch2_init[] = {
6027         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6028         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6029         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6030         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6031         { } /* end */
6032 };
6033
6034 /*
6035  * 6ch mode
6036  */
6037 static struct hda_verb alc883_3ST_ch6_init[] = {
6038         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6039         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6040         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6041         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6042         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6043         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6044         { } /* end */
6045 };
6046
6047 static struct hda_channel_mode alc883_3ST_6ch_modes[2] = {
6048         { 2, alc883_3ST_ch2_init },
6049         { 6, alc883_3ST_ch6_init },
6050 };
6051
6052 /*
6053  * 6ch mode
6054  */
6055 static struct hda_verb alc883_sixstack_ch6_init[] = {
6056         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6057         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6058         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6059         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6060         { } /* end */
6061 };
6062
6063 /*
6064  * 8ch mode
6065  */
6066 static struct hda_verb alc883_sixstack_ch8_init[] = {
6067         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6068         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6069         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6070         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6071         { } /* end */
6072 };
6073
6074 static struct hda_channel_mode alc883_sixstack_modes[2] = {
6075         { 6, alc883_sixstack_ch6_init },
6076         { 8, alc883_sixstack_ch8_init },
6077 };
6078
6079 static struct hda_verb alc883_medion_eapd_verbs[] = {
6080         /* eanable EAPD on medion laptop */
6081         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
6082         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
6083         { }
6084 };
6085
6086 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
6087  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
6088  */
6089
6090 static struct snd_kcontrol_new alc883_base_mixer[] = {
6091         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6092         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6093         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6094         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6095         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6096         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6097         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6098         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6099         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6100         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6101         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6102         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6103         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6104         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6105         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6106         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6107         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6108         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6109         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6110         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6111         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6112         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6113         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6114         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6115         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6116         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6117         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6118         {
6119                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6120                 /* .name = "Capture Source", */
6121                 .name = "Input Source",
6122                 .count = 2,
6123                 .info = alc883_mux_enum_info,
6124                 .get = alc883_mux_enum_get,
6125                 .put = alc883_mux_enum_put,
6126         },
6127         { } /* end */
6128 };
6129
6130 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
6131         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6132         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6133         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6134         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6135         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6136         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6137         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6138         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6139         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6140         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6141         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6142         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6143         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6144         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6145         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6146         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6147         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6148         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6149         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6150         {
6151                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6152                 /* .name = "Capture Source", */
6153                 .name = "Input Source",
6154                 .count = 2,
6155                 .info = alc883_mux_enum_info,
6156                 .get = alc883_mux_enum_get,
6157                 .put = alc883_mux_enum_put,
6158         },
6159         { } /* end */
6160 };
6161
6162 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
6163         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6164         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6165         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6166         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6167         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6168         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6169         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6170         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6171         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6172         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6173         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6174         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6175         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6176         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6177         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6178         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6179         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6180         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6181         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6182         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6183         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6184         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6185         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6186         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6187         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6188         {
6189                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6190                 /* .name = "Capture Source", */
6191                 .name = "Input Source",
6192                 .count = 2,
6193                 .info = alc883_mux_enum_info,
6194                 .get = alc883_mux_enum_get,
6195                 .put = alc883_mux_enum_put,
6196         },
6197         { } /* end */
6198 };
6199
6200 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
6201         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6202         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6203         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6204         HDA_CODEC_MUTE("Surround Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6205         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6206         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6207         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x16, 1, 0x0, HDA_OUTPUT),
6208         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
6209         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6210         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6211         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6212         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6213         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6214         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6215         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6216         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6217         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6218         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6219         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6220         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6221         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6222         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6223         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6224
6225         {
6226                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6227                 /* .name = "Capture Source", */
6228                 .name = "Input Source",
6229                 .count = 1,
6230                 .info = alc883_mux_enum_info,
6231                 .get = alc883_mux_enum_get,
6232                 .put = alc883_mux_enum_put,
6233         },
6234         { } /* end */
6235 };
6236
6237 static struct snd_kcontrol_new alc883_tagra_mixer[] = {
6238         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6239         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6240         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6241         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6242         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6243         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6244         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6245         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6246         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6247         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6248         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6249         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6250         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6251         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6252         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6253         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6254         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6255         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6256         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6257         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6258         {
6259                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6260                 /* .name = "Capture Source", */
6261                 .name = "Input Source",
6262                 .count = 2,
6263                 .info = alc883_mux_enum_info,
6264                 .get = alc883_mux_enum_get,
6265                 .put = alc883_mux_enum_put,
6266         },
6267         { } /* end */
6268 };
6269
6270 static struct snd_kcontrol_new alc883_tagra_2ch_mixer[] = {
6271         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6272         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6273         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6274         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6275         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6276         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6277         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6278         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6279         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6280         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6281         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6282         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6283         {
6284                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6285                 /* .name = "Capture Source", */
6286                 .name = "Input Source",
6287                 .count = 2,
6288                 .info = alc883_mux_enum_info,
6289                 .get = alc883_mux_enum_get,
6290                 .put = alc883_mux_enum_put,
6291         },
6292         { } /* end */
6293 };
6294
6295 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
6296         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6297         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6298         HDA_CODEC_VOLUME("iSpeaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6299         HDA_BIND_MUTE("iSpeaker Playback Switch", 0x0d, 2, HDA_INPUT),
6300         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6301         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6302         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6303         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6304         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6305         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6306         {
6307                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6308                 /* .name = "Capture Source", */
6309                 .name = "Input Source",
6310                 .count = 1,
6311                 .info = alc883_mux_enum_info,
6312                 .get = alc883_mux_enum_get,
6313                 .put = alc883_mux_enum_put,
6314         },
6315         { } /* end */
6316 };
6317
6318 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
6319         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6320         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
6321         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6322         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6323         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6324         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6325         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6326         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6327         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6328         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6329         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6330         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6331         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6332         {
6333                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6334                 /* .name = "Capture Source", */
6335                 .name = "Input Source",
6336                 .count = 2,
6337                 .info = alc883_mux_enum_info,
6338                 .get = alc883_mux_enum_get,
6339                 .put = alc883_mux_enum_put,
6340         },
6341         { } /* end */
6342 };
6343
6344 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
6345         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6346         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6347         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 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("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6351         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6352         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6353         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6354         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6355         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6356         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6357         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6358         {
6359                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6360                 /* .name = "Capture Source", */
6361                 .name = "Input Source",
6362                 .count = 2,
6363                 .info = alc883_mux_enum_info,
6364                 .get = alc883_mux_enum_get,
6365                 .put = alc883_mux_enum_put,
6366         },
6367         { } /* end */
6368 };      
6369
6370 static struct snd_kcontrol_new alc888_6st_hp_mixer[] = {
6371         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6372         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6373         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
6374         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
6375         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
6376         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
6377         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
6378         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
6379         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6380         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6381         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6382         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6383         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6384         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6385         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6386         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6387         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6388         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6389         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6390         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6391         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6392         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6393         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6394         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6395         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6396         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6397         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6398         {
6399                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6400                 /* .name = "Capture Source", */
6401                 .name = "Input Source",
6402                 .count = 2,
6403                 .info = alc883_mux_enum_info,
6404                 .get = alc883_mux_enum_get,
6405                 .put = alc883_mux_enum_put,
6406         },
6407         { } /* end */
6408 };
6409
6410 static struct snd_kcontrol_new alc888_3st_hp_mixer[] = {
6411         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6412         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6413         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
6414         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
6415         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
6416         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
6417         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
6418         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
6419         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6420         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6421         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6422         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6423         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6424         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6425         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6426         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6427         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6428         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6429         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6430         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6431         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6432         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6433         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6434         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6435         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6436         {
6437                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6438                 /* .name = "Capture Source", */
6439                 .name = "Input Source",
6440                 .count = 2,
6441                 .info = alc883_mux_enum_info,
6442                 .get = alc883_mux_enum_get,
6443                 .put = alc883_mux_enum_put,
6444         },
6445         { } /* end */
6446 };
6447
6448 static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
6449         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6450         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6451         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6452         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6453         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6454         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6455         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6456         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6457         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6458         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6459         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6460         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6461         {
6462                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6463                 /* .name = "Capture Source", */
6464                 .name = "Input Source",
6465                 .count = 2,
6466                 .info = alc883_mux_enum_info,
6467                 .get = alc883_mux_enum_get,
6468                 .put = alc883_mux_enum_put,
6469         },
6470         { } /* end */
6471 };
6472
6473 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
6474         {
6475                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6476                 .name = "Channel Mode",
6477                 .info = alc_ch_mode_info,
6478                 .get = alc_ch_mode_get,
6479                 .put = alc_ch_mode_put,
6480         },
6481         { } /* end */
6482 };
6483
6484 static struct hda_verb alc883_init_verbs[] = {
6485         /* ADC1: mute amp left and right */
6486         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6487         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6488         /* ADC2: mute amp left and right */
6489         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6490         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6491         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6492         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6493         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6494         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6495         /* Rear mixer */
6496         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6497         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6498         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6499         /* CLFE mixer */
6500         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6501         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6502         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6503         /* Side mixer */
6504         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6505         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6506         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6507
6508         /* mute analog input loopbacks */
6509         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6510         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6511         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6512         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6513         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6514
6515         /* Front Pin: output 0 (0x0c) */
6516         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6517         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6518         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6519         /* Rear Pin: output 1 (0x0d) */
6520         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6521         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6522         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
6523         /* CLFE Pin: output 2 (0x0e) */
6524         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6525         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6526         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
6527         /* Side Pin: output 3 (0x0f) */
6528         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6529         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6530         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
6531         /* Mic (rear) pin: input vref at 80% */
6532         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6533         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6534         /* Front Mic pin: input vref at 80% */
6535         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6536         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6537         /* Line In pin: input */
6538         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6539         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6540         /* Line-2 In: Headphone output (output 0 - 0x0c) */
6541         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6542         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6543         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
6544         /* CD pin widget for input */
6545         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6546
6547         /* FIXME: use matrix-type input source selection */
6548         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6549         /* Input mixer2 */
6550         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6551         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6552         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6553         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
6554         /* Input mixer3 */
6555         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6556         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6557         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6558         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
6559         { }
6560 };
6561
6562 static struct hda_verb alc883_tagra_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
6566         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6567         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6568         
6569         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6570         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6571         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6572
6573         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6574         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6575         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
6576         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
6577
6578         { } /* end */
6579 };
6580
6581 static struct hda_verb alc883_lenovo_101e_verbs[] = {
6582         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6583         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
6584         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
6585         { } /* end */
6586 };
6587
6588 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
6589         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6590         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6591         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6592         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6593         { } /* end */
6594 };
6595
6596 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
6597         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6598         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6599         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6600         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
6601         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
6602         { } /* end */
6603 };
6604
6605 static struct hda_verb alc883_haier_w66_verbs[] = {
6606         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6607         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6608
6609         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6610
6611         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
6612         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6613         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6614         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6615         { } /* end */
6616 };
6617
6618 static struct hda_verb alc888_6st_hp_verbs[] = {
6619         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
6620         {0x15, AC_VERB_SET_CONNECT_SEL, 0x02},  /* Rear : output 2 (0x0e) */
6621         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* CLFE : output 1 (0x0d) */
6622         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},  /* Side : output 3 (0x0f) */
6623         { }
6624 };
6625
6626 static struct hda_verb alc888_3st_hp_verbs[] = {
6627         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
6628         {0x18, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
6629         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
6630         { }
6631 };
6632
6633 static struct hda_verb alc888_3st_hp_2ch_init[] = {
6634         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6635         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6636         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6637         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6638         { }
6639 };
6640
6641 static struct hda_verb alc888_3st_hp_6ch_init[] = {
6642         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6643         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6644         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6645         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6646         { }
6647 };
6648
6649 static struct hda_channel_mode alc888_3st_hp_modes[2] = {
6650         { 2, alc888_3st_hp_2ch_init },
6651         { 6, alc888_3st_hp_6ch_init },
6652 };
6653
6654 /* toggle front-jack and RCA according to the hp-jack state */
6655 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
6656 {
6657         unsigned int present;
6658  
6659         present = snd_hda_codec_read(codec, 0x1b, 0,
6660                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6661         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
6662                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6663         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
6664                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6665 }
6666
6667 /* toggle RCA according to the front-jack state */
6668 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
6669 {
6670         unsigned int present;
6671  
6672         present = snd_hda_codec_read(codec, 0x14, 0,
6673                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6674         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
6675                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6676 }
6677
6678 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
6679                                              unsigned int res)
6680 {
6681         if ((res >> 26) == ALC880_HP_EVENT)
6682                 alc888_lenovo_ms7195_front_automute(codec);
6683         if ((res >> 26) == ALC880_FRONT_EVENT)
6684                 alc888_lenovo_ms7195_rca_automute(codec);
6685 }
6686
6687 static struct hda_verb alc883_medion_md2_verbs[] = {
6688         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6689         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6690
6691         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6692
6693         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6694         { } /* end */
6695 };
6696
6697 /* toggle speaker-output according to the hp-jack state */
6698 static void alc883_medion_md2_automute(struct hda_codec *codec)
6699 {
6700         unsigned int present;
6701  
6702         present = snd_hda_codec_read(codec, 0x14, 0,
6703                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6704         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
6705                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6706 }
6707
6708 static void alc883_medion_md2_unsol_event(struct hda_codec *codec,
6709                                           unsigned int res)
6710 {
6711         if ((res >> 26) == ALC880_HP_EVENT)
6712                 alc883_medion_md2_automute(codec);
6713 }
6714
6715 /* toggle speaker-output according to the hp-jack state */
6716 static void alc883_tagra_automute(struct hda_codec *codec)
6717 {
6718         unsigned int present;
6719         unsigned char bits;
6720
6721         present = snd_hda_codec_read(codec, 0x14, 0,
6722                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6723         bits = present ? HDA_AMP_MUTE : 0;
6724         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
6725                                  HDA_AMP_MUTE, bits);
6726         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
6727                                   present ? 1 : 3);
6728 }
6729
6730 static void alc883_tagra_unsol_event(struct hda_codec *codec, unsigned int res)
6731 {
6732         if ((res >> 26) == ALC880_HP_EVENT)
6733                 alc883_tagra_automute(codec);
6734 }
6735
6736 static void alc883_haier_w66_automute(struct hda_codec *codec)
6737 {
6738         unsigned int present;
6739         unsigned char bits;
6740
6741         present = snd_hda_codec_read(codec, 0x1b, 0,
6742                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6743         bits = present ? 0x80 : 0;
6744         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
6745                                  0x80, bits);
6746 }
6747
6748 static void alc883_haier_w66_unsol_event(struct hda_codec *codec,
6749                                          unsigned int res)
6750 {
6751         if ((res >> 26) == ALC880_HP_EVENT)
6752                 alc883_haier_w66_automute(codec);
6753 }
6754
6755 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
6756 {
6757         unsigned int present;
6758         unsigned char bits;
6759
6760         present = snd_hda_codec_read(codec, 0x14, 0,
6761                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6762         bits = present ? HDA_AMP_MUTE : 0;
6763         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
6764                                  HDA_AMP_MUTE, bits);
6765 }
6766
6767 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
6768 {
6769         unsigned int present;
6770         unsigned char bits;
6771
6772         present = snd_hda_codec_read(codec, 0x1b, 0,
6773                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6774         bits = present ? HDA_AMP_MUTE : 0;
6775         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
6776                                  HDA_AMP_MUTE, bits);
6777         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
6778                                  HDA_AMP_MUTE, bits);
6779 }
6780
6781 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
6782                                            unsigned int res)
6783 {
6784         if ((res >> 26) == ALC880_HP_EVENT)
6785                 alc883_lenovo_101e_all_automute(codec);
6786         if ((res >> 26) == ALC880_FRONT_EVENT)
6787                 alc883_lenovo_101e_ispeaker_automute(codec);
6788 }
6789
6790 /* toggle speaker-output according to the hp-jack state */
6791 static void alc883_acer_aspire_automute(struct hda_codec *codec)
6792 {
6793         unsigned int present;
6794  
6795         present = snd_hda_codec_read(codec, 0x14, 0,
6796                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6797         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
6798                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6799         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
6800                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6801 }
6802
6803 static void alc883_acer_aspire_unsol_event(struct hda_codec *codec,
6804                                            unsigned int res)
6805 {
6806         if ((res >> 26) == ALC880_HP_EVENT)
6807                 alc883_acer_aspire_automute(codec);
6808 }
6809
6810 static struct hda_verb alc883_acer_eapd_verbs[] = {
6811         /* HP Pin: output 0 (0x0c) */
6812         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6813         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6814         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6815         /* Front Pin: output 0 (0x0c) */
6816         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6817         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6818         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6819         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
6820         /* eanable EAPD on medion laptop */
6821         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
6822         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
6823         /* enable unsolicited event */
6824         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6825         { }
6826 };
6827
6828 /*
6829  * generic initialization of ADC, input mixers and output mixers
6830  */
6831 static struct hda_verb alc883_auto_init_verbs[] = {
6832         /*
6833          * Unmute ADC0-2 and set the default input to mic-in
6834          */
6835         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6836         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6837         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6838         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6839
6840         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
6841          * mixer widget
6842          * Note: PASD motherboards uses the Line In 2 as the input for
6843          * front panel mic (mic 2)
6844          */
6845         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
6846         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6847         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6848         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6849         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6850         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6851
6852         /*
6853          * Set up output mixers (0x0c - 0x0f)
6854          */
6855         /* set vol=0 to output mixers */
6856         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6857         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6858         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6859         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6860         /* set up input amps for analog loopback */
6861         /* Amp Indices: DAC = 0, mixer = 1 */
6862         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6863         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6864         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6865         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6866         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6867         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6868         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6869         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6870         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6871         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6872
6873         /* FIXME: use matrix-type input source selection */
6874         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6875         /* Input mixer1 */
6876         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6877         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6878         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6879         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
6880         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
6881         /* Input mixer2 */
6882         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6883         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6884         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6885         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
6886         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
6887
6888         { }
6889 };
6890
6891 /* capture mixer elements */
6892 static struct snd_kcontrol_new alc883_capture_mixer[] = {
6893         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6894         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6895         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6896         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6897         {
6898                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6899                 /* The multiple "Capture Source" controls confuse alsamixer
6900                  * So call somewhat different..
6901                  * FIXME: the controls appear in the "playback" view!
6902                  */
6903                 /* .name = "Capture Source", */
6904                 .name = "Input Source",
6905                 .count = 2,
6906                 .info = alc882_mux_enum_info,
6907                 .get = alc882_mux_enum_get,
6908                 .put = alc882_mux_enum_put,
6909         },
6910         { } /* end */
6911 };
6912
6913 #ifdef CONFIG_SND_HDA_POWER_SAVE
6914 #define alc883_loopbacks        alc880_loopbacks
6915 #endif
6916
6917 /* pcm configuration: identiacal with ALC880 */
6918 #define alc883_pcm_analog_playback      alc880_pcm_analog_playback
6919 #define alc883_pcm_analog_capture       alc880_pcm_analog_capture
6920 #define alc883_pcm_digital_playback     alc880_pcm_digital_playback
6921 #define alc883_pcm_digital_capture      alc880_pcm_digital_capture
6922
6923 /*
6924  * configuration and preset
6925  */
6926 static const char *alc883_models[ALC883_MODEL_LAST] = {
6927         [ALC883_3ST_2ch_DIG]    = "3stack-dig",
6928         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
6929         [ALC883_3ST_6ch]        = "3stack-6ch",
6930         [ALC883_6ST_DIG]        = "6stack-dig",
6931         [ALC883_TARGA_DIG]      = "targa-dig",
6932         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
6933         [ALC883_ACER]           = "acer",
6934         [ALC883_ACER_ASPIRE]    = "acer-aspire",
6935         [ALC883_MEDION]         = "medion",
6936         [ALC883_MEDION_MD2]     = "medion-md2",
6937         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
6938         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
6939         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
6940         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
6941         [ALC883_HAIER_W66]      = "haier-w66",
6942         [ALC888_6ST_HP]         = "6stack-hp",
6943         [ALC888_3ST_HP]         = "3stack-hp",
6944         [ALC883_AUTO]           = "auto",
6945 };
6946
6947 static struct snd_pci_quirk alc883_cfg_tbl[] = {
6948         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG),
6949         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
6950         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
6951         SND_PCI_QUIRK(0x1558, 0, "Clevo laptop", ALC883_LAPTOP_EAPD),
6952         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
6953         SND_PCI_QUIRK(0x1458, 0xa002, "MSI", ALC883_6ST_DIG),
6954         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
6955         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
6956         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
6957         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
6958         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
6959         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
6960         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
6961         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
6962         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
6963         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
6964         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
6965         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
6966         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
6967         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
6968         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
6969         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
6970         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
6971         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
6972         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
6973         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
6974         SND_PCI_QUIRK(0x1025, 0, "Acer laptop", ALC883_ACER),
6975         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
6976         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
6977         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
6978         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
6979         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
6980         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
6981         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
6982         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC888_6ST_HP),
6983         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
6984         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
6985         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
6986         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
6987         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
6988         {}
6989 };
6990
6991 static struct alc_config_preset alc883_presets[] = {
6992         [ALC883_3ST_2ch_DIG] = {
6993                 .mixers = { alc883_3ST_2ch_mixer },
6994                 .init_verbs = { alc883_init_verbs },
6995                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
6996                 .dac_nids = alc883_dac_nids,
6997                 .dig_out_nid = ALC883_DIGOUT_NID,
6998                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
6999                 .adc_nids = alc883_adc_nids,
7000                 .dig_in_nid = ALC883_DIGIN_NID,
7001                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7002                 .channel_mode = alc883_3ST_2ch_modes,
7003                 .input_mux = &alc883_capture_source,
7004         },
7005         [ALC883_3ST_6ch_DIG] = {
7006                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
7007                 .init_verbs = { alc883_init_verbs },
7008                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7009                 .dac_nids = alc883_dac_nids,
7010                 .dig_out_nid = ALC883_DIGOUT_NID,
7011                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7012                 .adc_nids = alc883_adc_nids,
7013                 .dig_in_nid = ALC883_DIGIN_NID,
7014                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7015                 .channel_mode = alc883_3ST_6ch_modes,
7016                 .need_dac_fix = 1,
7017                 .input_mux = &alc883_capture_source,
7018         },
7019         [ALC883_3ST_6ch] = {
7020                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
7021                 .init_verbs = { alc883_init_verbs },
7022                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7023                 .dac_nids = alc883_dac_nids,
7024                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7025                 .adc_nids = alc883_adc_nids,
7026                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7027                 .channel_mode = alc883_3ST_6ch_modes,
7028                 .need_dac_fix = 1,
7029                 .input_mux = &alc883_capture_source,
7030         },
7031         [ALC883_6ST_DIG] = {
7032                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
7033                 .init_verbs = { alc883_init_verbs },
7034                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7035                 .dac_nids = alc883_dac_nids,
7036                 .dig_out_nid = ALC883_DIGOUT_NID,
7037                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7038                 .adc_nids = alc883_adc_nids,
7039                 .dig_in_nid = ALC883_DIGIN_NID,
7040                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7041                 .channel_mode = alc883_sixstack_modes,
7042                 .input_mux = &alc883_capture_source,
7043         },
7044         [ALC883_TARGA_DIG] = {
7045                 .mixers = { alc883_tagra_mixer, alc883_chmode_mixer },
7046                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
7047                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7048                 .dac_nids = alc883_dac_nids,
7049                 .dig_out_nid = ALC883_DIGOUT_NID,
7050                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7051                 .adc_nids = alc883_adc_nids,
7052                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7053                 .channel_mode = alc883_3ST_6ch_modes,
7054                 .need_dac_fix = 1,
7055                 .input_mux = &alc883_capture_source,
7056                 .unsol_event = alc883_tagra_unsol_event,
7057                 .init_hook = alc883_tagra_automute,
7058         },
7059         [ALC883_TARGA_2ch_DIG] = {
7060                 .mixers = { alc883_tagra_2ch_mixer},
7061                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
7062                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7063                 .dac_nids = alc883_dac_nids,
7064                 .dig_out_nid = ALC883_DIGOUT_NID,
7065                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7066                 .adc_nids = alc883_adc_nids,
7067                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7068                 .channel_mode = alc883_3ST_2ch_modes,
7069                 .input_mux = &alc883_capture_source,
7070                 .unsol_event = alc883_tagra_unsol_event,
7071                 .init_hook = alc883_tagra_automute,
7072         },
7073         [ALC883_ACER] = {
7074                 .mixers = { alc883_base_mixer },
7075                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
7076                  * and the headphone jack.  Turn this on and rely on the
7077                  * standard mute methods whenever the user wants to turn
7078                  * these outputs off.
7079                  */
7080                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
7081                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7082                 .dac_nids = alc883_dac_nids,
7083                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7084                 .adc_nids = alc883_adc_nids,
7085                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7086                 .channel_mode = alc883_3ST_2ch_modes,
7087                 .input_mux = &alc883_capture_source,
7088         },
7089         [ALC883_ACER_ASPIRE] = {
7090                 .mixers = { alc883_acer_aspire_mixer },
7091                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
7092                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7093                 .dac_nids = alc883_dac_nids,
7094                 .dig_out_nid = ALC883_DIGOUT_NID,
7095                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7096                 .adc_nids = alc883_adc_nids,
7097                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7098                 .channel_mode = alc883_3ST_2ch_modes,
7099                 .input_mux = &alc883_capture_source,
7100                 .unsol_event = alc883_acer_aspire_unsol_event,
7101                 .init_hook = alc883_acer_aspire_automute,
7102         },
7103         [ALC883_MEDION] = {
7104                 .mixers = { alc883_fivestack_mixer,
7105                             alc883_chmode_mixer },
7106                 .init_verbs = { alc883_init_verbs,
7107                                 alc883_medion_eapd_verbs },
7108                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7109                 .dac_nids = alc883_dac_nids,
7110                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7111                 .adc_nids = alc883_adc_nids,
7112                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7113                 .channel_mode = alc883_sixstack_modes,
7114                 .input_mux = &alc883_capture_source,
7115         },
7116         [ALC883_MEDION_MD2] = {
7117                 .mixers = { alc883_medion_md2_mixer},
7118                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
7119                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7120                 .dac_nids = alc883_dac_nids,
7121                 .dig_out_nid = ALC883_DIGOUT_NID,
7122                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7123                 .adc_nids = alc883_adc_nids,
7124                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7125                 .channel_mode = alc883_3ST_2ch_modes,
7126                 .input_mux = &alc883_capture_source,
7127                 .unsol_event = alc883_medion_md2_unsol_event,
7128                 .init_hook = alc883_medion_md2_automute,
7129         },      
7130         [ALC883_LAPTOP_EAPD] = {
7131                 .mixers = { alc883_base_mixer },
7132                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
7133                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7134                 .dac_nids = alc883_dac_nids,
7135                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7136                 .adc_nids = alc883_adc_nids,
7137                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7138                 .channel_mode = alc883_3ST_2ch_modes,
7139                 .input_mux = &alc883_capture_source,
7140         },
7141         [ALC883_LENOVO_101E_2ch] = {
7142                 .mixers = { alc883_lenovo_101e_2ch_mixer},
7143                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
7144                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7145                 .dac_nids = alc883_dac_nids,
7146                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7147                 .adc_nids = alc883_adc_nids,
7148                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7149                 .channel_mode = alc883_3ST_2ch_modes,
7150                 .input_mux = &alc883_lenovo_101e_capture_source,
7151                 .unsol_event = alc883_lenovo_101e_unsol_event,
7152                 .init_hook = alc883_lenovo_101e_all_automute,
7153         },
7154         [ALC883_LENOVO_NB0763] = {
7155                 .mixers = { alc883_lenovo_nb0763_mixer },
7156                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
7157                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7158                 .dac_nids = alc883_dac_nids,
7159                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7160                 .adc_nids = alc883_adc_nids,
7161                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7162                 .channel_mode = alc883_3ST_2ch_modes,
7163                 .need_dac_fix = 1,
7164                 .input_mux = &alc883_lenovo_nb0763_capture_source,
7165                 .unsol_event = alc883_medion_md2_unsol_event,
7166                 .init_hook = alc883_medion_md2_automute,
7167         },
7168         [ALC888_LENOVO_MS7195_DIG] = {
7169                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
7170                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
7171                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7172                 .dac_nids = alc883_dac_nids,
7173                 .dig_out_nid = ALC883_DIGOUT_NID,
7174                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7175                 .adc_nids = alc883_adc_nids,
7176                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7177                 .channel_mode = alc883_3ST_6ch_modes,
7178                 .need_dac_fix = 1,
7179                 .input_mux = &alc883_capture_source,
7180                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
7181                 .init_hook = alc888_lenovo_ms7195_front_automute,
7182         },
7183         [ALC883_HAIER_W66] = {
7184                 .mixers = { alc883_tagra_2ch_mixer},
7185                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
7186                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7187                 .dac_nids = alc883_dac_nids,
7188                 .dig_out_nid = ALC883_DIGOUT_NID,
7189                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7190                 .adc_nids = alc883_adc_nids,
7191                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7192                 .channel_mode = alc883_3ST_2ch_modes,
7193                 .input_mux = &alc883_capture_source,
7194                 .unsol_event = alc883_haier_w66_unsol_event,
7195                 .init_hook = alc883_haier_w66_automute,
7196         },      
7197         [ALC888_6ST_HP] = {
7198                 .mixers = { alc888_6st_hp_mixer, alc883_chmode_mixer },
7199                 .init_verbs = { alc883_init_verbs, alc888_6st_hp_verbs },
7200                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7201                 .dac_nids = alc883_dac_nids,
7202                 .dig_out_nid = ALC883_DIGOUT_NID,
7203                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7204                 .adc_nids = alc883_adc_nids,
7205                 .dig_in_nid = ALC883_DIGIN_NID,
7206                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7207                 .channel_mode = alc883_sixstack_modes,
7208                 .input_mux = &alc883_capture_source,
7209         },
7210         [ALC888_3ST_HP] = {
7211                 .mixers = { alc888_3st_hp_mixer, alc883_chmode_mixer },
7212                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
7213                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7214                 .dac_nids = alc883_dac_nids,
7215                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7216                 .adc_nids = alc883_adc_nids,
7217                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
7218                 .channel_mode = alc888_3st_hp_modes,
7219                 .need_dac_fix = 1,
7220                 .input_mux = &alc883_capture_source,
7221         },
7222 };
7223
7224
7225 /*
7226  * BIOS auto configuration
7227  */
7228 static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
7229                                               hda_nid_t nid, int pin_type,
7230                                               int dac_idx)
7231 {
7232         /* set as output */
7233         struct alc_spec *spec = codec->spec;
7234         int idx;
7235
7236         if (spec->multiout.dac_nids[dac_idx] == 0x25)
7237                 idx = 4;
7238         else
7239                 idx = spec->multiout.dac_nids[dac_idx] - 2;
7240
7241         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
7242                             pin_type);
7243         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
7244                             AMP_OUT_UNMUTE);
7245         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
7246
7247 }
7248
7249 static void alc883_auto_init_multi_out(struct hda_codec *codec)
7250 {
7251         struct alc_spec *spec = codec->spec;
7252         int i;
7253
7254         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
7255         for (i = 0; i <= HDA_SIDE; i++) {
7256                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
7257                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
7258                 if (nid)
7259                         alc883_auto_set_output_and_unmute(codec, nid, pin_type,
7260                                                           i);
7261         }
7262 }
7263
7264 static void alc883_auto_init_hp_out(struct hda_codec *codec)
7265 {
7266         struct alc_spec *spec = codec->spec;
7267         hda_nid_t pin;
7268
7269         pin = spec->autocfg.hp_pins[0];
7270         if (pin) /* connect to front */
7271                 /* use dac 0 */
7272                 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
7273 }
7274
7275 #define alc883_is_input_pin(nid)        alc880_is_input_pin(nid)
7276 #define ALC883_PIN_CD_NID               ALC880_PIN_CD_NID
7277
7278 static void alc883_auto_init_analog_input(struct hda_codec *codec)
7279 {
7280         struct alc_spec *spec = codec->spec;
7281         int i;
7282
7283         for (i = 0; i < AUTO_PIN_LAST; i++) {
7284                 hda_nid_t nid = spec->autocfg.input_pins[i];
7285                 if (alc883_is_input_pin(nid)) {
7286                         snd_hda_codec_write(codec, nid, 0,
7287                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
7288                                             (i <= AUTO_PIN_FRONT_MIC ?
7289                                              PIN_VREF80 : PIN_IN));
7290                         if (nid != ALC883_PIN_CD_NID)
7291                                 snd_hda_codec_write(codec, nid, 0,
7292                                                     AC_VERB_SET_AMP_GAIN_MUTE,
7293                                                     AMP_OUT_MUTE);
7294                 }
7295         }
7296 }
7297
7298 /* almost identical with ALC880 parser... */
7299 static int alc883_parse_auto_config(struct hda_codec *codec)
7300 {
7301         struct alc_spec *spec = codec->spec;
7302         int err = alc880_parse_auto_config(codec);
7303
7304         if (err < 0)
7305                 return err;
7306         else if (!err)
7307                 return 0; /* no config found */
7308
7309         err = alc_auto_add_mic_boost(codec);
7310         if (err < 0)
7311                 return err;
7312
7313         /* hack - override the init verbs */
7314         spec->init_verbs[0] = alc883_auto_init_verbs;
7315         spec->mixers[spec->num_mixers] = alc883_capture_mixer;
7316         spec->num_mixers++;
7317
7318         return 1; /* config found */
7319 }
7320
7321 /* additional initialization for auto-configuration model */
7322 static void alc883_auto_init(struct hda_codec *codec)
7323 {
7324         alc883_auto_init_multi_out(codec);
7325         alc883_auto_init_hp_out(codec);
7326         alc883_auto_init_analog_input(codec);
7327 }
7328
7329 static int patch_alc883(struct hda_codec *codec)
7330 {
7331         struct alc_spec *spec;
7332         int err, board_config;
7333
7334         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
7335         if (spec == NULL)
7336                 return -ENOMEM;
7337
7338         codec->spec = spec;
7339
7340         board_config = snd_hda_check_board_config(codec, ALC883_MODEL_LAST,
7341                                                   alc883_models,
7342                                                   alc883_cfg_tbl);
7343         if (board_config < 0) {
7344                 printk(KERN_INFO "hda_codec: Unknown model for ALC883, "
7345                        "trying auto-probe from BIOS...\n");
7346                 board_config = ALC883_AUTO;
7347         }
7348
7349         if (board_config == ALC883_AUTO) {
7350                 /* automatic parse from the BIOS config */
7351                 err = alc883_parse_auto_config(codec);
7352                 if (err < 0) {
7353                         alc_free(codec);
7354                         return err;
7355                 } else if (!err) {
7356                         printk(KERN_INFO
7357                                "hda_codec: Cannot set up configuration "
7358                                "from BIOS.  Using base mode...\n");
7359                         board_config = ALC883_3ST_2ch_DIG;
7360                 }
7361         }
7362
7363         if (board_config != ALC883_AUTO)
7364                 setup_preset(spec, &alc883_presets[board_config]);
7365
7366         spec->stream_name_analog = "ALC883 Analog";
7367         spec->stream_analog_playback = &alc883_pcm_analog_playback;
7368         spec->stream_analog_capture = &alc883_pcm_analog_capture;
7369
7370         spec->stream_name_digital = "ALC883 Digital";
7371         spec->stream_digital_playback = &alc883_pcm_digital_playback;
7372         spec->stream_digital_capture = &alc883_pcm_digital_capture;
7373
7374         if (!spec->adc_nids && spec->input_mux) {
7375                 spec->adc_nids = alc883_adc_nids;
7376                 spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
7377         }
7378
7379         codec->patch_ops = alc_patch_ops;
7380         if (board_config == ALC883_AUTO)
7381                 spec->init_hook = alc883_auto_init;
7382 #ifdef CONFIG_SND_HDA_POWER_SAVE
7383         if (!spec->loopback.amplist)
7384                 spec->loopback.amplist = alc883_loopbacks;
7385 #endif
7386
7387         return 0;
7388 }
7389
7390 /*
7391  * ALC262 support
7392  */
7393
7394 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
7395 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
7396
7397 #define alc262_dac_nids         alc260_dac_nids
7398 #define alc262_adc_nids         alc882_adc_nids
7399 #define alc262_adc_nids_alt     alc882_adc_nids_alt
7400
7401 #define alc262_modes            alc260_modes
7402 #define alc262_capture_source   alc882_capture_source
7403
7404 static struct snd_kcontrol_new alc262_base_mixer[] = {
7405         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7406         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7407         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7408         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7409         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7410         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7411         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7412         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7413         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7414         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
7415         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
7416         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7417         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
7418            HDA_CODEC_MUTE("PC Beelp Playback Switch", 0x0b, 0x05, HDA_INPUT), */
7419         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
7420         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7421         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7422         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
7423         { } /* end */
7424 };
7425
7426 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
7427         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7428         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7429         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7430         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7431         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7432         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7433         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7434         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7435         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7436         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
7437         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
7438         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7439         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
7440            HDA_CODEC_MUTE("PC Beelp Playback Switch", 0x0b, 0x05, HDA_INPUT), */
7441         /*HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),*/
7442         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7443         { } /* end */
7444 };
7445
7446 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
7447         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7448         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7449         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7450         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7451         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
7452
7453         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7454         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7455         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7456         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
7457         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
7458         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7459         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7460         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7461         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7462         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7463         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
7464         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
7465         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
7466         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
7467         { } /* end */
7468 };
7469
7470 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
7471         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7472         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7473         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7474         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7475         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7476         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
7477         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
7478         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
7479         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
7480         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
7481         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
7482         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7483         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7484         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
7485         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
7486         { } /* end */
7487 };
7488
7489 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
7490         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7491         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7492         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
7493         { } /* end */
7494 };
7495
7496 /* bind hp and internal speaker mute (with plug check) */
7497 static int alc262_sony_master_sw_put(struct snd_kcontrol *kcontrol,
7498                                      struct snd_ctl_elem_value *ucontrol)
7499 {
7500         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
7501         long *valp = ucontrol->value.integer.value;
7502         int change;
7503
7504         /* change hp mute */
7505         change = snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
7506                                           HDA_AMP_MUTE,
7507                                           valp[0] ? 0 : HDA_AMP_MUTE);
7508         change |= snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
7509                                            HDA_AMP_MUTE,
7510                                            valp[1] ? 0 : HDA_AMP_MUTE);
7511         if (change) {
7512                 /* change speaker according to HP jack state */
7513                 struct alc_spec *spec = codec->spec;
7514                 unsigned int mute;
7515                 if (spec->jack_present)
7516                         mute = HDA_AMP_MUTE;
7517                 else
7518                         mute = snd_hda_codec_amp_read(codec, 0x15, 0,
7519                                                       HDA_OUTPUT, 0);
7520                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7521                                          HDA_AMP_MUTE, mute);
7522         }
7523         return change;
7524 }
7525
7526 static struct snd_kcontrol_new alc262_sony_mixer[] = {
7527         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7528         {
7529                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7530                 .name = "Master Playback Switch",
7531                 .info = snd_hda_mixer_amp_switch_info,
7532                 .get = snd_hda_mixer_amp_switch_get,
7533                 .put = alc262_sony_master_sw_put,
7534                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
7535         },
7536         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7537         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7538         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
7539         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
7540         { } /* end */
7541 };
7542
7543 static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
7544         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7545         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7546         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7547         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7548         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7549         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
7550         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
7551         { } /* end */
7552 };
7553
7554 #define alc262_capture_mixer            alc882_capture_mixer
7555 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
7556
7557 /*
7558  * generic initialization of ADC, input mixers and output mixers
7559  */
7560 static struct hda_verb alc262_init_verbs[] = {
7561         /*
7562          * Unmute ADC0-2 and set the default input to mic-in
7563          */
7564         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
7565         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7566         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7567         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7568         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7569         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7570
7571         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
7572          * mixer widget
7573          * Note: PASD motherboards uses the Line In 2 as the input for
7574          * front panel mic (mic 2)
7575          */
7576         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
7577         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7578         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7579         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7580         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7581         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7582
7583         /*
7584          * Set up output mixers (0x0c - 0x0e)
7585          */
7586         /* set vol=0 to output mixers */
7587         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7588         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7589         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7590         /* set up input amps for analog loopback */
7591         /* Amp Indices: DAC = 0, mixer = 1 */
7592         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7593         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7594         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7595         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7596         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7597         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7598
7599         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
7600         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
7601         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
7602         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
7603         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
7604         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
7605
7606         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
7607         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
7608         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
7609         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
7610         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
7611         
7612         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7613         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7614         
7615         /* FIXME: use matrix-type input source selection */
7616         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7617         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
7618         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7619         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7620         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7621         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7622         /* Input mixer2 */
7623         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7624         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7625         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7626         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7627         /* Input mixer3 */
7628         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7629         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7630         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7631         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7632
7633         { }
7634 };
7635
7636 static struct hda_verb alc262_hippo_unsol_verbs[] = {
7637         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
7638         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7639         {}
7640 };
7641
7642 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
7643         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
7644         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7645         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
7646
7647         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
7648         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7649         {}
7650 };
7651
7652 static struct hda_verb alc262_sony_unsol_verbs[] = {
7653         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
7654         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7655         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
7656
7657         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
7658         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7659 };
7660
7661 /* mute/unmute internal speaker according to the hp jack and mute state */
7662 static void alc262_hippo_automute(struct hda_codec *codec)
7663 {
7664         struct alc_spec *spec = codec->spec;
7665         unsigned int mute;
7666         unsigned int present;
7667
7668         /* need to execute and sync at first */
7669         snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
7670         present = snd_hda_codec_read(codec, 0x15, 0,
7671                                      AC_VERB_GET_PIN_SENSE, 0);
7672         spec->jack_present = (present & 0x80000000) != 0;
7673         if (spec->jack_present) {
7674                 /* mute internal speaker */
7675                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7676                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
7677         } else {
7678                 /* unmute internal speaker if necessary */
7679                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
7680                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7681                                          HDA_AMP_MUTE, mute);
7682         }
7683 }
7684
7685 /* unsolicited event for HP jack sensing */
7686 static void alc262_hippo_unsol_event(struct hda_codec *codec,
7687                                        unsigned int res)
7688 {
7689         if ((res >> 26) != ALC880_HP_EVENT)
7690                 return;
7691         alc262_hippo_automute(codec);
7692 }
7693
7694 static void alc262_hippo1_automute(struct hda_codec *codec)
7695 {
7696         unsigned int mute;
7697         unsigned int present;
7698
7699         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
7700         present = snd_hda_codec_read(codec, 0x1b, 0,
7701                                      AC_VERB_GET_PIN_SENSE, 0);
7702         present = (present & 0x80000000) != 0;
7703         if (present) {
7704                 /* mute internal speaker */
7705                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7706                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
7707         } else {
7708                 /* unmute internal speaker if necessary */
7709                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
7710                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7711                                          HDA_AMP_MUTE, mute);
7712         }
7713 }
7714
7715 /* unsolicited event for HP jack sensing */
7716 static void alc262_hippo1_unsol_event(struct hda_codec *codec,
7717                                        unsigned int res)
7718 {
7719         if ((res >> 26) != ALC880_HP_EVENT)
7720                 return;
7721         alc262_hippo1_automute(codec);
7722 }
7723
7724 /*
7725  * fujitsu model
7726  *  0x14 = headphone/spdif-out, 0x15 = internal speaker
7727  */
7728
7729 #define ALC_HP_EVENT    0x37
7730
7731 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
7732         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
7733         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7734         {}
7735 };
7736
7737 static struct hda_input_mux alc262_fujitsu_capture_source = {
7738         .num_items = 2,
7739         .items = {
7740                 { "Mic", 0x0 },
7741                 { "CD", 0x4 },
7742         },
7743 };
7744
7745 static struct hda_input_mux alc262_HP_capture_source = {
7746         .num_items = 5,
7747         .items = {
7748                 { "Mic", 0x0 },
7749                 { "Front Mic", 0x1 },
7750                 { "Line", 0x2 },
7751                 { "CD", 0x4 },
7752                 { "AUX IN", 0x6 },
7753         },
7754 };
7755
7756 static struct hda_input_mux alc262_HP_D7000_capture_source = {
7757         .num_items = 4,
7758         .items = {
7759                 { "Mic", 0x0 },
7760                 { "Front Mic", 0x2 },
7761                 { "Line", 0x1 },
7762                 { "CD", 0x4 },
7763         },
7764 };
7765
7766 /* mute/unmute internal speaker according to the hp jack and mute state */
7767 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
7768 {
7769         struct alc_spec *spec = codec->spec;
7770         unsigned int mute;
7771
7772         if (force || !spec->sense_updated) {
7773                 unsigned int present;
7774                 /* need to execute and sync at first */
7775                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
7776                 present = snd_hda_codec_read(codec, 0x14, 0,
7777                                          AC_VERB_GET_PIN_SENSE, 0);
7778                 spec->jack_present = (present & 0x80000000) != 0;
7779                 spec->sense_updated = 1;
7780         }
7781         if (spec->jack_present) {
7782                 /* mute internal speaker */
7783                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7784                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
7785         } else {
7786                 /* unmute internal speaker if necessary */
7787                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
7788                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7789                                          HDA_AMP_MUTE, mute);
7790         }
7791 }
7792
7793 /* unsolicited event for HP jack sensing */
7794 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
7795                                        unsigned int res)
7796 {
7797         if ((res >> 26) != ALC_HP_EVENT)
7798                 return;
7799         alc262_fujitsu_automute(codec, 1);
7800 }
7801
7802 /* bind volumes of both NID 0x0c and 0x0d */
7803 static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
7804         .ops = &snd_hda_bind_vol,
7805         .values = {
7806                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
7807                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
7808                 0
7809         },
7810 };
7811
7812 /* bind hp and internal speaker mute (with plug check) */
7813 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
7814                                          struct snd_ctl_elem_value *ucontrol)
7815 {
7816         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
7817         long *valp = ucontrol->value.integer.value;
7818         int change;
7819
7820         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
7821                                           HDA_AMP_MUTE,
7822                                           valp[0] ? 0 : HDA_AMP_MUTE);
7823         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
7824                                            HDA_AMP_MUTE,
7825                                            valp[1] ? 0 : HDA_AMP_MUTE);
7826         if (change)
7827                 alc262_fujitsu_automute(codec, 0);
7828         return change;
7829 }
7830
7831 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
7832         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
7833         {
7834                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7835                 .name = "Master Playback Switch",
7836                 .info = snd_hda_mixer_amp_switch_info,
7837                 .get = snd_hda_mixer_amp_switch_get,
7838                 .put = alc262_fujitsu_master_sw_put,
7839                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
7840         },
7841         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7842         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7843         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7844         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7845         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7846         { } /* end */
7847 };
7848
7849 /* additional init verbs for Benq laptops */
7850 static struct hda_verb alc262_EAPD_verbs[] = {
7851         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7852         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
7853         {}
7854 };
7855
7856 static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
7857         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7858         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
7859
7860         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7861         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
7862         {}
7863 };
7864
7865 /* add playback controls from the parsed DAC table */
7866 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
7867                                              const struct auto_pin_cfg *cfg)
7868 {
7869         hda_nid_t nid;
7870         int err;
7871
7872         spec->multiout.num_dacs = 1;    /* only use one dac */
7873         spec->multiout.dac_nids = spec->private_dac_nids;
7874         spec->multiout.dac_nids[0] = 2;
7875
7876         nid = cfg->line_out_pins[0];
7877         if (nid) {
7878                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
7879                                   "Front Playback Volume",
7880                                   HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT));
7881                 if (err < 0)
7882                         return err;
7883                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
7884                                   "Front Playback Switch",
7885                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
7886                 if (err < 0)
7887                         return err;
7888         }
7889
7890         nid = cfg->speaker_pins[0];
7891         if (nid) {
7892                 if (nid == 0x16) {
7893                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
7894                                           "Speaker Playback Volume",
7895                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
7896                                                               HDA_OUTPUT));
7897                         if (err < 0)
7898                                 return err;
7899                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
7900                                           "Speaker Playback Switch",
7901                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
7902                                                               HDA_OUTPUT));
7903                         if (err < 0)
7904                                 return err;
7905                 } else {
7906                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
7907                                           "Speaker Playback Switch",
7908                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
7909                                                               HDA_OUTPUT));
7910                         if (err < 0)
7911                                 return err;
7912                 }
7913         }
7914         nid = cfg->hp_pins[0];
7915         if (nid) {
7916                 /* spec->multiout.hp_nid = 2; */
7917                 if (nid == 0x16) {
7918                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
7919                                           "Headphone Playback Volume",
7920                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
7921                                                               HDA_OUTPUT));
7922                         if (err < 0)
7923                                 return err;
7924                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
7925                                           "Headphone Playback Switch",
7926                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
7927                                                               HDA_OUTPUT));
7928                         if (err < 0)
7929                                 return err;
7930                 } else {
7931                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
7932                                           "Headphone Playback Switch",
7933                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
7934                                                               HDA_OUTPUT));
7935                         if (err < 0)
7936                                 return err;
7937                 }
7938         }
7939         return 0;
7940 }
7941
7942 /* identical with ALC880 */
7943 #define alc262_auto_create_analog_input_ctls \
7944         alc880_auto_create_analog_input_ctls
7945
7946 /*
7947  * generic initialization of ADC, input mixers and output mixers
7948  */
7949 static struct hda_verb alc262_volume_init_verbs[] = {
7950         /*
7951          * Unmute ADC0-2 and set the default input to mic-in
7952          */
7953         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
7954         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7955         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7956         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7957         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7958         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7959
7960         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
7961          * mixer widget
7962          * Note: PASD motherboards uses the Line In 2 as the input for
7963          * front panel mic (mic 2)
7964          */
7965         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
7966         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7967         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7968         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7969         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7970         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7971
7972         /*
7973          * Set up output mixers (0x0c - 0x0f)
7974          */
7975         /* set vol=0 to output mixers */
7976         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7977         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7978         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7979         
7980         /* set up input amps for analog loopback */
7981         /* Amp Indices: DAC = 0, mixer = 1 */
7982         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7983         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7984         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7985         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7986         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7987         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7988
7989         /* FIXME: use matrix-type input source selection */
7990         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7991         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
7992         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7993         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7994         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7995         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7996         /* Input mixer2 */
7997         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7998         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7999         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8000         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8001         /* Input mixer3 */
8002         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8003         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8004         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8005         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8006
8007         { }
8008 };
8009
8010 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
8011         /*
8012          * Unmute ADC0-2 and set the default input to mic-in
8013          */
8014         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
8015         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8016         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8017         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8018         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8019         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8020
8021         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8022          * mixer widget
8023          * Note: PASD motherboards uses the Line In 2 as the input for
8024          * front panel mic (mic 2)
8025          */
8026         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8027         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8028         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8029         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8030         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8031         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8032         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
8033         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
8034         
8035         /*
8036          * Set up output mixers (0x0c - 0x0e)
8037          */
8038         /* set vol=0 to output mixers */
8039         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8040         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8041         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8042
8043         /* set up input amps for analog loopback */
8044         /* Amp Indices: DAC = 0, mixer = 1 */
8045         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8046         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8047         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8048         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8049         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8050         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8051
8052         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8053         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8054         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8055
8056         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8057         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8058
8059         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8060         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8061
8062         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8063         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8064         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8065         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8066         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8067
8068         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
8069         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8070         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8071         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
8072         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8073         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8074
8075
8076         /* FIXME: use matrix-type input source selection */
8077         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8078         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
8079         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8080         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
8081         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
8082         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
8083         /* Input mixer2 */
8084         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8085         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
8086         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
8087         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
8088         /* Input mixer3 */
8089         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8090         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
8091         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
8092         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
8093
8094         { }
8095 };
8096
8097 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
8098         /*
8099          * Unmute ADC0-2 and set the default input to mic-in
8100          */
8101         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
8102         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8103         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8104         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8105         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8106         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8107
8108         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8109          * mixer widget
8110          * Note: PASD motherboards uses the Line In 2 as the input for front
8111          * panel mic (mic 2)
8112          */
8113         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8114         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8115         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8116         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8117         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8118         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8119         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
8120         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
8121         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
8122         /*
8123          * Set up output mixers (0x0c - 0x0e)
8124          */
8125         /* set vol=0 to output mixers */
8126         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8127         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8128         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8129
8130         /* set up input amps for analog loopback */
8131         /* Amp Indices: DAC = 0, mixer = 1 */
8132         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8133         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8134         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8135         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8136         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8137         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8138
8139
8140         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
8141         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
8142         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
8143         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
8144         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
8145         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
8146         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
8147
8148         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8149         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8150
8151         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8152         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
8153
8154         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
8155         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8156         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8157         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
8158         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8159         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8160
8161         /* FIXME: use matrix-type input source selection */
8162         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8163         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
8164         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
8165         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
8166         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
8167         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
8168         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
8169         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
8170         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
8171         /* Input mixer2 */
8172         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8173         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8174         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
8175         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
8176         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
8177         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
8178         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
8179         /* Input mixer3 */
8180         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8181         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8182         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
8183         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
8184         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
8185         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
8186         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
8187
8188         { }
8189 };
8190
8191 #ifdef CONFIG_SND_HDA_POWER_SAVE
8192 #define alc262_loopbacks        alc880_loopbacks
8193 #endif
8194
8195 /* pcm configuration: identiacal with ALC880 */
8196 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
8197 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
8198 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
8199 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
8200
8201 /*
8202  * BIOS auto configuration
8203  */
8204 static int alc262_parse_auto_config(struct hda_codec *codec)
8205 {
8206         struct alc_spec *spec = codec->spec;
8207         int err;
8208         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
8209
8210         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
8211                                            alc262_ignore);
8212         if (err < 0)
8213                 return err;
8214         if (!spec->autocfg.line_outs)
8215                 return 0; /* can't find valid BIOS pin config */
8216         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
8217         if (err < 0)
8218                 return err;
8219         err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg);
8220         if (err < 0)
8221                 return err;
8222
8223         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
8224
8225         if (spec->autocfg.dig_out_pin)
8226                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
8227         if (spec->autocfg.dig_in_pin)
8228                 spec->dig_in_nid = ALC262_DIGIN_NID;
8229
8230         if (spec->kctl_alloc)
8231                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
8232
8233         spec->init_verbs[spec->num_init_verbs++] = alc262_volume_init_verbs;
8234         spec->num_mux_defs = 1;
8235         spec->input_mux = &spec->private_imux;
8236
8237         err = alc_auto_add_mic_boost(codec);
8238         if (err < 0)
8239                 return err;
8240
8241         return 1;
8242 }
8243
8244 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
8245 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
8246 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
8247
8248
8249 /* init callback for auto-configuration model -- overriding the default init */
8250 static void alc262_auto_init(struct hda_codec *codec)
8251 {
8252         alc262_auto_init_multi_out(codec);
8253         alc262_auto_init_hp_out(codec);
8254         alc262_auto_init_analog_input(codec);
8255 }
8256
8257 /*
8258  * configuration and preset
8259  */
8260 static const char *alc262_models[ALC262_MODEL_LAST] = {
8261         [ALC262_BASIC]          = "basic",
8262         [ALC262_HIPPO]          = "hippo",
8263         [ALC262_HIPPO_1]        = "hippo_1",
8264         [ALC262_FUJITSU]        = "fujitsu",
8265         [ALC262_HP_BPC]         = "hp-bpc",
8266         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
8267         [ALC262_BENQ_ED8]       = "benq",
8268         [ALC262_BENQ_T31]       = "benq-t31",
8269         [ALC262_SONY_ASSAMD]    = "sony-assamd",
8270         [ALC262_AUTO]           = "auto",
8271 };
8272
8273 static struct snd_pci_quirk alc262_cfg_tbl[] = {
8274         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
8275         SND_PCI_QUIRK(0x103c, 0x12fe, "HP xw9400", ALC262_HP_BPC),
8276         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
8277         SND_PCI_QUIRK(0x103c, 0x12ff, "HP xw4550", ALC262_HP_BPC),
8278         SND_PCI_QUIRK(0x103c, 0x1308, "HP xw4600", ALC262_HP_BPC),
8279         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
8280         SND_PCI_QUIRK(0x103c, 0x1307, "HP xw6600", ALC262_HP_BPC),
8281         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
8282         SND_PCI_QUIRK(0x103c, 0x1306, "HP xw8600", ALC262_HP_BPC),
8283         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
8284         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
8285         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
8286         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
8287         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
8288         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
8289         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
8290         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
8291         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
8292         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
8293         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
8294         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
8295         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
8296         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
8297         SND_PCI_QUIRK(0x104d, 0x9015, "Sony 0x9015", ALC262_SONY_ASSAMD),
8298         SND_PCI_QUIRK(0x104d, 0x900e, "Sony ASSAMD", ALC262_SONY_ASSAMD),
8299         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
8300         {}
8301 };
8302
8303 static struct alc_config_preset alc262_presets[] = {
8304         [ALC262_BASIC] = {
8305                 .mixers = { alc262_base_mixer },
8306                 .init_verbs = { alc262_init_verbs },
8307                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8308                 .dac_nids = alc262_dac_nids,
8309                 .hp_nid = 0x03,
8310                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8311                 .channel_mode = alc262_modes,
8312                 .input_mux = &alc262_capture_source,
8313         },
8314         [ALC262_HIPPO] = {
8315                 .mixers = { alc262_base_mixer },
8316                 .init_verbs = { alc262_init_verbs, alc262_hippo_unsol_verbs},
8317                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8318                 .dac_nids = alc262_dac_nids,
8319                 .hp_nid = 0x03,
8320                 .dig_out_nid = ALC262_DIGOUT_NID,
8321                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8322                 .channel_mode = alc262_modes,
8323                 .input_mux = &alc262_capture_source,
8324                 .unsol_event = alc262_hippo_unsol_event,
8325                 .init_hook = alc262_hippo_automute,
8326         },
8327         [ALC262_HIPPO_1] = {
8328                 .mixers = { alc262_hippo1_mixer },
8329                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
8330                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8331                 .dac_nids = alc262_dac_nids,
8332                 .hp_nid = 0x02,
8333                 .dig_out_nid = ALC262_DIGOUT_NID,
8334                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8335                 .channel_mode = alc262_modes,
8336                 .input_mux = &alc262_capture_source,
8337                 .unsol_event = alc262_hippo1_unsol_event,
8338                 .init_hook = alc262_hippo1_automute,
8339         },
8340         [ALC262_FUJITSU] = {
8341                 .mixers = { alc262_fujitsu_mixer },
8342                 .init_verbs = { alc262_init_verbs, alc262_fujitsu_unsol_verbs },
8343                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8344                 .dac_nids = alc262_dac_nids,
8345                 .hp_nid = 0x03,
8346                 .dig_out_nid = ALC262_DIGOUT_NID,
8347                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8348                 .channel_mode = alc262_modes,
8349                 .input_mux = &alc262_fujitsu_capture_source,
8350                 .unsol_event = alc262_fujitsu_unsol_event,
8351         },
8352         [ALC262_HP_BPC] = {
8353                 .mixers = { alc262_HP_BPC_mixer },
8354                 .init_verbs = { alc262_HP_BPC_init_verbs },
8355                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8356                 .dac_nids = alc262_dac_nids,
8357                 .hp_nid = 0x03,
8358                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8359                 .channel_mode = alc262_modes,
8360                 .input_mux = &alc262_HP_capture_source,
8361         },
8362         [ALC262_HP_BPC_D7000_WF] = {
8363                 .mixers = { alc262_HP_BPC_WildWest_mixer },
8364                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
8365                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8366                 .dac_nids = alc262_dac_nids,
8367                 .hp_nid = 0x03,
8368                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8369                 .channel_mode = alc262_modes,
8370                 .input_mux = &alc262_HP_D7000_capture_source,
8371         },
8372         [ALC262_HP_BPC_D7000_WL] = {
8373                 .mixers = { alc262_HP_BPC_WildWest_mixer,
8374                             alc262_HP_BPC_WildWest_option_mixer },
8375                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
8376                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8377                 .dac_nids = alc262_dac_nids,
8378                 .hp_nid = 0x03,
8379                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8380                 .channel_mode = alc262_modes,
8381                 .input_mux = &alc262_HP_D7000_capture_source,
8382         },
8383         [ALC262_BENQ_ED8] = {
8384                 .mixers = { alc262_base_mixer },
8385                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
8386                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8387                 .dac_nids = alc262_dac_nids,
8388                 .hp_nid = 0x03,
8389                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8390                 .channel_mode = alc262_modes,
8391                 .input_mux = &alc262_capture_source,
8392         },
8393         [ALC262_SONY_ASSAMD] = {
8394                 .mixers = { alc262_sony_mixer },
8395                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
8396                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8397                 .dac_nids = alc262_dac_nids,
8398                 .hp_nid = 0x02,
8399                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8400                 .channel_mode = alc262_modes,
8401                 .input_mux = &alc262_capture_source,
8402                 .unsol_event = alc262_hippo_unsol_event,
8403                 .init_hook = alc262_hippo_automute,
8404         },
8405         [ALC262_BENQ_T31] = {
8406                 .mixers = { alc262_benq_t31_mixer },
8407                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs, alc262_hippo_unsol_verbs },
8408                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8409                 .dac_nids = alc262_dac_nids,
8410                 .hp_nid = 0x03,
8411                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8412                 .channel_mode = alc262_modes,
8413                 .input_mux = &alc262_capture_source,
8414                 .unsol_event = alc262_hippo_unsol_event,
8415                 .init_hook = alc262_hippo_automute,
8416         },      
8417 };
8418
8419 static int patch_alc262(struct hda_codec *codec)
8420 {
8421         struct alc_spec *spec;
8422         int board_config;
8423         int err;
8424
8425         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
8426         if (spec == NULL)
8427                 return -ENOMEM;
8428
8429         codec->spec = spec;
8430 #if 0
8431         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
8432          * under-run
8433          */
8434         {
8435         int tmp;
8436         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
8437         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
8438         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
8439         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
8440         }
8441 #endif
8442
8443         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
8444                                                   alc262_models,
8445                                                   alc262_cfg_tbl);
8446
8447         if (board_config < 0) {
8448                 printk(KERN_INFO "hda_codec: Unknown model for ALC262, "
8449                        "trying auto-probe from BIOS...\n");
8450                 board_config = ALC262_AUTO;
8451         }
8452
8453         if (board_config == ALC262_AUTO) {
8454                 /* automatic parse from the BIOS config */
8455                 err = alc262_parse_auto_config(codec);
8456                 if (err < 0) {
8457                         alc_free(codec);
8458                         return err;
8459                 } else if (!err) {
8460                         printk(KERN_INFO
8461                                "hda_codec: Cannot set up configuration "
8462                                "from BIOS.  Using base mode...\n");
8463                         board_config = ALC262_BASIC;
8464                 }
8465         }
8466
8467         if (board_config != ALC262_AUTO)
8468                 setup_preset(spec, &alc262_presets[board_config]);
8469
8470         spec->stream_name_analog = "ALC262 Analog";
8471         spec->stream_analog_playback = &alc262_pcm_analog_playback;
8472         spec->stream_analog_capture = &alc262_pcm_analog_capture;
8473                 
8474         spec->stream_name_digital = "ALC262 Digital";
8475         spec->stream_digital_playback = &alc262_pcm_digital_playback;
8476         spec->stream_digital_capture = &alc262_pcm_digital_capture;
8477
8478         if (!spec->adc_nids && spec->input_mux) {
8479                 /* check whether NID 0x07 is valid */
8480                 unsigned int wcap = get_wcaps(codec, 0x07);
8481
8482                 /* get type */
8483                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
8484                 if (wcap != AC_WID_AUD_IN) {
8485                         spec->adc_nids = alc262_adc_nids_alt;
8486                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
8487                         spec->mixers[spec->num_mixers] =
8488                                 alc262_capture_alt_mixer;
8489                         spec->num_mixers++;
8490                 } else {
8491                         spec->adc_nids = alc262_adc_nids;
8492                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
8493                         spec->mixers[spec->num_mixers] = alc262_capture_mixer;
8494                         spec->num_mixers++;
8495                 }
8496         }
8497
8498         codec->patch_ops = alc_patch_ops;
8499         if (board_config == ALC262_AUTO)
8500                 spec->init_hook = alc262_auto_init;
8501 #ifdef CONFIG_SND_HDA_POWER_SAVE
8502         if (!spec->loopback.amplist)
8503                 spec->loopback.amplist = alc262_loopbacks;
8504 #endif
8505                 
8506         return 0;
8507 }
8508
8509 /*
8510  *  ALC268 channel source setting (2 channel)
8511  */
8512 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
8513 #define alc268_modes            alc260_modes
8514         
8515 static hda_nid_t alc268_dac_nids[2] = {
8516         /* front, hp */
8517         0x02, 0x03
8518 };
8519
8520 static hda_nid_t alc268_adc_nids[2] = {
8521         /* ADC0-1 */
8522         0x08, 0x07
8523 };
8524
8525 static hda_nid_t alc268_adc_nids_alt[1] = {
8526         /* ADC0 */
8527         0x08
8528 };
8529
8530 static struct snd_kcontrol_new alc268_base_mixer[] = {
8531         /* output mixer control */
8532         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
8533         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8534         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
8535         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8536         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8537         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8538         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
8539         { }
8540 };
8541
8542 static struct hda_verb alc268_eapd_verbs[] = {
8543         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
8544         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
8545         { }
8546 };
8547
8548 /* Toshiba specific */
8549 #define alc268_toshiba_automute alc262_hippo_automute
8550
8551 static struct hda_verb alc268_toshiba_verbs[] = {
8552         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8553         { } /* end */
8554 };
8555
8556 /* Acer specific */
8557 /* bind volumes of both NID 0x02 and 0x03 */
8558 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
8559         .ops = &snd_hda_bind_vol,
8560         .values = {
8561                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
8562                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
8563                 0
8564         },
8565 };
8566
8567 /* mute/unmute internal speaker according to the hp jack and mute state */
8568 static void alc268_acer_automute(struct hda_codec *codec, int force)
8569 {
8570         struct alc_spec *spec = codec->spec;
8571         unsigned int mute;
8572
8573         if (force || !spec->sense_updated) {
8574                 unsigned int present;
8575                 present = snd_hda_codec_read(codec, 0x14, 0,
8576                                          AC_VERB_GET_PIN_SENSE, 0);
8577                 spec->jack_present = (present & 0x80000000) != 0;
8578                 spec->sense_updated = 1;
8579         }
8580         if (spec->jack_present)
8581                 mute = HDA_AMP_MUTE; /* mute internal speaker */
8582         else /* unmute internal speaker if necessary */
8583                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
8584         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8585                                  HDA_AMP_MUTE, mute);
8586 }
8587
8588
8589 /* bind hp and internal speaker mute (with plug check) */
8590 static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
8591                                      struct snd_ctl_elem_value *ucontrol)
8592 {
8593         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8594         long *valp = ucontrol->value.integer.value;
8595         int change;
8596
8597         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
8598                                           HDA_AMP_MUTE,
8599                                           valp[0] ? 0 : HDA_AMP_MUTE);
8600         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
8601                                            HDA_AMP_MUTE,
8602                                            valp[1] ? 0 : HDA_AMP_MUTE);
8603         if (change)
8604                 alc268_acer_automute(codec, 0);
8605         return change;
8606 }
8607
8608 static struct snd_kcontrol_new alc268_acer_mixer[] = {
8609         /* output mixer control */
8610         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
8611         {
8612                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8613                 .name = "Master Playback Switch",
8614                 .info = snd_hda_mixer_amp_switch_info,
8615                 .get = snd_hda_mixer_amp_switch_get,
8616                 .put = alc268_acer_master_sw_put,
8617                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
8618         },
8619         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8620         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
8621         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
8622         { }
8623 };
8624
8625 static struct hda_verb alc268_acer_verbs[] = {
8626         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8627         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8628
8629         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8630         { }
8631 };
8632
8633 /* unsolicited event for HP jack sensing */
8634 static void alc268_toshiba_unsol_event(struct hda_codec *codec,
8635                                        unsigned int res)
8636 {
8637         if ((res >> 26) != ALC880_HP_EVENT)
8638                 return;
8639         alc268_toshiba_automute(codec);
8640 }
8641
8642 static void alc268_acer_unsol_event(struct hda_codec *codec,
8643                                        unsigned int res)
8644 {
8645         if ((res >> 26) != ALC880_HP_EVENT)
8646                 return;
8647         alc268_acer_automute(codec, 1);
8648 }
8649
8650 static void alc268_acer_init_hook(struct hda_codec *codec)
8651 {
8652         alc268_acer_automute(codec, 1);
8653 }
8654
8655 /*
8656  * generic initialization of ADC, input mixers and output mixers
8657  */
8658 static struct hda_verb alc268_base_init_verbs[] = {
8659         /* Unmute DAC0-1 and set vol = 0 */
8660         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8661         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8662         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8663         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8664         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8665         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8666
8667         /*
8668          * Set up output mixers (0x0c - 0x0e)
8669          */
8670         /* set vol=0 to output mixers */
8671         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8672         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8673         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8674         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
8675
8676         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8677         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8678
8679         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
8680         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8681         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
8682         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8683         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8684         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8685         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8686         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8687
8688         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8689         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8690         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8691         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8692         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8693         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8694         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8695         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8696
8697         /* FIXME: use matrix-type input source selection */
8698         /* Mixer elements: 0x18, 19, 1a, 1c, 14, 15, 0b */
8699         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
8700         /* Input mixer2 */
8701         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8702         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8703         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
8704         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
8705
8706         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8707         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8708         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
8709         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
8710         { }
8711 };
8712
8713 /*
8714  * generic initialization of ADC, input mixers and output mixers
8715  */
8716 static struct hda_verb alc268_volume_init_verbs[] = {
8717         /* set output DAC */
8718         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8719         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8720         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8721         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8722
8723         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8724         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8725         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8726         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8727         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8728
8729         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8730         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8731         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8732         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8733         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8734
8735         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8736         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8737         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8738         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8739
8740         /* set PCBEEP vol = 0 */
8741         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, (0xb000 | (0x00 << 8))},
8742
8743         { }
8744 };
8745
8746 #define alc268_mux_enum_info alc_mux_enum_info
8747 #define alc268_mux_enum_get alc_mux_enum_get
8748
8749 static int alc268_mux_enum_put(struct snd_kcontrol *kcontrol,
8750                                struct snd_ctl_elem_value *ucontrol)
8751 {
8752         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8753         struct alc_spec *spec = codec->spec;
8754         const struct hda_input_mux *imux = spec->input_mux;
8755         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
8756         static hda_nid_t capture_mixers[3] = { 0x23, 0x24 };
8757         hda_nid_t nid = capture_mixers[adc_idx];
8758         unsigned int *cur_val = &spec->cur_mux[adc_idx];
8759         unsigned int i, idx;
8760
8761         idx = ucontrol->value.enumerated.item[0];
8762         if (idx >= imux->num_items)
8763                 idx = imux->num_items - 1;
8764         if (*cur_val == idx)
8765                 return 0;
8766         for (i = 0; i < imux->num_items; i++) {
8767                 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
8768                 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
8769                                          imux->items[i].index,
8770                                          HDA_AMP_MUTE, v);
8771                 snd_hda_codec_write_cache(codec, nid, 0,
8772                                           AC_VERB_SET_CONNECT_SEL,
8773                                           idx );
8774         }
8775         *cur_val = idx;
8776         return 1;
8777 }
8778
8779 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
8780         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
8781         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
8782         {
8783                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8784                 /* The multiple "Capture Source" controls confuse alsamixer
8785                  * So call somewhat different..
8786                  * FIXME: the controls appear in the "playback" view!
8787                  */
8788                 /* .name = "Capture Source", */
8789                 .name = "Input Source",
8790                 .count = 1,
8791                 .info = alc268_mux_enum_info,
8792                 .get = alc268_mux_enum_get,
8793                 .put = alc268_mux_enum_put,
8794         },
8795         { } /* end */
8796 };
8797
8798 static struct snd_kcontrol_new alc268_capture_mixer[] = {
8799         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
8800         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
8801         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
8802         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
8803         {
8804                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8805                 /* The multiple "Capture Source" controls confuse alsamixer
8806                  * So call somewhat different..
8807                  * FIXME: the controls appear in the "playback" view!
8808                  */
8809                 /* .name = "Capture Source", */
8810                 .name = "Input Source",
8811                 .count = 2,
8812                 .info = alc268_mux_enum_info,
8813                 .get = alc268_mux_enum_get,
8814                 .put = alc268_mux_enum_put,
8815         },
8816         { } /* end */
8817 };
8818
8819 static struct hda_input_mux alc268_capture_source = {
8820         .num_items = 4,
8821         .items = {
8822                 { "Mic", 0x0 },
8823                 { "Front Mic", 0x1 },
8824                 { "Line", 0x2 },
8825                 { "CD", 0x3 },
8826         },
8827 };
8828
8829 /* create input playback/capture controls for the given pin */
8830 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
8831                                     const char *ctlname, int idx)
8832 {
8833         char name[32];
8834         int err;
8835
8836         sprintf(name, "%s Playback Volume", ctlname);
8837         if (nid == 0x14) {
8838                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
8839                                   HDA_COMPOSE_AMP_VAL(0x02, 3, idx,
8840                                                       HDA_OUTPUT));
8841                 if (err < 0)
8842                         return err;
8843         } else if (nid == 0x15) {
8844                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
8845                                   HDA_COMPOSE_AMP_VAL(0x03, 3, idx,
8846                                                       HDA_OUTPUT));
8847                 if (err < 0)
8848                         return err;
8849         } else
8850                 return -1;
8851         sprintf(name, "%s Playback Switch", ctlname);
8852         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
8853                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
8854         if (err < 0)
8855                 return err;
8856         return 0;
8857 }
8858
8859 /* add playback controls from the parsed DAC table */
8860 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
8861                                              const struct auto_pin_cfg *cfg)
8862 {
8863         hda_nid_t nid;
8864         int err;
8865
8866         spec->multiout.num_dacs = 2;    /* only use one dac */
8867         spec->multiout.dac_nids = spec->private_dac_nids;
8868         spec->multiout.dac_nids[0] = 2;
8869         spec->multiout.dac_nids[1] = 3;
8870
8871         nid = cfg->line_out_pins[0];
8872         if (nid)
8873                 alc268_new_analog_output(spec, nid, "Front", 0);        
8874
8875         nid = cfg->speaker_pins[0];
8876         if (nid == 0x1d) {
8877                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
8878                                   "Speaker Playback Volume",
8879                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
8880                 if (err < 0)
8881                         return err;
8882         }
8883         nid = cfg->hp_pins[0];
8884         if (nid)
8885                 alc268_new_analog_output(spec, nid, "Headphone", 0);
8886
8887         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
8888         if (nid == 0x16) {
8889                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
8890                                   "Mono Playback Switch",
8891                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_INPUT));
8892                 if (err < 0)
8893                         return err;
8894         }
8895         return 0;       
8896 }
8897
8898 /* create playback/capture controls for input pins */
8899 static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
8900                                                 const struct auto_pin_cfg *cfg)
8901 {
8902         struct hda_input_mux *imux = &spec->private_imux;
8903         int i, idx1;
8904
8905         for (i = 0; i < AUTO_PIN_LAST; i++) {
8906                 switch(cfg->input_pins[i]) {
8907                 case 0x18:
8908                         idx1 = 0;       /* Mic 1 */
8909                         break;
8910                 case 0x19:
8911                         idx1 = 1;       /* Mic 2 */
8912                         break;
8913                 case 0x1a:
8914                         idx1 = 2;       /* Line In */
8915                         break;
8916                 case 0x1c:      
8917                         idx1 = 3;       /* CD */
8918                         break;
8919                 default:
8920                         continue;
8921                 }
8922                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
8923                 imux->items[imux->num_items].index = idx1;
8924                 imux->num_items++;      
8925         }
8926         return 0;
8927 }
8928
8929 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
8930 {
8931         struct alc_spec *spec = codec->spec;
8932         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
8933         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
8934         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
8935         unsigned int    dac_vol1, dac_vol2;
8936
8937         if (speaker_nid) {
8938                 snd_hda_codec_write(codec, speaker_nid, 0,
8939                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
8940                 snd_hda_codec_write(codec, 0x0f, 0,
8941                                     AC_VERB_SET_AMP_GAIN_MUTE,
8942                                     AMP_IN_UNMUTE(1));
8943                 snd_hda_codec_write(codec, 0x10, 0,
8944                                     AC_VERB_SET_AMP_GAIN_MUTE,
8945                                     AMP_IN_UNMUTE(1));
8946         } else {
8947                 snd_hda_codec_write(codec, 0x0f, 0,
8948                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
8949                 snd_hda_codec_write(codec, 0x10, 0,
8950                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
8951         }
8952
8953         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
8954         if (line_nid == 0x14)   
8955                 dac_vol2 = AMP_OUT_ZERO;
8956         else if (line_nid == 0x15)
8957                 dac_vol1 = AMP_OUT_ZERO;
8958         if (hp_nid == 0x14)     
8959                 dac_vol2 = AMP_OUT_ZERO;
8960         else if (hp_nid == 0x15)
8961                 dac_vol1 = AMP_OUT_ZERO;
8962         if (line_nid != 0x16 || hp_nid != 0x16 ||
8963             spec->autocfg.line_out_pins[1] != 0x16 ||
8964             spec->autocfg.line_out_pins[2] != 0x16)
8965                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
8966
8967         snd_hda_codec_write(codec, 0x02, 0,
8968                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
8969         snd_hda_codec_write(codec, 0x03, 0,
8970                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
8971 }
8972
8973 /* pcm configuration: identiacal with ALC880 */
8974 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
8975 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
8976 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
8977
8978 /*
8979  * BIOS auto configuration
8980  */
8981 static int alc268_parse_auto_config(struct hda_codec *codec)
8982 {
8983         struct alc_spec *spec = codec->spec;
8984         int err;
8985         static hda_nid_t alc268_ignore[] = { 0 };
8986
8987         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
8988                                            alc268_ignore);
8989         if (err < 0)
8990                 return err;
8991         if (!spec->autocfg.line_outs)
8992                 return 0; /* can't find valid BIOS pin config */
8993
8994         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
8995         if (err < 0)
8996                 return err;
8997         err = alc268_auto_create_analog_input_ctls(spec, &spec->autocfg);
8998         if (err < 0)
8999                 return err;
9000
9001         spec->multiout.max_channels = 2;
9002
9003         /* digital only support output */
9004         if (spec->autocfg.dig_out_pin)
9005                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
9006
9007         if (spec->kctl_alloc)
9008                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
9009
9010         spec->init_verbs[spec->num_init_verbs++] = alc268_volume_init_verbs;
9011         spec->num_mux_defs = 1;
9012         spec->input_mux = &spec->private_imux;
9013
9014         err = alc_auto_add_mic_boost(codec);
9015         if (err < 0)
9016                 return err;
9017
9018         return 1;
9019 }
9020
9021 #define alc268_auto_init_multi_out      alc882_auto_init_multi_out
9022 #define alc268_auto_init_hp_out         alc882_auto_init_hp_out
9023 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
9024
9025 /* init callback for auto-configuration model -- overriding the default init */
9026 static void alc268_auto_init(struct hda_codec *codec)
9027 {
9028         alc268_auto_init_multi_out(codec);
9029         alc268_auto_init_hp_out(codec);
9030         alc268_auto_init_mono_speaker_out(codec);
9031         alc268_auto_init_analog_input(codec);
9032 }
9033
9034 /*
9035  * configuration and preset
9036  */
9037 static const char *alc268_models[ALC268_MODEL_LAST] = {
9038         [ALC268_3ST]            = "3stack",
9039         [ALC268_TOSHIBA]        = "toshiba",
9040         [ALC268_ACER]           = "acer",
9041         [ALC268_AUTO]           = "auto",
9042 };
9043
9044 static struct snd_pci_quirk alc268_cfg_tbl[] = {
9045         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
9046         SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA),
9047         SND_PCI_QUIRK(0x103c, 0x30cc, "TOSHIBA", ALC268_TOSHIBA),
9048         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
9049         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
9050         {}
9051 };
9052
9053 static struct alc_config_preset alc268_presets[] = {
9054         [ALC268_3ST] = {
9055                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer },
9056                 .init_verbs = { alc268_base_init_verbs },
9057                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
9058                 .dac_nids = alc268_dac_nids,
9059                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
9060                 .adc_nids = alc268_adc_nids_alt,
9061                 .hp_nid = 0x03,
9062                 .dig_out_nid = ALC268_DIGOUT_NID,
9063                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
9064                 .channel_mode = alc268_modes,
9065                 .input_mux = &alc268_capture_source,
9066         },
9067         [ALC268_TOSHIBA] = {
9068                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer },
9069                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
9070                                 alc268_toshiba_verbs },
9071                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
9072                 .dac_nids = alc268_dac_nids,
9073                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
9074                 .adc_nids = alc268_adc_nids_alt,
9075                 .hp_nid = 0x03,
9076                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
9077                 .channel_mode = alc268_modes,
9078                 .input_mux = &alc268_capture_source,
9079                 .input_mux = &alc268_capture_source,
9080                 .unsol_event = alc268_toshiba_unsol_event,
9081                 .init_hook = alc268_toshiba_automute,
9082         },
9083         [ALC268_ACER] = {
9084                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer },
9085                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
9086                                 alc268_acer_verbs },
9087                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
9088                 .dac_nids = alc268_dac_nids,
9089                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
9090                 .adc_nids = alc268_adc_nids_alt,
9091                 .hp_nid = 0x02,
9092                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
9093                 .channel_mode = alc268_modes,
9094                 .input_mux = &alc268_capture_source,
9095                 .unsol_event = alc268_acer_unsol_event,
9096                 .init_hook = alc268_acer_init_hook,
9097         },
9098 };
9099
9100 static int patch_alc268(struct hda_codec *codec)
9101 {
9102         struct alc_spec *spec;
9103         int board_config;
9104         int err;
9105
9106         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
9107         if (spec == NULL)
9108                 return -ENOMEM;
9109
9110         codec->spec = spec;
9111
9112         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
9113                                                   alc268_models,
9114                                                   alc268_cfg_tbl);
9115
9116         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
9117                 printk(KERN_INFO "hda_codec: Unknown model for ALC268, "
9118                        "trying auto-probe from BIOS...\n");
9119                 board_config = ALC268_AUTO;
9120         }
9121
9122         if (board_config == ALC268_AUTO) {
9123                 /* automatic parse from the BIOS config */
9124                 err = alc268_parse_auto_config(codec);
9125                 if (err < 0) {
9126                         alc_free(codec);
9127                         return err;
9128                 } else if (!err) {
9129                         printk(KERN_INFO
9130                                "hda_codec: Cannot set up configuration "
9131                                "from BIOS.  Using base mode...\n");
9132                         board_config = ALC268_3ST;
9133                 }
9134         }
9135
9136         if (board_config != ALC268_AUTO)
9137                 setup_preset(spec, &alc268_presets[board_config]);
9138
9139         spec->stream_name_analog = "ALC268 Analog";
9140         spec->stream_analog_playback = &alc268_pcm_analog_playback;
9141         spec->stream_analog_capture = &alc268_pcm_analog_capture;
9142
9143         spec->stream_name_digital = "ALC268 Digital";
9144         spec->stream_digital_playback = &alc268_pcm_digital_playback;
9145
9146         if (board_config == ALC268_AUTO) {
9147                 if (!spec->adc_nids && spec->input_mux) {
9148                         /* check whether NID 0x07 is valid */
9149                         unsigned int wcap = get_wcaps(codec, 0x07);
9150
9151                         /* get type */
9152                         wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
9153                         if (wcap != AC_WID_AUD_IN) {
9154                                 spec->adc_nids = alc268_adc_nids_alt;
9155                                 spec->num_adc_nids =
9156                                         ARRAY_SIZE(alc268_adc_nids_alt);
9157                                 spec->mixers[spec->num_mixers] =
9158                                         alc268_capture_alt_mixer;
9159                                 spec->num_mixers++;
9160                         } else {
9161                                 spec->adc_nids = alc268_adc_nids;
9162                                 spec->num_adc_nids =
9163                                         ARRAY_SIZE(alc268_adc_nids);
9164                                 spec->mixers[spec->num_mixers] =
9165                                         alc268_capture_mixer;
9166                                 spec->num_mixers++;
9167                         }
9168                 }
9169         }
9170         codec->patch_ops = alc_patch_ops;
9171         if (board_config == ALC268_AUTO)
9172                 spec->init_hook = alc268_auto_init;
9173                 
9174         return 0;
9175 }
9176
9177 /*
9178  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
9179  */
9180
9181 /*
9182  * set the path ways for 2 channel output
9183  * need to set the codec line out and mic 1 pin widgets to inputs
9184  */
9185 static struct hda_verb alc861_threestack_ch2_init[] = {
9186         /* set pin widget 1Ah (line in) for input */
9187         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
9188         /* set pin widget 18h (mic1/2) for input, for mic also enable
9189          * the vref
9190          */
9191         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9192
9193         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
9194 #if 0
9195         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
9196         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
9197 #endif
9198         { } /* end */
9199 };
9200 /*
9201  * 6ch mode
9202  * need to set the codec line out and mic 1 pin widgets to outputs
9203  */
9204 static struct hda_verb alc861_threestack_ch6_init[] = {
9205         /* set pin widget 1Ah (line in) for output (Back Surround)*/
9206         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9207         /* set pin widget 18h (mic1) for output (CLFE)*/
9208         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9209
9210         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
9211         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
9212
9213         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
9214 #if 0
9215         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
9216         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
9217 #endif
9218         { } /* end */
9219 };
9220
9221 static struct hda_channel_mode alc861_threestack_modes[2] = {
9222         { 2, alc861_threestack_ch2_init },
9223         { 6, alc861_threestack_ch6_init },
9224 };
9225 /* Set mic1 as input and unmute the mixer */
9226 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
9227         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9228         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
9229         { } /* end */
9230 };
9231 /* Set mic1 as output and mute mixer */
9232 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
9233         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9234         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
9235         { } /* end */
9236 };
9237
9238 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
9239         { 2, alc861_uniwill_m31_ch2_init },
9240         { 4, alc861_uniwill_m31_ch4_init },
9241 };
9242
9243 /* Set mic1 and line-in as input and unmute the mixer */
9244 static struct hda_verb alc861_asus_ch2_init[] = {
9245         /* set pin widget 1Ah (line in) for input */
9246         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
9247         /* set pin widget 18h (mic1/2) for input, for mic also enable
9248          * the vref
9249          */
9250         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9251
9252         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
9253 #if 0
9254         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
9255         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
9256 #endif
9257         { } /* end */
9258 };
9259 /* Set mic1 nad line-in as output and mute mixer */
9260 static struct hda_verb alc861_asus_ch6_init[] = {
9261         /* set pin widget 1Ah (line in) for output (Back Surround)*/
9262         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9263         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
9264         /* set pin widget 18h (mic1) for output (CLFE)*/
9265         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9266         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
9267         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
9268         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
9269
9270         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
9271 #if 0
9272         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
9273         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
9274 #endif
9275         { } /* end */
9276 };
9277
9278 static struct hda_channel_mode alc861_asus_modes[2] = {
9279         { 2, alc861_asus_ch2_init },
9280         { 6, alc861_asus_ch6_init },
9281 };
9282
9283 /* patch-ALC861 */
9284
9285 static struct snd_kcontrol_new alc861_base_mixer[] = {
9286         /* output mixer control */
9287         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
9288         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
9289         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
9290         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
9291         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
9292
9293         /*Input mixer control */
9294         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
9295            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
9296         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
9297         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
9298         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
9299         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
9300         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
9301         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
9302         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
9303         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
9304
9305         /* Capture mixer control */
9306         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
9307         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
9308         {
9309                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9310                 .name = "Capture Source",
9311                 .count = 1,
9312                 .info = alc_mux_enum_info,
9313                 .get = alc_mux_enum_get,
9314                 .put = alc_mux_enum_put,
9315         },
9316         { } /* end */
9317 };
9318
9319 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
9320         /* output mixer control */
9321         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
9322         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
9323         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
9324         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
9325         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
9326
9327         /* Input mixer control */
9328         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
9329            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
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("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
9333         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
9334         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
9335         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
9336         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
9337         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
9338
9339         /* Capture mixer control */
9340         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
9341         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
9342         {
9343                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9344                 .name = "Capture Source",
9345                 .count = 1,
9346                 .info = alc_mux_enum_info,
9347                 .get = alc_mux_enum_get,
9348                 .put = alc_mux_enum_put,
9349         },
9350         {
9351                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9352                 .name = "Channel Mode",
9353                 .info = alc_ch_mode_info,
9354                 .get = alc_ch_mode_get,
9355                 .put = alc_ch_mode_put,
9356                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
9357         },
9358         { } /* end */
9359 };
9360
9361 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
9362         /* output mixer control */
9363         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
9364         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
9365         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
9366         
9367         /*Capture mixer control */
9368         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
9369         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
9370         {
9371                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9372                 .name = "Capture Source",
9373                 .count = 1,
9374                 .info = alc_mux_enum_info,
9375                 .get = alc_mux_enum_get,
9376                 .put = alc_mux_enum_put,
9377         },
9378
9379         { } /* end */
9380 };
9381
9382 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
9383         /* output mixer control */
9384         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
9385         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
9386         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
9387         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
9388         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
9389
9390         /* Input mixer control */
9391         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
9392            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
9393         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
9394         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
9395         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
9396         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
9397         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
9398         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
9399         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
9400         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
9401
9402         /* Capture mixer control */
9403         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
9404         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
9405         {
9406                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9407                 .name = "Capture Source",
9408                 .count = 1,
9409                 .info = alc_mux_enum_info,
9410                 .get = alc_mux_enum_get,
9411                 .put = alc_mux_enum_put,
9412         },
9413         {
9414                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9415                 .name = "Channel Mode",
9416                 .info = alc_ch_mode_info,
9417                 .get = alc_ch_mode_get,
9418                 .put = alc_ch_mode_put,
9419                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
9420         },
9421         { } /* end */
9422 };
9423
9424 static struct snd_kcontrol_new alc861_asus_mixer[] = {
9425         /* output mixer control */
9426         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
9427         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
9428         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
9429         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
9430         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
9431
9432         /* Input mixer control */
9433         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
9434         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9435         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
9436         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
9437         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
9438         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
9439         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
9440         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
9441         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
9442         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
9443
9444         /* Capture mixer control */
9445         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
9446         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
9447         {
9448                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9449                 .name = "Capture Source",
9450                 .count = 1,
9451                 .info = alc_mux_enum_info,
9452                 .get = alc_mux_enum_get,
9453                 .put = alc_mux_enum_put,
9454         },
9455         {
9456                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9457                 .name = "Channel Mode",
9458                 .info = alc_ch_mode_info,
9459                 .get = alc_ch_mode_get,
9460                 .put = alc_ch_mode_put,
9461                 .private_value = ARRAY_SIZE(alc861_asus_modes),
9462         },
9463         { }
9464 };
9465
9466 /* additional mixer */
9467 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
9468         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
9469         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
9470         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x23, 0x0, HDA_OUTPUT),
9471         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x23, 0x0, HDA_OUTPUT),
9472         { }
9473 };
9474
9475 /*
9476  * generic initialization of ADC, input mixers and output mixers
9477  */
9478 static struct hda_verb alc861_base_init_verbs[] = {
9479         /*
9480          * Unmute ADC0 and set the default input to mic-in
9481          */
9482         /* port-A for surround (rear panel) */
9483         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9484         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
9485         /* port-B for mic-in (rear panel) with vref */
9486         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9487         /* port-C for line-in (rear panel) */
9488         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
9489         /* port-D for Front */
9490         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9491         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
9492         /* port-E for HP out (front panel) */
9493         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
9494         /* route front PCM to HP */
9495         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
9496         /* port-F for mic-in (front panel) with vref */
9497         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9498         /* port-G for CLFE (rear panel) */
9499         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9500         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
9501         /* port-H for side (rear panel) */
9502         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9503         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
9504         /* CD-in */
9505         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
9506         /* route front mic to ADC1*/
9507         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9508         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9509         
9510         /* Unmute DAC0~3 & spdif out*/
9511         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9512         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9513         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9514         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9515         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9516         
9517         /* Unmute Mixer 14 (mic) 1c (Line in)*/
9518         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9519         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9520         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9521         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9522         
9523         /* Unmute Stereo Mixer 15 */
9524         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9525         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9526         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9527         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
9528
9529         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9530         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9531         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9532         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9533         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9534         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9535         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9536         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9537         /* hp used DAC 3 (Front) */
9538         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
9539         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9540
9541         { }
9542 };
9543
9544 static struct hda_verb alc861_threestack_init_verbs[] = {
9545         /*
9546          * Unmute ADC0 and set the default input to mic-in
9547          */
9548         /* port-A for surround (rear panel) */
9549         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
9550         /* port-B for mic-in (rear panel) with vref */
9551         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9552         /* port-C for line-in (rear panel) */
9553         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
9554         /* port-D for Front */
9555         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9556         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
9557         /* port-E for HP out (front panel) */
9558         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
9559         /* route front PCM to HP */
9560         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
9561         /* port-F for mic-in (front panel) with vref */
9562         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9563         /* port-G for CLFE (rear panel) */
9564         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
9565         /* port-H for side (rear panel) */
9566         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
9567         /* CD-in */
9568         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
9569         /* route front mic to ADC1*/
9570         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9571         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9572         /* Unmute DAC0~3 & spdif out*/
9573         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9574         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9575         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9576         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9577         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9578         
9579         /* Unmute Mixer 14 (mic) 1c (Line in)*/
9580         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9581         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9582         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9583         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9584         
9585         /* Unmute Stereo Mixer 15 */
9586         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9587         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9588         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9589         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
9590
9591         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9592         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9593         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9594         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9595         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9596         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9597         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9598         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9599         /* hp used DAC 3 (Front) */
9600         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
9601         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9602         { }
9603 };
9604
9605 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
9606         /*
9607          * Unmute ADC0 and set the default input to mic-in
9608          */
9609         /* port-A for surround (rear panel) */
9610         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
9611         /* port-B for mic-in (rear panel) with vref */
9612         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9613         /* port-C for line-in (rear panel) */
9614         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
9615         /* port-D for Front */
9616         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9617         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
9618         /* port-E for HP out (front panel) */
9619         /* this has to be set to VREF80 */
9620         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9621         /* route front PCM to HP */
9622         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
9623         /* port-F for mic-in (front panel) with vref */
9624         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9625         /* port-G for CLFE (rear panel) */
9626         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
9627         /* port-H for side (rear panel) */
9628         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
9629         /* CD-in */
9630         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
9631         /* route front mic to ADC1*/
9632         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9633         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9634         /* Unmute DAC0~3 & spdif out*/
9635         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9636         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9637         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9638         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9639         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9640         
9641         /* Unmute Mixer 14 (mic) 1c (Line in)*/
9642         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9643         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9644         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9645         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9646         
9647         /* Unmute Stereo Mixer 15 */
9648         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9649         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9650         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9651         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
9652
9653         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9654         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9655         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9656         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9657         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9658         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9659         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9660         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9661         /* hp used DAC 3 (Front) */
9662         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
9663         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9664         { }
9665 };
9666
9667 static struct hda_verb alc861_asus_init_verbs[] = {
9668         /*
9669          * Unmute ADC0 and set the default input to mic-in
9670          */
9671         /* port-A for surround (rear panel)
9672          * according to codec#0 this is the HP jack
9673          */
9674         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
9675         /* route front PCM to HP */
9676         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
9677         /* port-B for mic-in (rear panel) with vref */
9678         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9679         /* port-C for line-in (rear panel) */
9680         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
9681         /* port-D for Front */
9682         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9683         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
9684         /* port-E for HP out (front panel) */
9685         /* this has to be set to VREF80 */
9686         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9687         /* route front PCM to HP */
9688         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
9689         /* port-F for mic-in (front panel) with vref */
9690         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
9691         /* port-G for CLFE (rear panel) */
9692         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9693         /* port-H for side (rear panel) */
9694         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
9695         /* CD-in */
9696         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
9697         /* route front mic to ADC1*/
9698         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9699         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9700         /* Unmute DAC0~3 & spdif out*/
9701         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9702         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9703         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9704         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9705         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9706         /* Unmute Mixer 14 (mic) 1c (Line in)*/
9707         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9708         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9709         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9710         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9711         
9712         /* Unmute Stereo Mixer 15 */
9713         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9714         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9715         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9716         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
9717
9718         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9719         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9720         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9721         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9722         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9723         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9724         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9725         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9726         /* hp used DAC 3 (Front) */
9727         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
9728         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9729         { }
9730 };
9731
9732 /* additional init verbs for ASUS laptops */
9733 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
9734         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
9735         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
9736         { }
9737 };
9738
9739 /*
9740  * generic initialization of ADC, input mixers and output mixers
9741  */
9742 static struct hda_verb alc861_auto_init_verbs[] = {
9743         /*
9744          * Unmute ADC0 and set the default input to mic-in
9745          */
9746         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
9747         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9748         
9749         /* Unmute DAC0~3 & spdif out*/
9750         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9751         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9752         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9753         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9754         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9755         
9756         /* Unmute Mixer 14 (mic) 1c (Line in)*/
9757         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9758         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9759         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9760         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9761         
9762         /* Unmute Stereo Mixer 15 */
9763         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9764         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9765         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9766         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
9767
9768         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9769         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9770         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9771         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9772         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9773         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9774         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9775         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9776
9777         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9778         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9779         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9780         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
9781         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9782         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9783         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9784         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
9785
9786         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
9787
9788         { }
9789 };
9790
9791 static struct hda_verb alc861_toshiba_init_verbs[] = {
9792         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9793
9794         { }
9795 };
9796
9797 /* toggle speaker-output according to the hp-jack state */
9798 static void alc861_toshiba_automute(struct hda_codec *codec)
9799 {
9800         unsigned int present;
9801
9802         present = snd_hda_codec_read(codec, 0x0f, 0,
9803                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9804         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
9805                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
9806         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
9807                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
9808 }
9809
9810 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
9811                                        unsigned int res)
9812 {
9813         if ((res >> 26) == ALC880_HP_EVENT)
9814                 alc861_toshiba_automute(codec);
9815 }
9816
9817 /* pcm configuration: identiacal with ALC880 */
9818 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
9819 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
9820 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
9821 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
9822
9823
9824 #define ALC861_DIGOUT_NID       0x07
9825
9826 static struct hda_channel_mode alc861_8ch_modes[1] = {
9827         { 8, NULL }
9828 };
9829
9830 static hda_nid_t alc861_dac_nids[4] = {
9831         /* front, surround, clfe, side */
9832         0x03, 0x06, 0x05, 0x04
9833 };
9834
9835 static hda_nid_t alc660_dac_nids[3] = {
9836         /* front, clfe, surround */
9837         0x03, 0x05, 0x06
9838 };
9839
9840 static hda_nid_t alc861_adc_nids[1] = {
9841         /* ADC0-2 */
9842         0x08,
9843 };
9844
9845 static struct hda_input_mux alc861_capture_source = {
9846         .num_items = 5,
9847         .items = {
9848                 { "Mic", 0x0 },
9849                 { "Front Mic", 0x3 },
9850                 { "Line", 0x1 },
9851                 { "CD", 0x4 },
9852                 { "Mixer", 0x5 },
9853         },
9854 };
9855
9856 /* fill in the dac_nids table from the parsed pin configuration */
9857 static int alc861_auto_fill_dac_nids(struct alc_spec *spec,
9858                                      const struct auto_pin_cfg *cfg)
9859 {
9860         int i;
9861         hda_nid_t nid;
9862
9863         spec->multiout.dac_nids = spec->private_dac_nids;
9864         for (i = 0; i < cfg->line_outs; i++) {
9865                 nid = cfg->line_out_pins[i];
9866                 if (nid) {
9867                         if (i >= ARRAY_SIZE(alc861_dac_nids))
9868                                 continue;
9869                         spec->multiout.dac_nids[i] = alc861_dac_nids[i];
9870                 }
9871         }
9872         spec->multiout.num_dacs = cfg->line_outs;
9873         return 0;
9874 }
9875
9876 /* add playback controls from the parsed DAC table */
9877 static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
9878                                              const struct auto_pin_cfg *cfg)
9879 {
9880         char name[32];
9881         static const char *chname[4] = {
9882                 "Front", "Surround", NULL /*CLFE*/, "Side"
9883         };
9884         hda_nid_t nid;
9885         int i, idx, err;
9886
9887         for (i = 0; i < cfg->line_outs; i++) {
9888                 nid = spec->multiout.dac_nids[i];
9889                 if (!nid)
9890                         continue;
9891                 if (nid == 0x05) {
9892                         /* Center/LFE */
9893                         err = add_control(spec, ALC_CTL_BIND_MUTE,
9894                                           "Center Playback Switch",
9895                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
9896                                                               HDA_OUTPUT));
9897                         if (err < 0)
9898                                 return err;
9899                         err = add_control(spec, ALC_CTL_BIND_MUTE,
9900                                           "LFE Playback Switch",
9901                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
9902                                                               HDA_OUTPUT));
9903                         if (err < 0)
9904                                 return err;
9905                 } else {
9906                         for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1;
9907                              idx++)
9908                                 if (nid == alc861_dac_nids[idx])
9909                                         break;
9910                         sprintf(name, "%s Playback Switch", chname[idx]);
9911                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
9912                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
9913                                                               HDA_OUTPUT));
9914                         if (err < 0)
9915                                 return err;
9916                 }
9917         }
9918         return 0;
9919 }
9920
9921 static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
9922 {
9923         int err;
9924         hda_nid_t nid;
9925
9926         if (!pin)
9927                 return 0;
9928
9929         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
9930                 nid = 0x03;
9931                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9932                                   "Headphone Playback Switch",
9933                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
9934                 if (err < 0)
9935                         return err;
9936                 spec->multiout.hp_nid = nid;
9937         }
9938         return 0;
9939 }
9940
9941 /* create playback/capture controls for input pins */
9942 static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec,
9943                                                 const struct auto_pin_cfg *cfg)
9944 {
9945         struct hda_input_mux *imux = &spec->private_imux;
9946         int i, err, idx, idx1;
9947
9948         for (i = 0; i < AUTO_PIN_LAST; i++) {
9949                 switch (cfg->input_pins[i]) {
9950                 case 0x0c:
9951                         idx1 = 1;
9952                         idx = 2;        /* Line In */
9953                         break;
9954                 case 0x0f:
9955                         idx1 = 2;
9956                         idx = 2;        /* Line In */
9957                         break;
9958                 case 0x0d:
9959                         idx1 = 0;
9960                         idx = 1;        /* Mic In */
9961                         break;
9962                 case 0x10:
9963                         idx1 = 3;
9964                         idx = 1;        /* Mic In */
9965                         break;
9966                 case 0x11:
9967                         idx1 = 4;
9968                         idx = 0;        /* CD */
9969                         break;
9970                 default:
9971                         continue;
9972                 }
9973
9974                 err = new_analog_input(spec, cfg->input_pins[i],
9975                                        auto_pin_cfg_labels[i], idx, 0x15);
9976                 if (err < 0)
9977                         return err;
9978
9979                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
9980                 imux->items[imux->num_items].index = idx1;
9981                 imux->num_items++;
9982         }
9983         return 0;
9984 }
9985
9986 static struct snd_kcontrol_new alc861_capture_mixer[] = {
9987         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
9988         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
9989
9990         {
9991                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9992                 /* The multiple "Capture Source" controls confuse alsamixer
9993                  * So call somewhat different..
9994                  *FIXME: the controls appear in the "playback" view!
9995                  */
9996                 /* .name = "Capture Source", */
9997                 .name = "Input Source",
9998                 .count = 1,
9999                 .info = alc_mux_enum_info,
10000                 .get = alc_mux_enum_get,
10001                 .put = alc_mux_enum_put,
10002         },
10003         { } /* end */
10004 };
10005
10006 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
10007                                               hda_nid_t nid,
10008                                               int pin_type, int dac_idx)
10009 {
10010         /* set as output */
10011
10012         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
10013                             pin_type);
10014         snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE,
10015                             AMP_OUT_UNMUTE);
10016
10017 }
10018
10019 static void alc861_auto_init_multi_out(struct hda_codec *codec)
10020 {
10021         struct alc_spec *spec = codec->spec;
10022         int i;
10023
10024         alc_subsystem_id(codec, 0x0e, 0x0f, 0x0b);
10025         for (i = 0; i < spec->autocfg.line_outs; i++) {
10026                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
10027                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
10028                 if (nid)
10029                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
10030                                                           spec->multiout.dac_nids[i]);
10031         }
10032 }
10033
10034 static void alc861_auto_init_hp_out(struct hda_codec *codec)
10035 {
10036         struct alc_spec *spec = codec->spec;
10037         hda_nid_t pin;
10038
10039         pin = spec->autocfg.hp_pins[0];
10040         if (pin) /* connect to front */
10041                 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
10042                                                   spec->multiout.dac_nids[0]);
10043 }
10044
10045 static void alc861_auto_init_analog_input(struct hda_codec *codec)
10046 {
10047         struct alc_spec *spec = codec->spec;
10048         int i;
10049
10050         for (i = 0; i < AUTO_PIN_LAST; i++) {
10051                 hda_nid_t nid = spec->autocfg.input_pins[i];
10052                 if (nid >= 0x0c && nid <= 0x11) {
10053                         snd_hda_codec_write(codec, nid, 0,
10054                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
10055                                             i <= AUTO_PIN_FRONT_MIC ?
10056                                             PIN_VREF80 : PIN_IN);
10057                 }
10058         }
10059 }
10060
10061 /* parse the BIOS configuration and set up the alc_spec */
10062 /* return 1 if successful, 0 if the proper config is not found,
10063  * or a negative error code
10064  */
10065 static int alc861_parse_auto_config(struct hda_codec *codec)
10066 {
10067         struct alc_spec *spec = codec->spec;
10068         int err;
10069         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
10070
10071         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
10072                                            alc861_ignore);
10073         if (err < 0)
10074                 return err;
10075         if (!spec->autocfg.line_outs)
10076                 return 0; /* can't find valid BIOS pin config */
10077
10078         err = alc861_auto_fill_dac_nids(spec, &spec->autocfg);
10079         if (err < 0)
10080                 return err;
10081         err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg);
10082         if (err < 0)
10083                 return err;
10084         err = alc861_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
10085         if (err < 0)
10086                 return err;
10087         err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg);
10088         if (err < 0)
10089                 return err;
10090
10091         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
10092
10093         if (spec->autocfg.dig_out_pin)
10094                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
10095
10096         if (spec->kctl_alloc)
10097                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
10098
10099         spec->init_verbs[spec->num_init_verbs++] = alc861_auto_init_verbs;
10100
10101         spec->num_mux_defs = 1;
10102         spec->input_mux = &spec->private_imux;
10103
10104         spec->adc_nids = alc861_adc_nids;
10105         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
10106         spec->mixers[spec->num_mixers] = alc861_capture_mixer;
10107         spec->num_mixers++;
10108
10109         return 1;
10110 }
10111
10112 /* additional initialization for auto-configuration model */
10113 static void alc861_auto_init(struct hda_codec *codec)
10114 {
10115         alc861_auto_init_multi_out(codec);
10116         alc861_auto_init_hp_out(codec);
10117         alc861_auto_init_analog_input(codec);
10118 }
10119
10120 #ifdef CONFIG_SND_HDA_POWER_SAVE
10121 static struct hda_amp_list alc861_loopbacks[] = {
10122         { 0x15, HDA_INPUT, 0 },
10123         { 0x15, HDA_INPUT, 1 },
10124         { 0x15, HDA_INPUT, 2 },
10125         { 0x15, HDA_INPUT, 3 },
10126         { } /* end */
10127 };
10128 #endif
10129
10130
10131 /*
10132  * configuration and preset
10133  */
10134 static const char *alc861_models[ALC861_MODEL_LAST] = {
10135         [ALC861_3ST]            = "3stack",
10136         [ALC660_3ST]            = "3stack-660",
10137         [ALC861_3ST_DIG]        = "3stack-dig",
10138         [ALC861_6ST_DIG]        = "6stack-dig",
10139         [ALC861_UNIWILL_M31]    = "uniwill-m31",
10140         [ALC861_TOSHIBA]        = "toshiba",
10141         [ALC861_ASUS]           = "asus",
10142         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
10143         [ALC861_AUTO]           = "auto",
10144 };
10145
10146 static struct snd_pci_quirk alc861_cfg_tbl[] = {
10147         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
10148         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
10149         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
10150         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
10151         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
10152         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
10153         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
10154         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
10155         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
10156          *        Any other models that need this preset?
10157          */
10158         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
10159         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
10160         SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31),
10161         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
10162         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
10163         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
10164         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
10165         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
10166         {}
10167 };
10168
10169 static struct alc_config_preset alc861_presets[] = {
10170         [ALC861_3ST] = {
10171                 .mixers = { alc861_3ST_mixer },
10172                 .init_verbs = { alc861_threestack_init_verbs },
10173                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
10174                 .dac_nids = alc861_dac_nids,
10175                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
10176                 .channel_mode = alc861_threestack_modes,
10177                 .need_dac_fix = 1,
10178                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
10179                 .adc_nids = alc861_adc_nids,
10180                 .input_mux = &alc861_capture_source,
10181         },
10182         [ALC861_3ST_DIG] = {
10183                 .mixers = { alc861_base_mixer },
10184                 .init_verbs = { alc861_threestack_init_verbs },
10185                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
10186                 .dac_nids = alc861_dac_nids,
10187                 .dig_out_nid = ALC861_DIGOUT_NID,
10188                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
10189                 .channel_mode = alc861_threestack_modes,
10190                 .need_dac_fix = 1,
10191                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
10192                 .adc_nids = alc861_adc_nids,
10193                 .input_mux = &alc861_capture_source,
10194         },
10195         [ALC861_6ST_DIG] = {
10196                 .mixers = { alc861_base_mixer },
10197                 .init_verbs = { alc861_base_init_verbs },
10198                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
10199                 .dac_nids = alc861_dac_nids,
10200                 .dig_out_nid = ALC861_DIGOUT_NID,
10201                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
10202                 .channel_mode = alc861_8ch_modes,
10203                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
10204                 .adc_nids = alc861_adc_nids,
10205                 .input_mux = &alc861_capture_source,
10206         },
10207         [ALC660_3ST] = {
10208                 .mixers = { alc861_3ST_mixer },
10209                 .init_verbs = { alc861_threestack_init_verbs },
10210                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
10211                 .dac_nids = alc660_dac_nids,
10212                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
10213                 .channel_mode = alc861_threestack_modes,
10214                 .need_dac_fix = 1,
10215                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
10216                 .adc_nids = alc861_adc_nids,
10217                 .input_mux = &alc861_capture_source,
10218         },
10219         [ALC861_UNIWILL_M31] = {
10220                 .mixers = { alc861_uniwill_m31_mixer },
10221                 .init_verbs = { alc861_uniwill_m31_init_verbs },
10222                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
10223                 .dac_nids = alc861_dac_nids,
10224                 .dig_out_nid = ALC861_DIGOUT_NID,
10225                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
10226                 .channel_mode = alc861_uniwill_m31_modes,
10227                 .need_dac_fix = 1,
10228                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
10229                 .adc_nids = alc861_adc_nids,
10230                 .input_mux = &alc861_capture_source,
10231         },
10232         [ALC861_TOSHIBA] = {
10233                 .mixers = { alc861_toshiba_mixer },
10234                 .init_verbs = { alc861_base_init_verbs,
10235                                 alc861_toshiba_init_verbs },
10236                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
10237                 .dac_nids = alc861_dac_nids,
10238                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
10239                 .channel_mode = alc883_3ST_2ch_modes,
10240                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
10241                 .adc_nids = alc861_adc_nids,
10242                 .input_mux = &alc861_capture_source,
10243                 .unsol_event = alc861_toshiba_unsol_event,
10244                 .init_hook = alc861_toshiba_automute,
10245         },
10246         [ALC861_ASUS] = {
10247                 .mixers = { alc861_asus_mixer },
10248                 .init_verbs = { alc861_asus_init_verbs },
10249                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
10250                 .dac_nids = alc861_dac_nids,
10251                 .dig_out_nid = ALC861_DIGOUT_NID,
10252                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
10253                 .channel_mode = alc861_asus_modes,
10254                 .need_dac_fix = 1,
10255                 .hp_nid = 0x06,
10256                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
10257                 .adc_nids = alc861_adc_nids,
10258                 .input_mux = &alc861_capture_source,
10259         },
10260         [ALC861_ASUS_LAPTOP] = {
10261                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
10262                 .init_verbs = { alc861_asus_init_verbs,
10263                                 alc861_asus_laptop_init_verbs },
10264                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
10265                 .dac_nids = alc861_dac_nids,
10266                 .dig_out_nid = ALC861_DIGOUT_NID,
10267                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
10268                 .channel_mode = alc883_3ST_2ch_modes,
10269                 .need_dac_fix = 1,
10270                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
10271                 .adc_nids = alc861_adc_nids,
10272                 .input_mux = &alc861_capture_source,
10273         },
10274 };
10275
10276
10277 static int patch_alc861(struct hda_codec *codec)
10278 {
10279         struct alc_spec *spec;
10280         int board_config;
10281         int err;
10282
10283         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
10284         if (spec == NULL)
10285                 return -ENOMEM;
10286
10287         codec->spec = spec;
10288
10289         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
10290                                                   alc861_models,
10291                                                   alc861_cfg_tbl);
10292
10293         if (board_config < 0) {
10294                 printk(KERN_INFO "hda_codec: Unknown model for ALC861, "
10295                        "trying auto-probe from BIOS...\n");
10296                 board_config = ALC861_AUTO;
10297         }
10298
10299         if (board_config == ALC861_AUTO) {
10300                 /* automatic parse from the BIOS config */
10301                 err = alc861_parse_auto_config(codec);
10302                 if (err < 0) {
10303                         alc_free(codec);
10304                         return err;
10305                 } else if (!err) {
10306                         printk(KERN_INFO
10307                                "hda_codec: Cannot set up configuration "
10308                                "from BIOS.  Using base mode...\n");
10309                    board_config = ALC861_3ST_DIG;
10310                 }
10311         }
10312
10313         if (board_config != ALC861_AUTO)
10314                 setup_preset(spec, &alc861_presets[board_config]);
10315
10316         spec->stream_name_analog = "ALC861 Analog";
10317         spec->stream_analog_playback = &alc861_pcm_analog_playback;
10318         spec->stream_analog_capture = &alc861_pcm_analog_capture;
10319
10320         spec->stream_name_digital = "ALC861 Digital";
10321         spec->stream_digital_playback = &alc861_pcm_digital_playback;
10322         spec->stream_digital_capture = &alc861_pcm_digital_capture;
10323
10324         codec->patch_ops = alc_patch_ops;
10325         if (board_config == ALC861_AUTO)
10326                 spec->init_hook = alc861_auto_init;
10327 #ifdef CONFIG_SND_HDA_POWER_SAVE
10328         if (!spec->loopback.amplist)
10329                 spec->loopback.amplist = alc861_loopbacks;
10330 #endif
10331                 
10332         return 0;
10333 }
10334
10335 /*
10336  * ALC861-VD support
10337  *
10338  * Based on ALC882
10339  *
10340  * In addition, an independent DAC
10341  */
10342 #define ALC861VD_DIGOUT_NID     0x06
10343
10344 static hda_nid_t alc861vd_dac_nids[4] = {
10345         /* front, surr, clfe, side surr */
10346         0x02, 0x03, 0x04, 0x05
10347 };
10348
10349 /* dac_nids for ALC660vd are in a different order - according to
10350  * Realtek's driver.
10351  * This should probably tesult in a different mixer for 6stack models
10352  * of ALC660vd codecs, but for now there is only 3stack mixer
10353  * - and it is the same as in 861vd.
10354  * adc_nids in ALC660vd are (is) the same as in 861vd
10355  */
10356 static hda_nid_t alc660vd_dac_nids[3] = {
10357         /* front, rear, clfe, rear_surr */
10358         0x02, 0x04, 0x03
10359 };
10360
10361 static hda_nid_t alc861vd_adc_nids[1] = {
10362         /* ADC0 */
10363         0x09,
10364 };
10365
10366 /* input MUX */
10367 /* FIXME: should be a matrix-type input source selection */
10368 static struct hda_input_mux alc861vd_capture_source = {
10369         .num_items = 4,
10370         .items = {
10371                 { "Mic", 0x0 },
10372                 { "Front Mic", 0x1 },
10373                 { "Line", 0x2 },
10374                 { "CD", 0x4 },
10375         },
10376 };
10377
10378 static struct hda_input_mux alc861vd_dallas_capture_source = {
10379         .num_items = 3,
10380         .items = {
10381                 { "Front Mic", 0x0 },
10382                 { "ATAPI Mic", 0x1 },
10383                 { "Line In", 0x5 },
10384         },
10385 };
10386
10387 static struct hda_input_mux alc861vd_hp_capture_source = {
10388         .num_items = 2,
10389         .items = {
10390                 { "Front Mic", 0x0 },
10391                 { "ATAPI Mic", 0x1 },
10392         },
10393 };
10394
10395 #define alc861vd_mux_enum_info alc_mux_enum_info
10396 #define alc861vd_mux_enum_get alc_mux_enum_get
10397
10398 static int alc861vd_mux_enum_put(struct snd_kcontrol *kcontrol,
10399                                 struct snd_ctl_elem_value *ucontrol)
10400 {
10401         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10402         struct alc_spec *spec = codec->spec;
10403         const struct hda_input_mux *imux = spec->input_mux;
10404         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
10405         static hda_nid_t capture_mixers[1] = { 0x22 };
10406         hda_nid_t nid = capture_mixers[adc_idx];
10407         unsigned int *cur_val = &spec->cur_mux[adc_idx];
10408         unsigned int i, idx;
10409
10410         idx = ucontrol->value.enumerated.item[0];
10411         if (idx >= imux->num_items)
10412                 idx = imux->num_items - 1;
10413         if (*cur_val == idx)
10414                 return 0;
10415         for (i = 0; i < imux->num_items; i++) {
10416                 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
10417                 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
10418                                          imux->items[i].index,
10419                                          HDA_AMP_MUTE, v);
10420         }
10421         *cur_val = idx;
10422         return 1;
10423 }
10424
10425 /*
10426  * 2ch mode
10427  */
10428 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
10429         { 2, NULL }
10430 };
10431
10432 /*
10433  * 6ch mode
10434  */
10435 static struct hda_verb alc861vd_6stack_ch6_init[] = {
10436         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
10437         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10438         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10439         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10440         { } /* end */
10441 };
10442
10443 /*
10444  * 8ch mode
10445  */
10446 static struct hda_verb alc861vd_6stack_ch8_init[] = {
10447         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10448         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10449         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10450         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10451         { } /* end */
10452 };
10453
10454 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
10455         { 6, alc861vd_6stack_ch6_init },
10456         { 8, alc861vd_6stack_ch8_init },
10457 };
10458
10459 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
10460         {
10461                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10462                 .name = "Channel Mode",
10463                 .info = alc_ch_mode_info,
10464                 .get = alc_ch_mode_get,
10465                 .put = alc_ch_mode_put,
10466         },
10467         { } /* end */
10468 };
10469
10470 static struct snd_kcontrol_new alc861vd_capture_mixer[] = {
10471         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
10472         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
10473
10474         {
10475                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10476                 /* The multiple "Capture Source" controls confuse alsamixer
10477                  * So call somewhat different..
10478                  *FIXME: the controls appear in the "playback" view!
10479                  */
10480                 /* .name = "Capture Source", */
10481                 .name = "Input Source",
10482                 .count = 1,
10483                 .info = alc861vd_mux_enum_info,
10484                 .get = alc861vd_mux_enum_get,
10485                 .put = alc861vd_mux_enum_put,
10486         },
10487         { } /* end */
10488 };
10489
10490 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
10491  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
10492  */
10493 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
10494         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10495         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
10496
10497         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
10498         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
10499
10500         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
10501                                 HDA_OUTPUT),
10502         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
10503                                 HDA_OUTPUT),
10504         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
10505         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
10506
10507         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
10508         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
10509
10510         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10511
10512         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10513         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10514         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10515
10516         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10517         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10518         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10519
10520         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10521         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10522
10523         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10524         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10525
10526         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
10527         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
10528
10529         { } /* end */
10530 };
10531
10532 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
10533         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10534         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
10535
10536         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10537
10538         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10539         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10540         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10541
10542         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10543         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10544         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10545
10546         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10547         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10548
10549         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10550         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10551
10552         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
10553         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
10554
10555         { } /* end */
10556 };
10557
10558 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
10559         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10560         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
10561         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10562
10563         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10564
10565         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10566         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10567         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10568
10569         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10570         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10571         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10572
10573         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10574         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10575
10576         { } /* end */
10577 };
10578
10579 /* Pin assignment: Front=0x14, HP = 0x15,
10580  *                 Front Mic=0x18, ATAPI Mic = 0x19, Line In = 0x1d
10581  */
10582 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
10583         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10584         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
10585         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
10586         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
10587         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10588         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10589         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10590         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10591         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x05, HDA_INPUT),
10592         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x05, HDA_INPUT),
10593         { } /* end */
10594 };
10595
10596 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
10597  *                 Front Mic=0x18, ATAPI Mic = 0x19,
10598  */
10599 static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
10600         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10601         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
10602         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
10603         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
10604         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10605         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10606         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10607         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10608         
10609         { } /* end */
10610 };
10611
10612 /*
10613  * generic initialization of ADC, input mixers and output mixers
10614  */
10615 static struct hda_verb alc861vd_volume_init_verbs[] = {
10616         /*
10617          * Unmute ADC0 and set the default input to mic-in
10618          */
10619         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10620         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10621
10622         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
10623          * the analog-loopback mixer widget
10624          */
10625         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10626         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10627         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10628         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10629         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10630         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10631
10632         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
10633         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10634         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10635         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10636         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
10637
10638         /*
10639          * Set up output mixers (0x02 - 0x05)
10640          */
10641         /* set vol=0 to output mixers */
10642         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10643         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10644         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10645         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10646
10647         /* set up input amps for analog loopback */
10648         /* Amp Indices: DAC = 0, mixer = 1 */
10649         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10650         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10651         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10652         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10653         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10654         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10655         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10656         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10657
10658         { }
10659 };
10660
10661 /*
10662  * 3-stack pin configuration:
10663  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
10664  */
10665 static struct hda_verb alc861vd_3stack_init_verbs[] = {
10666         /*
10667          * Set pin mode and muting
10668          */
10669         /* set front pin widgets 0x14 for output */
10670         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10671         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10672         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
10673
10674         /* Mic (rear) pin: input vref at 80% */
10675         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10676         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10677         /* Front Mic pin: input vref at 80% */
10678         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10679         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10680         /* Line In pin: input */
10681         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10682         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10683         /* Line-2 In: Headphone output (output 0 - 0x0c) */
10684         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10685         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10686         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10687         /* CD pin widget for input */
10688         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10689
10690         { }
10691 };
10692
10693 /*
10694  * 6-stack pin configuration:
10695  */
10696 static struct hda_verb alc861vd_6stack_init_verbs[] = {
10697         /*
10698          * Set pin mode and muting
10699          */
10700         /* set front pin widgets 0x14 for output */
10701         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10702         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10703         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
10704
10705         /* Rear Pin: output 1 (0x0d) */
10706         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10707         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10708         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
10709         /* CLFE Pin: output 2 (0x0e) */
10710         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10711         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10712         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
10713         /* Side Pin: output 3 (0x0f) */
10714         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10715         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10716         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
10717
10718         /* Mic (rear) pin: input vref at 80% */
10719         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10720         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10721         /* Front Mic pin: input vref at 80% */
10722         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10723         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10724         /* Line In pin: input */
10725         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10726         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10727         /* Line-2 In: Headphone output (output 0 - 0x0c) */
10728         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10729         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10730         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10731         /* CD pin widget for input */
10732         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10733
10734         { }
10735 };
10736
10737 static struct hda_verb alc861vd_eapd_verbs[] = {
10738         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
10739         { }
10740 };
10741
10742 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
10743         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10744         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10745         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10746         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10747         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT}, 
10748         {}
10749 };
10750
10751 /* toggle speaker-output according to the hp-jack state */
10752 static void alc861vd_lenovo_hp_automute(struct hda_codec *codec)
10753 {
10754         unsigned int present;
10755         unsigned char bits;
10756
10757         present = snd_hda_codec_read(codec, 0x1b, 0,
10758                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10759         bits = present ? HDA_AMP_MUTE : 0;
10760         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10761                                  HDA_AMP_MUTE, bits);
10762 }
10763
10764 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
10765 {
10766         unsigned int present;
10767         unsigned char bits;
10768
10769         present = snd_hda_codec_read(codec, 0x18, 0,
10770                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10771         bits = present ? HDA_AMP_MUTE : 0;
10772         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
10773                                  HDA_AMP_MUTE, bits);
10774 }
10775
10776 static void alc861vd_lenovo_automute(struct hda_codec *codec)
10777 {
10778         alc861vd_lenovo_hp_automute(codec);
10779         alc861vd_lenovo_mic_automute(codec);
10780 }
10781
10782 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
10783                                         unsigned int res)
10784 {
10785         switch (res >> 26) {
10786         case ALC880_HP_EVENT:
10787                 alc861vd_lenovo_hp_automute(codec);
10788                 break;
10789         case ALC880_MIC_EVENT:
10790                 alc861vd_lenovo_mic_automute(codec);
10791                 break;
10792         }
10793 }
10794
10795 static struct hda_verb alc861vd_dallas_verbs[] = {
10796         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10797         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10798         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10799         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10800
10801         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10802         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10803         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10804         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10805         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10806         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10807         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10808         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10809         
10810         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10811         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10812         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10813         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10814         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10815         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10816         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10817         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10818
10819         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
10820         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10821         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
10822         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10823         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10824         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10825         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10826         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10827
10828         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10829         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10830         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10831         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10832
10833         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10834         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},  
10835         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10836
10837         { } /* end */
10838 };
10839
10840 /* toggle speaker-output according to the hp-jack state */
10841 static void alc861vd_dallas_automute(struct hda_codec *codec)
10842 {
10843         unsigned int present;
10844
10845         present = snd_hda_codec_read(codec, 0x15, 0,
10846                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10847         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10848                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
10849 }
10850
10851 static void alc861vd_dallas_unsol_event(struct hda_codec *codec, unsigned int res)
10852 {
10853         if ((res >> 26) == ALC880_HP_EVENT)
10854                 alc861vd_dallas_automute(codec);
10855 }
10856
10857 #ifdef CONFIG_SND_HDA_POWER_SAVE
10858 #define alc861vd_loopbacks      alc880_loopbacks
10859 #endif
10860
10861 /* pcm configuration: identiacal with ALC880 */
10862 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
10863 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
10864 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
10865 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
10866
10867 /*
10868  * configuration and preset
10869  */
10870 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
10871         [ALC660VD_3ST]          = "3stack-660",
10872         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
10873         [ALC861VD_3ST]          = "3stack",
10874         [ALC861VD_3ST_DIG]      = "3stack-digout",
10875         [ALC861VD_6ST_DIG]      = "6stack-digout",
10876         [ALC861VD_LENOVO]       = "lenovo",
10877         [ALC861VD_DALLAS]       = "dallas",
10878         [ALC861VD_HP]           = "hp",
10879         [ALC861VD_AUTO]         = "auto",
10880 };
10881
10882 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
10883         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
10884         SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),
10885         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
10886         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
10887         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
10888
10889         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
10890         SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS),
10891         SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo 3000 C200", ALC861VD_LENOVO),
10892         SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo", ALC861VD_LENOVO),
10893         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
10894         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
10895         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
10896         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
10897         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
10898         {}
10899 };
10900
10901 static struct alc_config_preset alc861vd_presets[] = {
10902         [ALC660VD_3ST] = {
10903                 .mixers = { alc861vd_3st_mixer },
10904                 .init_verbs = { alc861vd_volume_init_verbs,
10905                                  alc861vd_3stack_init_verbs },
10906                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
10907                 .dac_nids = alc660vd_dac_nids,
10908                 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
10909                 .adc_nids = alc861vd_adc_nids,
10910                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
10911                 .channel_mode = alc861vd_3stack_2ch_modes,
10912                 .input_mux = &alc861vd_capture_source,
10913         },
10914         [ALC660VD_3ST_DIG] = {
10915                 .mixers = { alc861vd_3st_mixer },
10916                 .init_verbs = { alc861vd_volume_init_verbs,
10917                                  alc861vd_3stack_init_verbs },
10918                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
10919                 .dac_nids = alc660vd_dac_nids,
10920                 .dig_out_nid = ALC861VD_DIGOUT_NID,
10921                 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
10922                 .adc_nids = alc861vd_adc_nids,
10923                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
10924                 .channel_mode = alc861vd_3stack_2ch_modes,
10925                 .input_mux = &alc861vd_capture_source,
10926         },
10927         [ALC861VD_3ST] = {
10928                 .mixers = { alc861vd_3st_mixer },
10929                 .init_verbs = { alc861vd_volume_init_verbs,
10930                                  alc861vd_3stack_init_verbs },
10931                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
10932                 .dac_nids = alc861vd_dac_nids,
10933                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
10934                 .channel_mode = alc861vd_3stack_2ch_modes,
10935                 .input_mux = &alc861vd_capture_source,
10936         },
10937         [ALC861VD_3ST_DIG] = {
10938                 .mixers = { alc861vd_3st_mixer },
10939                 .init_verbs = { alc861vd_volume_init_verbs,
10940                                  alc861vd_3stack_init_verbs },
10941                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
10942                 .dac_nids = alc861vd_dac_nids,
10943                 .dig_out_nid = ALC861VD_DIGOUT_NID,
10944                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
10945                 .channel_mode = alc861vd_3stack_2ch_modes,
10946                 .input_mux = &alc861vd_capture_source,
10947         },
10948         [ALC861VD_6ST_DIG] = {
10949                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
10950                 .init_verbs = { alc861vd_volume_init_verbs,
10951                                 alc861vd_6stack_init_verbs },
10952                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
10953                 .dac_nids = alc861vd_dac_nids,
10954                 .dig_out_nid = ALC861VD_DIGOUT_NID,
10955                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
10956                 .channel_mode = alc861vd_6stack_modes,
10957                 .input_mux = &alc861vd_capture_source,
10958         },
10959         [ALC861VD_LENOVO] = {
10960                 .mixers = { alc861vd_lenovo_mixer },
10961                 .init_verbs = { alc861vd_volume_init_verbs,
10962                                 alc861vd_3stack_init_verbs,
10963                                 alc861vd_eapd_verbs,
10964                                 alc861vd_lenovo_unsol_verbs },
10965                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
10966                 .dac_nids = alc660vd_dac_nids,
10967                 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
10968                 .adc_nids = alc861vd_adc_nids,
10969                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
10970                 .channel_mode = alc861vd_3stack_2ch_modes,
10971                 .input_mux = &alc861vd_capture_source,
10972                 .unsol_event = alc861vd_lenovo_unsol_event,
10973                 .init_hook = alc861vd_lenovo_automute,
10974         },
10975         [ALC861VD_DALLAS] = {
10976                 .mixers = { alc861vd_dallas_mixer },
10977                 .init_verbs = { alc861vd_dallas_verbs },
10978                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
10979                 .dac_nids = alc861vd_dac_nids,
10980                 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
10981                 .adc_nids = alc861vd_adc_nids,
10982                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
10983                 .channel_mode = alc861vd_3stack_2ch_modes,
10984                 .input_mux = &alc861vd_dallas_capture_source,
10985                 .unsol_event = alc861vd_dallas_unsol_event,
10986                 .init_hook = alc861vd_dallas_automute,
10987         },
10988         [ALC861VD_HP] = {
10989                 .mixers = { alc861vd_hp_mixer },
10990                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
10991                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
10992                 .dac_nids = alc861vd_dac_nids,
10993                 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
10994                 .dig_out_nid = ALC861VD_DIGOUT_NID,
10995                 .adc_nids = alc861vd_adc_nids,
10996                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
10997                 .channel_mode = alc861vd_3stack_2ch_modes,
10998                 .input_mux = &alc861vd_hp_capture_source,
10999                 .unsol_event = alc861vd_dallas_unsol_event,
11000                 .init_hook = alc861vd_dallas_automute,
11001         },              
11002 };
11003
11004 /*
11005  * BIOS auto configuration
11006  */
11007 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
11008                                 hda_nid_t nid, int pin_type, int dac_idx)
11009 {
11010         /* set as output */
11011         snd_hda_codec_write(codec, nid, 0,
11012                                 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
11013         snd_hda_codec_write(codec, nid, 0,
11014                                 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
11015 }
11016
11017 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
11018 {
11019         struct alc_spec *spec = codec->spec;
11020         int i;
11021
11022         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
11023         for (i = 0; i <= HDA_SIDE; i++) {
11024                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
11025                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
11026                 if (nid)
11027                         alc861vd_auto_set_output_and_unmute(codec, nid,
11028                                                             pin_type, i);
11029         }
11030 }
11031
11032
11033 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
11034 {
11035         struct alc_spec *spec = codec->spec;
11036         hda_nid_t pin;
11037
11038         pin = spec->autocfg.hp_pins[0];
11039         if (pin) /* connect to front and  use dac 0 */
11040                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
11041 }
11042
11043 #define alc861vd_is_input_pin(nid)      alc880_is_input_pin(nid)
11044 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
11045
11046 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
11047 {
11048         struct alc_spec *spec = codec->spec;
11049         int i;
11050
11051         for (i = 0; i < AUTO_PIN_LAST; i++) {
11052                 hda_nid_t nid = spec->autocfg.input_pins[i];
11053                 if (alc861vd_is_input_pin(nid)) {
11054                         snd_hda_codec_write(codec, nid, 0,
11055                                         AC_VERB_SET_PIN_WIDGET_CONTROL,
11056                                         i <= AUTO_PIN_FRONT_MIC ?
11057                                                         PIN_VREF80 : PIN_IN);
11058                         if (nid != ALC861VD_PIN_CD_NID)
11059                                 snd_hda_codec_write(codec, nid, 0,
11060                                                 AC_VERB_SET_AMP_GAIN_MUTE,
11061                                                 AMP_OUT_MUTE);
11062                 }
11063         }
11064 }
11065
11066 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
11067 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
11068
11069 /* add playback controls from the parsed DAC table */
11070 /* Based on ALC880 version. But ALC861VD has separate,
11071  * different NIDs for mute/unmute switch and volume control */
11072 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
11073                                              const struct auto_pin_cfg *cfg)
11074 {
11075         char name[32];
11076         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
11077         hda_nid_t nid_v, nid_s;
11078         int i, err;
11079
11080         for (i = 0; i < cfg->line_outs; i++) {
11081                 if (!spec->multiout.dac_nids[i])
11082                         continue;
11083                 nid_v = alc861vd_idx_to_mixer_vol(
11084                                 alc880_dac_to_idx(
11085                                         spec->multiout.dac_nids[i]));
11086                 nid_s = alc861vd_idx_to_mixer_switch(
11087                                 alc880_dac_to_idx(
11088                                         spec->multiout.dac_nids[i]));
11089
11090                 if (i == 2) {
11091                         /* Center/LFE */
11092                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
11093                                           "Center Playback Volume",
11094                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
11095                                                               HDA_OUTPUT));
11096                         if (err < 0)
11097                                 return err;
11098                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
11099                                           "LFE Playback Volume",
11100                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
11101                                                               HDA_OUTPUT));
11102                         if (err < 0)
11103                                 return err;
11104                         err = add_control(spec, ALC_CTL_BIND_MUTE,
11105                                           "Center Playback Switch",
11106                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
11107                                                               HDA_INPUT));
11108                         if (err < 0)
11109                                 return err;
11110                         err = add_control(spec, ALC_CTL_BIND_MUTE,
11111                                           "LFE Playback Switch",
11112                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
11113                                                               HDA_INPUT));
11114                         if (err < 0)
11115                                 return err;
11116                 } else {
11117                         sprintf(name, "%s Playback Volume", chname[i]);
11118                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11119                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
11120                                                               HDA_OUTPUT));
11121                         if (err < 0)
11122                                 return err;
11123                         sprintf(name, "%s Playback Switch", chname[i]);
11124                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
11125                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
11126                                                               HDA_INPUT));
11127                         if (err < 0)
11128                                 return err;
11129                 }
11130         }
11131         return 0;
11132 }
11133
11134 /* add playback controls for speaker and HP outputs */
11135 /* Based on ALC880 version. But ALC861VD has separate,
11136  * different NIDs for mute/unmute switch and volume control */
11137 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
11138                                         hda_nid_t pin, const char *pfx)
11139 {
11140         hda_nid_t nid_v, nid_s;
11141         int err;
11142         char name[32];
11143
11144         if (!pin)
11145                 return 0;
11146
11147         if (alc880_is_fixed_pin(pin)) {
11148                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
11149                 /* specify the DAC as the extra output */
11150                 if (!spec->multiout.hp_nid)
11151                         spec->multiout.hp_nid = nid_v;
11152                 else
11153                         spec->multiout.extra_out_nid[0] = nid_v;
11154                 /* control HP volume/switch on the output mixer amp */
11155                 nid_v = alc861vd_idx_to_mixer_vol(
11156                                 alc880_fixed_pin_idx(pin));
11157                 nid_s = alc861vd_idx_to_mixer_switch(
11158                                 alc880_fixed_pin_idx(pin));
11159
11160                 sprintf(name, "%s Playback Volume", pfx);
11161                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11162                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
11163                 if (err < 0)
11164                         return err;
11165                 sprintf(name, "%s Playback Switch", pfx);
11166                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
11167                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
11168                 if (err < 0)
11169                         return err;
11170         } else if (alc880_is_multi_pin(pin)) {
11171                 /* set manual connection */
11172                 /* we have only a switch on HP-out PIN */
11173                 sprintf(name, "%s Playback Switch", pfx);
11174                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
11175                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
11176                 if (err < 0)
11177                         return err;
11178         }
11179         return 0;
11180 }
11181
11182 /* parse the BIOS configuration and set up the alc_spec
11183  * return 1 if successful, 0 if the proper config is not found,
11184  * or a negative error code
11185  * Based on ALC880 version - had to change it to override
11186  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
11187 static int alc861vd_parse_auto_config(struct hda_codec *codec)
11188 {
11189         struct alc_spec *spec = codec->spec;
11190         int err;
11191         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
11192
11193         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11194                                            alc861vd_ignore);
11195         if (err < 0)
11196                 return err;
11197         if (!spec->autocfg.line_outs)
11198                 return 0; /* can't find valid BIOS pin config */
11199
11200         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
11201         if (err < 0)
11202                 return err;
11203         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
11204         if (err < 0)
11205                 return err;
11206         err = alc861vd_auto_create_extra_out(spec,
11207                                              spec->autocfg.speaker_pins[0],
11208                                              "Speaker");
11209         if (err < 0)
11210                 return err;
11211         err = alc861vd_auto_create_extra_out(spec,
11212                                              spec->autocfg.hp_pins[0],
11213                                              "Headphone");
11214         if (err < 0)
11215                 return err;
11216         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
11217         if (err < 0)
11218                 return err;
11219
11220         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
11221
11222         if (spec->autocfg.dig_out_pin)
11223                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
11224
11225         if (spec->kctl_alloc)
11226                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
11227
11228         spec->init_verbs[spec->num_init_verbs++]
11229                 = alc861vd_volume_init_verbs;
11230
11231         spec->num_mux_defs = 1;
11232         spec->input_mux = &spec->private_imux;
11233
11234         err = alc_auto_add_mic_boost(codec);
11235         if (err < 0)
11236                 return err;
11237
11238         return 1;
11239 }
11240
11241 /* additional initialization for auto-configuration model */
11242 static void alc861vd_auto_init(struct hda_codec *codec)
11243 {
11244         alc861vd_auto_init_multi_out(codec);
11245         alc861vd_auto_init_hp_out(codec);
11246         alc861vd_auto_init_analog_input(codec);
11247 }
11248
11249 static int patch_alc861vd(struct hda_codec *codec)
11250 {
11251         struct alc_spec *spec;
11252         int err, board_config;
11253
11254         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
11255         if (spec == NULL)
11256                 return -ENOMEM;
11257
11258         codec->spec = spec;
11259
11260         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
11261                                                   alc861vd_models,
11262                                                   alc861vd_cfg_tbl);
11263
11264         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
11265                 printk(KERN_INFO "hda_codec: Unknown model for ALC660VD/"
11266                         "ALC861VD, trying auto-probe from BIOS...\n");
11267                 board_config = ALC861VD_AUTO;
11268         }
11269
11270         if (board_config == ALC861VD_AUTO) {
11271                 /* automatic parse from the BIOS config */
11272                 err = alc861vd_parse_auto_config(codec);
11273                 if (err < 0) {
11274                         alc_free(codec);
11275                         return err;
11276                 } else if (!err) {
11277                         printk(KERN_INFO
11278                                "hda_codec: Cannot set up configuration "
11279                                "from BIOS.  Using base mode...\n");
11280                         board_config = ALC861VD_3ST;
11281                 }
11282         }
11283
11284         if (board_config != ALC861VD_AUTO)
11285                 setup_preset(spec, &alc861vd_presets[board_config]);
11286
11287         spec->stream_name_analog = "ALC861VD Analog";
11288         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
11289         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
11290
11291         spec->stream_name_digital = "ALC861VD Digital";
11292         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
11293         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
11294
11295         spec->adc_nids = alc861vd_adc_nids;
11296         spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
11297
11298         spec->mixers[spec->num_mixers] = alc861vd_capture_mixer;
11299         spec->num_mixers++;
11300
11301         codec->patch_ops = alc_patch_ops;
11302
11303         if (board_config == ALC861VD_AUTO)
11304                 spec->init_hook = alc861vd_auto_init;
11305 #ifdef CONFIG_SND_HDA_POWER_SAVE
11306         if (!spec->loopback.amplist)
11307                 spec->loopback.amplist = alc861vd_loopbacks;
11308 #endif
11309
11310         return 0;
11311 }
11312
11313 /*
11314  * ALC662 support
11315  *
11316  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
11317  * configuration.  Each pin widget can choose any input DACs and a mixer.
11318  * Each ADC is connected from a mixer of all inputs.  This makes possible
11319  * 6-channel independent captures.
11320  *
11321  * In addition, an independent DAC for the multi-playback (not used in this
11322  * driver yet).
11323  */
11324 #define ALC662_DIGOUT_NID       0x06
11325 #define ALC662_DIGIN_NID        0x0a
11326
11327 static hda_nid_t alc662_dac_nids[4] = {
11328         /* front, rear, clfe, rear_surr */
11329         0x02, 0x03, 0x04
11330 };
11331
11332 static hda_nid_t alc662_adc_nids[1] = {
11333         /* ADC1-2 */
11334         0x09,
11335 };
11336 /* input MUX */
11337 /* FIXME: should be a matrix-type input source selection */
11338
11339 static struct hda_input_mux alc662_capture_source = {
11340         .num_items = 4,
11341         .items = {
11342                 { "Mic", 0x0 },
11343                 { "Front Mic", 0x1 },
11344                 { "Line", 0x2 },
11345                 { "CD", 0x4 },
11346         },
11347 };
11348
11349 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
11350         .num_items = 2,
11351         .items = {
11352                 { "Mic", 0x1 },
11353                 { "Line", 0x2 },
11354         },
11355 };
11356 #define alc662_mux_enum_info alc_mux_enum_info
11357 #define alc662_mux_enum_get alc_mux_enum_get
11358
11359 static int alc662_mux_enum_put(struct snd_kcontrol *kcontrol,
11360                                struct snd_ctl_elem_value *ucontrol)
11361 {
11362         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
11363         struct alc_spec *spec = codec->spec;
11364         const struct hda_input_mux *imux = spec->input_mux;
11365         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
11366         static hda_nid_t capture_mixers[2] = { 0x23, 0x22 };
11367         hda_nid_t nid = capture_mixers[adc_idx];
11368         unsigned int *cur_val = &spec->cur_mux[adc_idx];
11369         unsigned int i, idx;
11370
11371         idx = ucontrol->value.enumerated.item[0];
11372         if (idx >= imux->num_items)
11373                 idx = imux->num_items - 1;
11374         if (*cur_val == idx)
11375                 return 0;
11376         for (i = 0; i < imux->num_items; i++) {
11377                 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
11378                 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
11379                                          imux->items[i].index,
11380                                          HDA_AMP_MUTE, v);
11381         }
11382         *cur_val = idx;
11383         return 1;
11384 }
11385 /*
11386  * 2ch mode
11387  */
11388 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
11389         { 2, NULL }
11390 };
11391
11392 /*
11393  * 2ch mode
11394  */
11395 static struct hda_verb alc662_3ST_ch2_init[] = {
11396         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
11397         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
11398         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
11399         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
11400         { } /* end */
11401 };
11402
11403 /*
11404  * 6ch mode
11405  */
11406 static struct hda_verb alc662_3ST_ch6_init[] = {
11407         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11408         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11409         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
11410         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11411         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11412         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
11413         { } /* end */
11414 };
11415
11416 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
11417         { 2, alc662_3ST_ch2_init },
11418         { 6, alc662_3ST_ch6_init },
11419 };
11420
11421 /*
11422  * 2ch mode
11423  */
11424 static struct hda_verb alc662_sixstack_ch6_init[] = {
11425         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11426         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11427         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11428         { } /* end */
11429 };
11430
11431 /*
11432  * 6ch mode
11433  */
11434 static struct hda_verb alc662_sixstack_ch8_init[] = {
11435         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11436         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11437         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11438         { } /* end */
11439 };
11440
11441 static struct hda_channel_mode alc662_5stack_modes[2] = {
11442         { 2, alc662_sixstack_ch6_init },
11443         { 6, alc662_sixstack_ch8_init },
11444 };
11445
11446 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
11447  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
11448  */
11449
11450 static struct snd_kcontrol_new alc662_base_mixer[] = {
11451         /* output mixer control */
11452         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
11453         HDA_CODEC_MUTE("Front Playback Switch", 0x02, 0x0, HDA_OUTPUT),
11454         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
11455         HDA_CODEC_MUTE("Surround Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11456         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
11457         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
11458         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
11459         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
11460         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
11461
11462         /*Input mixer control */
11463         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
11464         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
11465         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
11466         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
11467         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
11468         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
11469         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
11470         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
11471
11472         /* Capture mixer control */
11473         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
11474         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
11475         {
11476                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11477                 .name = "Capture Source",
11478                 .count = 1,
11479                 .info = alc_mux_enum_info,
11480                 .get = alc_mux_enum_get,
11481                 .put = alc_mux_enum_put,
11482         },
11483         { } /* end */
11484 };
11485
11486 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
11487         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11488         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
11489         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
11490         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
11491         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
11492         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
11493         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11494         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11495         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11496         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
11497         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
11498         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
11499         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
11500         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
11501         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
11502         {
11503                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11504                 /* .name = "Capture Source", */
11505                 .name = "Input Source",
11506                 .count = 1,
11507                 .info = alc662_mux_enum_info,
11508                 .get = alc662_mux_enum_get,
11509                 .put = alc662_mux_enum_put,
11510         },
11511         { } /* end */
11512 };
11513
11514 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
11515         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11516         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
11517         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11518         HDA_BIND_MUTE("Surround Playback Switch", 0x03, 2, HDA_INPUT),
11519         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
11520         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
11521         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
11522         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
11523         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
11524         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
11525         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
11526         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
11527         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11528         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11529         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11530         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
11531         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
11532         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
11533         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
11534         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
11535         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
11536         {
11537                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11538                 /* .name = "Capture Source", */
11539                 .name = "Input Source",
11540                 .count = 1,
11541                 .info = alc662_mux_enum_info,
11542                 .get = alc662_mux_enum_get,
11543                 .put = alc662_mux_enum_put,
11544         },
11545         { } /* end */
11546 };
11547
11548 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
11549         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11550         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
11551         HDA_CODEC_VOLUME("iSpeaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11552         HDA_BIND_MUTE("iSpeaker Playback Switch", 0x03, 2, HDA_INPUT),
11553         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
11554         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
11555         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11556         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
11557         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
11558         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
11559         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
11560         {
11561                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11562                 /* .name = "Capture Source", */
11563                 .name = "Input Source",
11564                 .count = 1,
11565                 .info = alc662_mux_enum_info,
11566                 .get = alc662_mux_enum_get,
11567                 .put = alc662_mux_enum_put,
11568         },
11569         { } /* end */
11570 };
11571
11572 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
11573         {
11574                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11575                 .name = "Channel Mode",
11576                 .info = alc_ch_mode_info,
11577                 .get = alc_ch_mode_get,
11578                 .put = alc_ch_mode_put,
11579         },
11580         { } /* end */
11581 };
11582
11583 static struct hda_verb alc662_init_verbs[] = {
11584         /* ADC: mute amp left and right */
11585         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11586         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
11587         /* Front mixer: unmute input/output amp left and right (volume = 0) */
11588
11589         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11590         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11591         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11592         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11593         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11594
11595         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11596         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11597         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11598         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11599         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11600         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11601
11602         /* Front Pin: output 0 (0x0c) */
11603         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11604         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11605
11606         /* Rear Pin: output 1 (0x0d) */
11607         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11608         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11609
11610         /* CLFE Pin: output 2 (0x0e) */
11611         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11612         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11613
11614         /* Mic (rear) pin: input vref at 80% */
11615         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11616         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11617         /* Front Mic pin: input vref at 80% */
11618         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11619         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11620         /* Line In pin: input */
11621         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11622         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11623         /* Line-2 In: Headphone output (output 0 - 0x0c) */
11624         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11625         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11626         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
11627         /* CD pin widget for input */
11628         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11629
11630         /* FIXME: use matrix-type input source selection */
11631         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
11632         /* Input mixer */
11633         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11634         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11635         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11636         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
11637         { }
11638 };
11639
11640 static struct hda_verb alc662_sue_init_verbs[] = {
11641         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
11642         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
11643         {}
11644 };
11645
11646 /*
11647  * generic initialization of ADC, input mixers and output mixers
11648  */
11649 static struct hda_verb alc662_auto_init_verbs[] = {
11650         /*
11651          * Unmute ADC and set the default input to mic-in
11652          */
11653         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
11654         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11655
11656         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
11657          * mixer widget
11658          * Note: PASD motherboards uses the Line In 2 as the input for front
11659          * panel mic (mic 2)
11660          */
11661         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11662         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11663         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11664         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11665         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11666         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11667
11668         /*
11669          * Set up output mixers (0x0c - 0x0f)
11670          */
11671         /* set vol=0 to output mixers */
11672         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11673         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11674         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11675
11676         /* set up input amps for analog loopback */
11677         /* Amp Indices: DAC = 0, mixer = 1 */
11678         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11679         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11680         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11681         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11682         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11683         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11684
11685
11686         /* FIXME: use matrix-type input source selection */
11687         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
11688         /* Input mixer */
11689         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11690         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11691         { }
11692 };
11693
11694 /* capture mixer elements */
11695 static struct snd_kcontrol_new alc662_capture_mixer[] = {
11696         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
11697         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
11698         {
11699                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11700                 /* The multiple "Capture Source" controls confuse alsamixer
11701                  * So call somewhat different..
11702                  * FIXME: the controls appear in the "playback" view!
11703                  */
11704                 /* .name = "Capture Source", */
11705                 .name = "Input Source",
11706                 .count = 1,
11707                 .info = alc882_mux_enum_info,
11708                 .get = alc882_mux_enum_get,
11709                 .put = alc882_mux_enum_put,
11710         },
11711         { } /* end */
11712 };
11713
11714 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
11715 {
11716         unsigned int present;
11717         unsigned char bits;
11718
11719         present = snd_hda_codec_read(codec, 0x14, 0,
11720                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11721         bits = present ? HDA_AMP_MUTE : 0;
11722         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
11723                                  HDA_AMP_MUTE, bits);
11724 }
11725
11726 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
11727 {
11728         unsigned int present;
11729         unsigned char bits;
11730
11731         present = snd_hda_codec_read(codec, 0x1b, 0,
11732                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11733         bits = present ? HDA_AMP_MUTE : 0;
11734         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
11735                                  HDA_AMP_MUTE, bits);
11736         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
11737                                  HDA_AMP_MUTE, bits);
11738 }
11739
11740 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
11741                                            unsigned int res)
11742 {
11743         if ((res >> 26) == ALC880_HP_EVENT)
11744                 alc662_lenovo_101e_all_automute(codec);
11745         if ((res >> 26) == ALC880_FRONT_EVENT)
11746                 alc662_lenovo_101e_ispeaker_automute(codec);
11747 }
11748
11749 #ifdef CONFIG_SND_HDA_POWER_SAVE
11750 #define alc662_loopbacks        alc880_loopbacks
11751 #endif
11752
11753
11754 /* pcm configuration: identiacal with ALC880 */
11755 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
11756 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
11757 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
11758 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
11759
11760 /*
11761  * configuration and preset
11762  */
11763 static const char *alc662_models[ALC662_MODEL_LAST] = {
11764         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
11765         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
11766         [ALC662_3ST_6ch]        = "3stack-6ch",
11767         [ALC662_5ST_DIG]        = "6stack-dig",
11768         [ALC662_LENOVO_101E]    = "lenovo-101e",
11769         [ALC662_AUTO]           = "auto",
11770 };
11771
11772 static struct snd_pci_quirk alc662_cfg_tbl[] = {
11773         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
11774         {}
11775 };
11776
11777 static struct alc_config_preset alc662_presets[] = {
11778         [ALC662_3ST_2ch_DIG] = {
11779                 .mixers = { alc662_3ST_2ch_mixer },
11780                 .init_verbs = { alc662_init_verbs },
11781                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
11782                 .dac_nids = alc662_dac_nids,
11783                 .dig_out_nid = ALC662_DIGOUT_NID,
11784                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
11785                 .adc_nids = alc662_adc_nids,
11786                 .dig_in_nid = ALC662_DIGIN_NID,
11787                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
11788                 .channel_mode = alc662_3ST_2ch_modes,
11789                 .input_mux = &alc662_capture_source,
11790         },
11791         [ALC662_3ST_6ch_DIG] = {
11792                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
11793                 .init_verbs = { alc662_init_verbs },
11794                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
11795                 .dac_nids = alc662_dac_nids,
11796                 .dig_out_nid = ALC662_DIGOUT_NID,
11797                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
11798                 .adc_nids = alc662_adc_nids,
11799                 .dig_in_nid = ALC662_DIGIN_NID,
11800                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
11801                 .channel_mode = alc662_3ST_6ch_modes,
11802                 .need_dac_fix = 1,
11803                 .input_mux = &alc662_capture_source,
11804         },
11805         [ALC662_3ST_6ch] = {
11806                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
11807                 .init_verbs = { alc662_init_verbs },
11808                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
11809                 .dac_nids = alc662_dac_nids,
11810                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
11811                 .adc_nids = alc662_adc_nids,
11812                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
11813                 .channel_mode = alc662_3ST_6ch_modes,
11814                 .need_dac_fix = 1,
11815                 .input_mux = &alc662_capture_source,
11816         },
11817         [ALC662_5ST_DIG] = {
11818                 .mixers = { alc662_base_mixer, alc662_chmode_mixer },
11819                 .init_verbs = { alc662_init_verbs },
11820                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
11821                 .dac_nids = alc662_dac_nids,
11822                 .dig_out_nid = ALC662_DIGOUT_NID,
11823                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
11824                 .adc_nids = alc662_adc_nids,
11825                 .dig_in_nid = ALC662_DIGIN_NID,
11826                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
11827                 .channel_mode = alc662_5stack_modes,
11828                 .input_mux = &alc662_capture_source,
11829         },
11830         [ALC662_LENOVO_101E] = {
11831                 .mixers = { alc662_lenovo_101e_mixer },
11832                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
11833                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
11834                 .dac_nids = alc662_dac_nids,
11835                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
11836                 .adc_nids = alc662_adc_nids,
11837                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
11838                 .channel_mode = alc662_3ST_2ch_modes,
11839                 .input_mux = &alc662_lenovo_101e_capture_source,
11840                 .unsol_event = alc662_lenovo_101e_unsol_event,
11841                 .init_hook = alc662_lenovo_101e_all_automute,
11842         },
11843
11844 };
11845
11846
11847 /*
11848  * BIOS auto configuration
11849  */
11850
11851 /* add playback controls from the parsed DAC table */
11852 static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec,
11853                                              const struct auto_pin_cfg *cfg)
11854 {
11855         char name[32];
11856         static const char *chname[4] = {
11857                 "Front", "Surround", NULL /*CLFE*/, "Side"
11858         };
11859         hda_nid_t nid;
11860         int i, err;
11861
11862         for (i = 0; i < cfg->line_outs; i++) {
11863                 if (!spec->multiout.dac_nids[i])
11864                         continue;
11865                 nid = alc880_idx_to_mixer(i);
11866                 if (i == 2) {
11867                         /* Center/LFE */
11868                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
11869                                           "Center Playback Volume",
11870                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
11871                                                               HDA_OUTPUT));
11872                         if (err < 0)
11873                                 return err;
11874                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
11875                                           "LFE Playback Volume",
11876                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
11877                                                               HDA_OUTPUT));
11878                         if (err < 0)
11879                                 return err;
11880                         err = add_control(spec, ALC_CTL_BIND_MUTE,
11881                                           "Center Playback Switch",
11882                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
11883                                                               HDA_INPUT));
11884                         if (err < 0)
11885                                 return err;
11886                         err = add_control(spec, ALC_CTL_BIND_MUTE,
11887                                           "LFE Playback Switch",
11888                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
11889                                                               HDA_INPUT));
11890                         if (err < 0)
11891                                 return err;
11892                 } else {
11893                         sprintf(name, "%s Playback Volume", chname[i]);
11894                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11895                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
11896                                                               HDA_OUTPUT));
11897                         if (err < 0)
11898                                 return err;
11899                         sprintf(name, "%s Playback Switch", chname[i]);
11900                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
11901                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
11902                                                               HDA_INPUT));
11903                         if (err < 0)
11904                                 return err;
11905                 }
11906         }
11907         return 0;
11908 }
11909
11910 /* add playback controls for speaker and HP outputs */
11911 static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
11912                                         const char *pfx)
11913 {
11914         hda_nid_t nid;
11915         int err;
11916         char name[32];
11917
11918         if (!pin)
11919                 return 0;
11920
11921         if (alc880_is_fixed_pin(pin)) {
11922                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
11923                 /* printk("DAC nid=%x\n",nid); */
11924                 /* specify the DAC as the extra output */
11925                 if (!spec->multiout.hp_nid)
11926                         spec->multiout.hp_nid = nid;
11927                 else
11928                         spec->multiout.extra_out_nid[0] = nid;
11929                 /* control HP volume/switch on the output mixer amp */
11930                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
11931                 sprintf(name, "%s Playback Volume", pfx);
11932                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11933                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
11934                 if (err < 0)
11935                         return err;
11936                 sprintf(name, "%s Playback Switch", pfx);
11937                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
11938                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
11939                 if (err < 0)
11940                         return err;
11941         } else if (alc880_is_multi_pin(pin)) {
11942                 /* set manual connection */
11943                 /* we have only a switch on HP-out PIN */
11944                 sprintf(name, "%s Playback Switch", pfx);
11945                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
11946                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
11947                 if (err < 0)
11948                         return err;
11949         }
11950         return 0;
11951 }
11952
11953 /* create playback/capture controls for input pins */
11954 static int alc662_auto_create_analog_input_ctls(struct alc_spec *spec,
11955                                                 const struct auto_pin_cfg *cfg)
11956 {
11957         struct hda_input_mux *imux = &spec->private_imux;
11958         int i, err, idx;
11959
11960         for (i = 0; i < AUTO_PIN_LAST; i++) {
11961                 if (alc880_is_input_pin(cfg->input_pins[i])) {
11962                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
11963                         err = new_analog_input(spec, cfg->input_pins[i],
11964                                                auto_pin_cfg_labels[i],
11965                                                idx, 0x0b);
11966                         if (err < 0)
11967                                 return err;
11968                         imux->items[imux->num_items].label =
11969                                 auto_pin_cfg_labels[i];
11970                         imux->items[imux->num_items].index =
11971                                 alc880_input_pin_idx(cfg->input_pins[i]);
11972                         imux->num_items++;
11973                 }
11974         }
11975         return 0;
11976 }
11977
11978 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
11979                                               hda_nid_t nid, int pin_type,
11980                                               int dac_idx)
11981 {
11982         /* set as output */
11983         snd_hda_codec_write(codec, nid, 0,
11984                             AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
11985         snd_hda_codec_write(codec, nid, 0,
11986                             AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
11987         /* need the manual connection? */
11988         if (alc880_is_multi_pin(nid)) {
11989                 struct alc_spec *spec = codec->spec;
11990                 int idx = alc880_multi_pin_idx(nid);
11991                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
11992                                     AC_VERB_SET_CONNECT_SEL,
11993                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
11994         }
11995 }
11996
11997 static void alc662_auto_init_multi_out(struct hda_codec *codec)
11998 {
11999         struct alc_spec *spec = codec->spec;
12000         int i;
12001
12002         for (i = 0; i <= HDA_SIDE; i++) {
12003                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
12004                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
12005                 if (nid)
12006                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
12007                                                           i);
12008         }
12009 }
12010
12011 static void alc662_auto_init_hp_out(struct hda_codec *codec)
12012 {
12013         struct alc_spec *spec = codec->spec;
12014         hda_nid_t pin;
12015
12016         pin = spec->autocfg.hp_pins[0];
12017         if (pin) /* connect to front */
12018                 /* use dac 0 */
12019                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
12020 }
12021
12022 #define alc662_is_input_pin(nid)        alc880_is_input_pin(nid)
12023 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
12024
12025 static void alc662_auto_init_analog_input(struct hda_codec *codec)
12026 {
12027         struct alc_spec *spec = codec->spec;
12028         int i;
12029
12030         for (i = 0; i < AUTO_PIN_LAST; i++) {
12031                 hda_nid_t nid = spec->autocfg.input_pins[i];
12032                 if (alc662_is_input_pin(nid)) {
12033                         snd_hda_codec_write(codec, nid, 0,
12034                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
12035                                             (i <= AUTO_PIN_FRONT_MIC ?
12036                                              PIN_VREF80 : PIN_IN));
12037                         if (nid != ALC662_PIN_CD_NID)
12038                                 snd_hda_codec_write(codec, nid, 0,
12039                                                     AC_VERB_SET_AMP_GAIN_MUTE,
12040                                                     AMP_OUT_MUTE);
12041                 }
12042         }
12043 }
12044
12045 static int alc662_parse_auto_config(struct hda_codec *codec)
12046 {
12047         struct alc_spec *spec = codec->spec;
12048         int err;
12049         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
12050
12051         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
12052                                            alc662_ignore);
12053         if (err < 0)
12054                 return err;
12055         if (!spec->autocfg.line_outs)
12056                 return 0; /* can't find valid BIOS pin config */
12057
12058         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
12059         if (err < 0)
12060                 return err;
12061         err = alc662_auto_create_multi_out_ctls(spec, &spec->autocfg);
12062         if (err < 0)
12063                 return err;
12064         err = alc662_auto_create_extra_out(spec,
12065                                            spec->autocfg.speaker_pins[0],
12066                                            "Speaker");
12067         if (err < 0)
12068                 return err;
12069         err = alc662_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
12070                                            "Headphone");
12071         if (err < 0)
12072                 return err;
12073         err = alc662_auto_create_analog_input_ctls(spec, &spec->autocfg);
12074         if (err < 0)
12075                 return err;
12076
12077         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
12078
12079         if (spec->autocfg.dig_out_pin)
12080                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
12081
12082         if (spec->kctl_alloc)
12083                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
12084
12085         spec->num_mux_defs = 1;
12086         spec->input_mux = &spec->private_imux;
12087         
12088         spec->init_verbs[spec->num_init_verbs++] = alc662_auto_init_verbs;
12089         spec->mixers[spec->num_mixers] = alc662_capture_mixer;
12090         spec->num_mixers++;
12091         return 1;
12092 }
12093
12094 /* additional initialization for auto-configuration model */
12095 static void alc662_auto_init(struct hda_codec *codec)
12096 {
12097         alc662_auto_init_multi_out(codec);
12098         alc662_auto_init_hp_out(codec);
12099         alc662_auto_init_analog_input(codec);
12100 }
12101
12102 static int patch_alc662(struct hda_codec *codec)
12103 {
12104         struct alc_spec *spec;
12105         int err, board_config;
12106
12107         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
12108         if (!spec)
12109                 return -ENOMEM;
12110
12111         codec->spec = spec;
12112
12113         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
12114                                                   alc662_models,
12115                                                   alc662_cfg_tbl);
12116         if (board_config < 0) {
12117                 printk(KERN_INFO "hda_codec: Unknown model for ALC662, "
12118                        "trying auto-probe from BIOS...\n");
12119                 board_config = ALC662_AUTO;
12120         }
12121
12122         if (board_config == ALC662_AUTO) {
12123                 /* automatic parse from the BIOS config */
12124                 err = alc662_parse_auto_config(codec);
12125                 if (err < 0) {
12126                         alc_free(codec);
12127                         return err;
12128                 } else if (!err) {
12129                         printk(KERN_INFO
12130                                "hda_codec: Cannot set up configuration "
12131                                "from BIOS.  Using base mode...\n");
12132                         board_config = ALC662_3ST_2ch_DIG;
12133                 }
12134         }
12135
12136         if (board_config != ALC662_AUTO)
12137                 setup_preset(spec, &alc662_presets[board_config]);
12138
12139         spec->stream_name_analog = "ALC662 Analog";
12140         spec->stream_analog_playback = &alc662_pcm_analog_playback;
12141         spec->stream_analog_capture = &alc662_pcm_analog_capture;
12142
12143         spec->stream_name_digital = "ALC662 Digital";
12144         spec->stream_digital_playback = &alc662_pcm_digital_playback;
12145         spec->stream_digital_capture = &alc662_pcm_digital_capture;
12146
12147         if (!spec->adc_nids && spec->input_mux) {
12148                 spec->adc_nids = alc662_adc_nids;
12149                 spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
12150         }
12151
12152         codec->patch_ops = alc_patch_ops;
12153         if (board_config == ALC662_AUTO)
12154                 spec->init_hook = alc662_auto_init;
12155 #ifdef CONFIG_SND_HDA_POWER_SAVE
12156         if (!spec->loopback.amplist)
12157                 spec->loopback.amplist = alc662_loopbacks;
12158 #endif
12159
12160         return 0;
12161 }
12162
12163 /*
12164  * patch entries
12165  */
12166 struct hda_codec_preset snd_hda_preset_realtek[] = {
12167         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
12168         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
12169         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
12170         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
12171           .patch = patch_alc861 },
12172         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
12173         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
12174         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
12175         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
12176           .patch = patch_alc883 },
12177         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
12178           .patch = patch_alc662 },
12179         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
12180         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
12181         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
12182         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
12183         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
12184         {} /* terminator */
12185 };