]> err.no Git - linux-2.6/blob - sound/pci/hda/patch_realtek.c
Merge branch 'release' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux...
[linux-2.6] / sound / pci / hda / patch_realtek.c
1 /*
2  * Universal Interface for Intel High Definition Audio Codec
3  *
4  * HD audio interface patch for ALC 260/880/882 codecs
5  *
6  * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7  *                    PeiSen Hou <pshou@realtek.com.tw>
8  *                    Takashi Iwai <tiwai@suse.de>
9  *                    Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
10  *
11  *  This driver is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This driver is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
24  */
25
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/slab.h>
29 #include <linux/pci.h>
30 #include <sound/core.h>
31 #include "hda_codec.h"
32 #include "hda_local.h"
33 #include "hda_patch.h"
34
35 #define ALC880_FRONT_EVENT              0x01
36 #define ALC880_DCVOL_EVENT              0x02
37 #define ALC880_HP_EVENT                 0x04
38 #define ALC880_MIC_EVENT                0x08
39
40 /* ALC880 board config type */
41 enum {
42         ALC880_3ST,
43         ALC880_3ST_DIG,
44         ALC880_5ST,
45         ALC880_5ST_DIG,
46         ALC880_W810,
47         ALC880_Z71V,
48         ALC880_6ST,
49         ALC880_6ST_DIG,
50         ALC880_F1734,
51         ALC880_ASUS,
52         ALC880_ASUS_DIG,
53         ALC880_ASUS_W1V,
54         ALC880_ASUS_DIG2,
55         ALC880_FUJITSU,
56         ALC880_UNIWILL_DIG,
57         ALC880_UNIWILL,
58         ALC880_UNIWILL_P53,
59         ALC880_CLEVO,
60         ALC880_TCL_S700,
61         ALC880_LG,
62         ALC880_LG_LW,
63         ALC880_MEDION_RIM,
64 #ifdef CONFIG_SND_DEBUG
65         ALC880_TEST,
66 #endif
67         ALC880_AUTO,
68         ALC880_MODEL_LAST /* last tag */
69 };
70
71 /* ALC260 models */
72 enum {
73         ALC260_BASIC,
74         ALC260_HP,
75         ALC260_HP_3013,
76         ALC260_FUJITSU_S702X,
77         ALC260_ACER,
78         ALC260_WILL,
79         ALC260_REPLACER_672V,
80 #ifdef CONFIG_SND_DEBUG
81         ALC260_TEST,
82 #endif
83         ALC260_AUTO,
84         ALC260_MODEL_LAST /* last tag */
85 };
86
87 /* ALC262 models */
88 enum {
89         ALC262_BASIC,
90         ALC262_HIPPO,
91         ALC262_HIPPO_1,
92         ALC262_FUJITSU,
93         ALC262_HP_BPC,
94         ALC262_HP_BPC_D7000_WL,
95         ALC262_HP_BPC_D7000_WF,
96         ALC262_HP_TC_T5735,
97         ALC262_HP_RP5700,
98         ALC262_BENQ_ED8,
99         ALC262_SONY_ASSAMD,
100         ALC262_BENQ_T31,
101         ALC262_ULTRA,
102         ALC262_LENOVO_3000,
103         ALC262_AUTO,
104         ALC262_MODEL_LAST /* last tag */
105 };
106
107 /* ALC268 models */
108 enum {
109         ALC267_QUANTA_IL1,
110         ALC268_3ST,
111         ALC268_TOSHIBA,
112         ALC268_ACER,
113         ALC268_DELL,
114         ALC268_ZEPTO,
115 #ifdef CONFIG_SND_DEBUG
116         ALC268_TEST,
117 #endif
118         ALC268_AUTO,
119         ALC268_MODEL_LAST /* last tag */
120 };
121
122 /* ALC269 models */
123 enum {
124         ALC269_BASIC,
125         ALC269_AUTO,
126         ALC269_MODEL_LAST /* last tag */
127 };
128
129 /* ALC861 models */
130 enum {
131         ALC861_3ST,
132         ALC660_3ST,
133         ALC861_3ST_DIG,
134         ALC861_6ST_DIG,
135         ALC861_UNIWILL_M31,
136         ALC861_TOSHIBA,
137         ALC861_ASUS,
138         ALC861_ASUS_LAPTOP,
139         ALC861_AUTO,
140         ALC861_MODEL_LAST,
141 };
142
143 /* ALC861-VD models */
144 enum {
145         ALC660VD_3ST,
146         ALC660VD_3ST_DIG,
147         ALC861VD_3ST,
148         ALC861VD_3ST_DIG,
149         ALC861VD_6ST_DIG,
150         ALC861VD_LENOVO,
151         ALC861VD_DALLAS,
152         ALC861VD_HP,
153         ALC861VD_AUTO,
154         ALC861VD_MODEL_LAST,
155 };
156
157 /* ALC662 models */
158 enum {
159         ALC662_3ST_2ch_DIG,
160         ALC662_3ST_6ch_DIG,
161         ALC662_3ST_6ch,
162         ALC662_5ST_DIG,
163         ALC662_LENOVO_101E,
164         ALC662_ASUS_EEEPC_P701,
165         ALC662_ASUS_EEEPC_EP20,
166         ALC662_AUTO,
167         ALC662_MODEL_LAST,
168 };
169
170 /* ALC882 models */
171 enum {
172         ALC882_3ST_DIG,
173         ALC882_6ST_DIG,
174         ALC882_ARIMA,
175         ALC882_W2JC,
176         ALC882_TARGA,
177         ALC882_ASUS_A7J,
178         ALC882_ASUS_A7M,
179         ALC885_MACPRO,
180         ALC885_MBP3,
181         ALC885_IMAC24,
182         ALC882_AUTO,
183         ALC882_MODEL_LAST,
184 };
185
186 /* ALC883 models */
187 enum {
188         ALC883_3ST_2ch_DIG,
189         ALC883_3ST_6ch_DIG,
190         ALC883_3ST_6ch,
191         ALC883_6ST_DIG,
192         ALC883_TARGA_DIG,
193         ALC883_TARGA_2ch_DIG,
194         ALC883_ACER,
195         ALC883_ACER_ASPIRE,
196         ALC883_MEDION,
197         ALC883_MEDION_MD2,      
198         ALC883_LAPTOP_EAPD,
199         ALC883_LENOVO_101E_2ch,
200         ALC883_LENOVO_NB0763,
201         ALC888_LENOVO_MS7195_DIG,
202         ALC883_HAIER_W66,               
203         ALC888_3ST_HP,
204         ALC888_6ST_DELL,
205         ALC883_MITAC,
206         ALC883_CLEVO_M720,
207         ALC883_FUJITSU_PI2515,
208         ALC883_AUTO,
209         ALC883_MODEL_LAST,
210 };
211
212 /* for GPIO Poll */
213 #define GPIO_MASK       0x03
214
215 struct alc_spec {
216         /* codec parameterization */
217         struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
218         unsigned int num_mixers;
219
220         const struct hda_verb *init_verbs[5];   /* initialization verbs
221                                                  * don't forget NULL
222                                                  * termination!
223                                                  */
224         unsigned int num_init_verbs;
225
226         char *stream_name_analog;       /* analog PCM stream */
227         struct hda_pcm_stream *stream_analog_playback;
228         struct hda_pcm_stream *stream_analog_capture;
229         struct hda_pcm_stream *stream_analog_alt_playback;
230         struct hda_pcm_stream *stream_analog_alt_capture;
231
232         char *stream_name_digital;      /* digital PCM stream */
233         struct hda_pcm_stream *stream_digital_playback;
234         struct hda_pcm_stream *stream_digital_capture;
235
236         /* playback */
237         struct hda_multi_out multiout;  /* playback set-up
238                                          * max_channels, dacs must be set
239                                          * dig_out_nid and hp_nid are optional
240                                          */
241         hda_nid_t alt_dac_nid;
242
243         /* capture */
244         unsigned int num_adc_nids;
245         hda_nid_t *adc_nids;
246         hda_nid_t *capsrc_nids;
247         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
248
249         /* capture source */
250         unsigned int num_mux_defs;
251         const struct hda_input_mux *input_mux;
252         unsigned int cur_mux[3];
253
254         /* channel model */
255         const struct hda_channel_mode *channel_mode;
256         int num_channel_mode;
257         int need_dac_fix;
258
259         /* PCM information */
260         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
261
262         /* dynamic controls, init_verbs and input_mux */
263         struct auto_pin_cfg autocfg;
264         unsigned int num_kctl_alloc, num_kctl_used;
265         struct snd_kcontrol_new *kctl_alloc;
266         struct hda_input_mux private_imux;
267         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
268
269         /* hooks */
270         void (*init_hook)(struct hda_codec *codec);
271         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
272
273         /* for pin sensing */
274         unsigned int sense_updated: 1;
275         unsigned int jack_present: 1;
276         unsigned int master_sw: 1;
277
278         /* for virtual master */
279         hda_nid_t vmaster_nid;
280 #ifdef CONFIG_SND_HDA_POWER_SAVE
281         struct hda_loopback_check loopback;
282 #endif
283 };
284
285 /*
286  * configuration template - to be copied to the spec instance
287  */
288 struct alc_config_preset {
289         struct snd_kcontrol_new *mixers[5]; /* should be identical size
290                                              * with spec
291                                              */
292         const struct hda_verb *init_verbs[5];
293         unsigned int num_dacs;
294         hda_nid_t *dac_nids;
295         hda_nid_t dig_out_nid;          /* optional */
296         hda_nid_t hp_nid;               /* optional */
297         unsigned int num_adc_nids;
298         hda_nid_t *adc_nids;
299         hda_nid_t *capsrc_nids;
300         hda_nid_t dig_in_nid;
301         unsigned int num_channel_mode;
302         const struct hda_channel_mode *channel_mode;
303         int need_dac_fix;
304         unsigned int num_mux_defs;
305         const struct hda_input_mux *input_mux;
306         void (*unsol_event)(struct hda_codec *, unsigned int);
307         void (*init_hook)(struct hda_codec *);
308 #ifdef CONFIG_SND_HDA_POWER_SAVE
309         struct hda_amp_list *loopbacks;
310 #endif
311 };
312
313
314 /*
315  * input MUX handling
316  */
317 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
318                              struct snd_ctl_elem_info *uinfo)
319 {
320         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
321         struct alc_spec *spec = codec->spec;
322         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
323         if (mux_idx >= spec->num_mux_defs)
324                 mux_idx = 0;
325         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
326 }
327
328 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
329                             struct snd_ctl_elem_value *ucontrol)
330 {
331         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
332         struct alc_spec *spec = codec->spec;
333         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
334
335         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
336         return 0;
337 }
338
339 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
340                             struct snd_ctl_elem_value *ucontrol)
341 {
342         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
343         struct alc_spec *spec = codec->spec;
344         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
345         unsigned int mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
346         hda_nid_t nid = spec->capsrc_nids ?
347                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
348         return snd_hda_input_mux_put(codec, &spec->input_mux[mux_idx], ucontrol,
349                                      nid, &spec->cur_mux[adc_idx]);
350 }
351
352
353 /*
354  * channel mode setting
355  */
356 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
357                             struct snd_ctl_elem_info *uinfo)
358 {
359         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
360         struct alc_spec *spec = codec->spec;
361         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
362                                     spec->num_channel_mode);
363 }
364
365 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
366                            struct snd_ctl_elem_value *ucontrol)
367 {
368         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
369         struct alc_spec *spec = codec->spec;
370         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
371                                    spec->num_channel_mode,
372                                    spec->multiout.max_channels);
373 }
374
375 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
376                            struct snd_ctl_elem_value *ucontrol)
377 {
378         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
379         struct alc_spec *spec = codec->spec;
380         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
381                                       spec->num_channel_mode,
382                                       &spec->multiout.max_channels);
383         if (err >= 0 && spec->need_dac_fix)
384                 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
385         return err;
386 }
387
388 /*
389  * Control the mode of pin widget settings via the mixer.  "pc" is used
390  * instead of "%" to avoid consequences of accidently treating the % as 
391  * being part of a format specifier.  Maximum allowed length of a value is
392  * 63 characters plus NULL terminator.
393  *
394  * Note: some retasking pin complexes seem to ignore requests for input
395  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
396  * are requested.  Therefore order this list so that this behaviour will not
397  * cause problems when mixer clients move through the enum sequentially.
398  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
399  * March 2006.
400  */
401 static char *alc_pin_mode_names[] = {
402         "Mic 50pc bias", "Mic 80pc bias",
403         "Line in", "Line out", "Headphone out",
404 };
405 static unsigned char alc_pin_mode_values[] = {
406         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
407 };
408 /* The control can present all 5 options, or it can limit the options based
409  * in the pin being assumed to be exclusively an input or an output pin.  In
410  * addition, "input" pins may or may not process the mic bias option
411  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
412  * accept requests for bias as of chip versions up to March 2006) and/or
413  * wiring in the computer.
414  */
415 #define ALC_PIN_DIR_IN              0x00
416 #define ALC_PIN_DIR_OUT             0x01
417 #define ALC_PIN_DIR_INOUT           0x02
418 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
419 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
420
421 /* Info about the pin modes supported by the different pin direction modes. 
422  * For each direction the minimum and maximum values are given.
423  */
424 static signed char alc_pin_mode_dir_info[5][2] = {
425         { 0, 2 },    /* ALC_PIN_DIR_IN */
426         { 3, 4 },    /* ALC_PIN_DIR_OUT */
427         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
428         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
429         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
430 };
431 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
432 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
433 #define alc_pin_mode_n_items(_dir) \
434         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
435
436 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
437                              struct snd_ctl_elem_info *uinfo)
438 {
439         unsigned int item_num = uinfo->value.enumerated.item;
440         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
441
442         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
443         uinfo->count = 1;
444         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
445
446         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
447                 item_num = alc_pin_mode_min(dir);
448         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
449         return 0;
450 }
451
452 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
453                             struct snd_ctl_elem_value *ucontrol)
454 {
455         unsigned int i;
456         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
457         hda_nid_t nid = kcontrol->private_value & 0xffff;
458         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
459         long *valp = ucontrol->value.integer.value;
460         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
461                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
462                                                  0x00);
463
464         /* Find enumerated value for current pinctl setting */
465         i = alc_pin_mode_min(dir);
466         while (alc_pin_mode_values[i] != pinctl && i <= alc_pin_mode_max(dir))
467                 i++;
468         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
469         return 0;
470 }
471
472 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
473                             struct snd_ctl_elem_value *ucontrol)
474 {
475         signed int change;
476         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
477         hda_nid_t nid = kcontrol->private_value & 0xffff;
478         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
479         long val = *ucontrol->value.integer.value;
480         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
481                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
482                                                  0x00);
483
484         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
485                 val = alc_pin_mode_min(dir);
486
487         change = pinctl != alc_pin_mode_values[val];
488         if (change) {
489                 /* Set pin mode to that requested */
490                 snd_hda_codec_write_cache(codec, nid, 0,
491                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
492                                           alc_pin_mode_values[val]);
493
494                 /* Also enable the retasking pin's input/output as required 
495                  * for the requested pin mode.  Enum values of 2 or less are
496                  * input modes.
497                  *
498                  * Dynamically switching the input/output buffers probably
499                  * reduces noise slightly (particularly on input) so we'll
500                  * do it.  However, having both input and output buffers
501                  * enabled simultaneously doesn't seem to be problematic if
502                  * this turns out to be necessary in the future.
503                  */
504                 if (val <= 2) {
505                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
506                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
507                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
508                                                  HDA_AMP_MUTE, 0);
509                 } else {
510                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
511                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
512                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
513                                                  HDA_AMP_MUTE, 0);
514                 }
515         }
516         return change;
517 }
518
519 #define ALC_PIN_MODE(xname, nid, dir) \
520         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
521           .info = alc_pin_mode_info, \
522           .get = alc_pin_mode_get, \
523           .put = alc_pin_mode_put, \
524           .private_value = nid | (dir<<16) }
525
526 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
527  * together using a mask with more than one bit set.  This control is
528  * currently used only by the ALC260 test model.  At this stage they are not
529  * needed for any "production" models.
530  */
531 #ifdef CONFIG_SND_DEBUG
532 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
533
534 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
535                              struct snd_ctl_elem_value *ucontrol)
536 {
537         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
538         hda_nid_t nid = kcontrol->private_value & 0xffff;
539         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
540         long *valp = ucontrol->value.integer.value;
541         unsigned int val = snd_hda_codec_read(codec, nid, 0,
542                                               AC_VERB_GET_GPIO_DATA, 0x00);
543
544         *valp = (val & mask) != 0;
545         return 0;
546 }
547 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
548                              struct snd_ctl_elem_value *ucontrol)
549 {
550         signed int change;
551         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
552         hda_nid_t nid = kcontrol->private_value & 0xffff;
553         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
554         long val = *ucontrol->value.integer.value;
555         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
556                                                     AC_VERB_GET_GPIO_DATA,
557                                                     0x00);
558
559         /* Set/unset the masked GPIO bit(s) as needed */
560         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
561         if (val == 0)
562                 gpio_data &= ~mask;
563         else
564                 gpio_data |= mask;
565         snd_hda_codec_write_cache(codec, nid, 0,
566                                   AC_VERB_SET_GPIO_DATA, gpio_data);
567
568         return change;
569 }
570 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
571         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
572           .info = alc_gpio_data_info, \
573           .get = alc_gpio_data_get, \
574           .put = alc_gpio_data_put, \
575           .private_value = nid | (mask<<16) }
576 #endif   /* CONFIG_SND_DEBUG */
577
578 /* A switch control to allow the enabling of the digital IO pins on the
579  * ALC260.  This is incredibly simplistic; the intention of this control is
580  * to provide something in the test model allowing digital outputs to be
581  * identified if present.  If models are found which can utilise these
582  * outputs a more complete mixer control can be devised for those models if
583  * necessary.
584  */
585 #ifdef CONFIG_SND_DEBUG
586 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
587
588 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
589                               struct snd_ctl_elem_value *ucontrol)
590 {
591         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
592         hda_nid_t nid = kcontrol->private_value & 0xffff;
593         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
594         long *valp = ucontrol->value.integer.value;
595         unsigned int val = snd_hda_codec_read(codec, nid, 0,
596                                               AC_VERB_GET_DIGI_CONVERT_1, 0x00);
597
598         *valp = (val & mask) != 0;
599         return 0;
600 }
601 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
602                               struct snd_ctl_elem_value *ucontrol)
603 {
604         signed int change;
605         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
606         hda_nid_t nid = kcontrol->private_value & 0xffff;
607         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
608         long val = *ucontrol->value.integer.value;
609         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
610                                                     AC_VERB_GET_DIGI_CONVERT_1,
611                                                     0x00);
612
613         /* Set/unset the masked control bit(s) as needed */
614         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
615         if (val==0)
616                 ctrl_data &= ~mask;
617         else
618                 ctrl_data |= mask;
619         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
620                                   ctrl_data);
621
622         return change;
623 }
624 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
625         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
626           .info = alc_spdif_ctrl_info, \
627           .get = alc_spdif_ctrl_get, \
628           .put = alc_spdif_ctrl_put, \
629           .private_value = nid | (mask<<16) }
630 #endif   /* CONFIG_SND_DEBUG */
631
632 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
633  * Again, this is only used in the ALC26x test models to help identify when
634  * the EAPD line must be asserted for features to work.
635  */
636 #ifdef CONFIG_SND_DEBUG
637 #define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
638
639 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
640                               struct snd_ctl_elem_value *ucontrol)
641 {
642         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
643         hda_nid_t nid = kcontrol->private_value & 0xffff;
644         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
645         long *valp = ucontrol->value.integer.value;
646         unsigned int val = snd_hda_codec_read(codec, nid, 0,
647                                               AC_VERB_GET_EAPD_BTLENABLE, 0x00);
648
649         *valp = (val & mask) != 0;
650         return 0;
651 }
652
653 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
654                               struct snd_ctl_elem_value *ucontrol)
655 {
656         int change;
657         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
658         hda_nid_t nid = kcontrol->private_value & 0xffff;
659         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
660         long val = *ucontrol->value.integer.value;
661         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
662                                                     AC_VERB_GET_EAPD_BTLENABLE,
663                                                     0x00);
664
665         /* Set/unset the masked control bit(s) as needed */
666         change = (!val ? 0 : mask) != (ctrl_data & mask);
667         if (!val)
668                 ctrl_data &= ~mask;
669         else
670                 ctrl_data |= mask;
671         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
672                                   ctrl_data);
673
674         return change;
675 }
676
677 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
678         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
679           .info = alc_eapd_ctrl_info, \
680           .get = alc_eapd_ctrl_get, \
681           .put = alc_eapd_ctrl_put, \
682           .private_value = nid | (mask<<16) }
683 #endif   /* CONFIG_SND_DEBUG */
684
685 /*
686  * set up from the preset table
687  */
688 static void setup_preset(struct alc_spec *spec,
689                          const struct alc_config_preset *preset)
690 {
691         int i;
692
693         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
694                 spec->mixers[spec->num_mixers++] = preset->mixers[i];
695         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
696              i++)
697                 spec->init_verbs[spec->num_init_verbs++] =
698                         preset->init_verbs[i];
699         
700         spec->channel_mode = preset->channel_mode;
701         spec->num_channel_mode = preset->num_channel_mode;
702         spec->need_dac_fix = preset->need_dac_fix;
703
704         spec->multiout.max_channels = spec->channel_mode[0].channels;
705
706         spec->multiout.num_dacs = preset->num_dacs;
707         spec->multiout.dac_nids = preset->dac_nids;
708         spec->multiout.dig_out_nid = preset->dig_out_nid;
709         spec->multiout.hp_nid = preset->hp_nid;
710         
711         spec->num_mux_defs = preset->num_mux_defs;
712         if (!spec->num_mux_defs)
713                 spec->num_mux_defs = 1;
714         spec->input_mux = preset->input_mux;
715
716         spec->num_adc_nids = preset->num_adc_nids;
717         spec->adc_nids = preset->adc_nids;
718         spec->capsrc_nids = preset->capsrc_nids;
719         spec->dig_in_nid = preset->dig_in_nid;
720
721         spec->unsol_event = preset->unsol_event;
722         spec->init_hook = preset->init_hook;
723 #ifdef CONFIG_SND_HDA_POWER_SAVE
724         spec->loopback.amplist = preset->loopbacks;
725 #endif
726 }
727
728 /* Enable GPIO mask and set output */
729 static struct hda_verb alc_gpio1_init_verbs[] = {
730         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
731         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
732         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
733         { }
734 };
735
736 static struct hda_verb alc_gpio2_init_verbs[] = {
737         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
738         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
739         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
740         { }
741 };
742
743 static struct hda_verb alc_gpio3_init_verbs[] = {
744         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
745         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
746         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
747         { }
748 };
749
750 static void alc_sku_automute(struct hda_codec *codec)
751 {
752         struct alc_spec *spec = codec->spec;
753         unsigned int present;
754         unsigned int hp_nid = spec->autocfg.hp_pins[0];
755         unsigned int sp_nid = spec->autocfg.speaker_pins[0];
756
757         /* need to execute and sync at first */
758         snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
759         present = snd_hda_codec_read(codec, hp_nid, 0,
760                                      AC_VERB_GET_PIN_SENSE, 0);
761         spec->jack_present = (present & 0x80000000) != 0;
762         snd_hda_codec_write(codec, sp_nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
763                             spec->jack_present ? 0 : PIN_OUT);
764 }
765
766 /* unsolicited event for HP jack sensing */
767 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
768 {
769         if (codec->vendor_id == 0x10ec0880)
770                 res >>= 28;
771         else
772                 res >>= 26;
773         if (res != ALC880_HP_EVENT)
774                 return;
775
776         alc_sku_automute(codec);
777 }
778
779 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
780  *      31 ~ 16 :       Manufacture ID
781  *      15 ~ 8  :       SKU ID
782  *      7  ~ 0  :       Assembly ID
783  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
784  */
785 static void alc_subsystem_id(struct hda_codec *codec,
786                              unsigned int porta, unsigned int porte,
787                              unsigned int portd)
788 {
789         unsigned int ass, tmp, i;
790         unsigned nid;
791         struct alc_spec *spec = codec->spec;
792
793         ass = codec->subsystem_id & 0xffff;
794         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
795                 goto do_sku;
796
797         /*      
798          * 31~30        : port conetcivity
799          * 29~21        : reserve
800          * 20           : PCBEEP input
801          * 19~16        : Check sum (15:1)
802          * 15~1         : Custom
803          * 0            : override
804         */
805         nid = 0x1d;
806         if (codec->vendor_id == 0x10ec0260)
807                 nid = 0x17;
808         ass = snd_hda_codec_read(codec, nid, 0,
809                                  AC_VERB_GET_CONFIG_DEFAULT, 0);
810         if (!(ass & 1) && !(ass & 0x100000))
811                 return;
812         if ((ass >> 30) != 1)   /* no physical connection */
813                 return;
814
815         /* check sum */
816         tmp = 0;
817         for (i = 1; i < 16; i++) {
818                 if ((ass >> i) & 1)
819                         tmp++;
820         }
821         if (((ass >> 16) & 0xf) != tmp)
822                 return;
823 do_sku:
824         /*
825          * 0 : override
826          * 1 :  Swap Jack
827          * 2 : 0 --> Desktop, 1 --> Laptop
828          * 3~5 : External Amplifier control
829          * 7~6 : Reserved
830         */
831         tmp = (ass & 0x38) >> 3;        /* external Amp control */
832         switch (tmp) {
833         case 1:
834                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
835                 break;
836         case 3:
837                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
838                 break;
839         case 7:
840                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
841                 break;
842         case 5: /* set EAPD output high */
843                 switch (codec->vendor_id) {
844                 case 0x10ec0260:
845                         snd_hda_codec_write(codec, 0x0f, 0,
846                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
847                         snd_hda_codec_write(codec, 0x10, 0,
848                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
849                         break;
850                 case 0x10ec0262:
851                 case 0x10ec0267:
852                 case 0x10ec0268:
853                 case 0x10ec0269:
854                 case 0x10ec0862:
855                 case 0x10ec0662:        
856                         snd_hda_codec_write(codec, 0x14, 0,
857                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
858                         snd_hda_codec_write(codec, 0x15, 0,
859                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
860                         break;
861                 }
862                 switch (codec->vendor_id) {
863                 case 0x10ec0260:
864                         snd_hda_codec_write(codec, 0x1a, 0,
865                                             AC_VERB_SET_COEF_INDEX, 7);
866                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
867                                                  AC_VERB_GET_PROC_COEF, 0);
868                         snd_hda_codec_write(codec, 0x1a, 0,
869                                             AC_VERB_SET_COEF_INDEX, 7);
870                         snd_hda_codec_write(codec, 0x1a, 0,
871                                             AC_VERB_SET_PROC_COEF,
872                                             tmp | 0x2010);
873                         break;
874                 case 0x10ec0262:
875                 case 0x10ec0880:
876                 case 0x10ec0882:
877                 case 0x10ec0883:
878                 case 0x10ec0885:
879                 case 0x10ec0888:
880                         snd_hda_codec_write(codec, 0x20, 0,
881                                             AC_VERB_SET_COEF_INDEX, 7);
882                         tmp = snd_hda_codec_read(codec, 0x20, 0,
883                                                  AC_VERB_GET_PROC_COEF, 0);
884                         snd_hda_codec_write(codec, 0x20, 0,
885                                             AC_VERB_SET_COEF_INDEX, 7); 
886                         snd_hda_codec_write(codec, 0x20, 0,
887                                             AC_VERB_SET_PROC_COEF,
888                                             tmp | 0x2010);
889                         break;
890                 case 0x10ec0267:
891                 case 0x10ec0268:
892                         snd_hda_codec_write(codec, 0x20, 0,
893                                             AC_VERB_SET_COEF_INDEX, 7);
894                         tmp = snd_hda_codec_read(codec, 0x20, 0,
895                                                  AC_VERB_GET_PROC_COEF, 0);
896                         snd_hda_codec_write(codec, 0x20, 0,
897                                             AC_VERB_SET_COEF_INDEX, 7); 
898                         snd_hda_codec_write(codec, 0x20, 0,
899                                             AC_VERB_SET_PROC_COEF,
900                                             tmp | 0x3000);
901                         break;
902                 }
903         default:
904                 break;
905         }
906         
907         /* is laptop or Desktop and enable the function "Mute internal speaker
908          * when the external headphone out jack is plugged"
909          */
910         if (!(ass & 0x8000))
911                 return;
912         /*
913          * 10~8 : Jack location
914          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
915          * 14~13: Resvered
916          * 15   : 1 --> enable the function "Mute internal speaker
917          *              when the external headphone out jack is plugged"
918          */
919         if (!spec->autocfg.speaker_pins[0]) {
920                 if (spec->autocfg.line_out_pins[0])
921                         spec->autocfg.speaker_pins[0] =
922                                 spec->autocfg.line_out_pins[0];
923                 else
924                         return;
925         }
926
927         if (!spec->autocfg.hp_pins[0]) {
928                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
929                 if (tmp == 0)
930                         spec->autocfg.hp_pins[0] = porta;
931                 else if (tmp == 1)
932                         spec->autocfg.hp_pins[0] = porte;
933                 else if (tmp == 2)
934                         spec->autocfg.hp_pins[0] = portd;
935                 else
936                         return;
937         }
938
939         snd_hda_codec_write(codec, spec->autocfg.hp_pins[0], 0,
940                             AC_VERB_SET_UNSOLICITED_ENABLE,
941                             AC_USRSP_EN | ALC880_HP_EVENT);
942         spec->unsol_event = alc_sku_unsol_event;
943         spec->init_hook = alc_sku_automute;     
944 }
945
946 /*
947  * Fix-up pin default configurations
948  */
949
950 struct alc_pincfg {
951         hda_nid_t nid;
952         u32 val;
953 };
954
955 static void alc_fix_pincfg(struct hda_codec *codec,
956                            const struct snd_pci_quirk *quirk,
957                            const struct alc_pincfg **pinfix)
958 {
959         const struct alc_pincfg *cfg;
960
961         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
962         if (!quirk)
963                 return;
964
965         cfg = pinfix[quirk->value];
966         for (; cfg->nid; cfg++) {
967                 int i;
968                 u32 val = cfg->val;
969                 for (i = 0; i < 4; i++) {
970                         snd_hda_codec_write(codec, cfg->nid, 0,
971                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0 + i,
972                                     val & 0xff);
973                         val >>= 8;
974                 }
975         }
976 }
977
978 /*
979  * ALC880 3-stack model
980  *
981  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
982  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
983  *                 F-Mic = 0x1b, HP = 0x19
984  */
985
986 static hda_nid_t alc880_dac_nids[4] = {
987         /* front, rear, clfe, rear_surr */
988         0x02, 0x05, 0x04, 0x03
989 };
990
991 static hda_nid_t alc880_adc_nids[3] = {
992         /* ADC0-2 */
993         0x07, 0x08, 0x09,
994 };
995
996 /* The datasheet says the node 0x07 is connected from inputs,
997  * but it shows zero connection in the real implementation on some devices.
998  * Note: this is a 915GAV bug, fixed on 915GLV
999  */
1000 static hda_nid_t alc880_adc_nids_alt[2] = {
1001         /* ADC1-2 */
1002         0x08, 0x09,
1003 };
1004
1005 #define ALC880_DIGOUT_NID       0x06
1006 #define ALC880_DIGIN_NID        0x0a
1007
1008 static struct hda_input_mux alc880_capture_source = {
1009         .num_items = 4,
1010         .items = {
1011                 { "Mic", 0x0 },
1012                 { "Front Mic", 0x3 },
1013                 { "Line", 0x2 },
1014                 { "CD", 0x4 },
1015         },
1016 };
1017
1018 /* channel source setting (2/6 channel selection for 3-stack) */
1019 /* 2ch mode */
1020 static struct hda_verb alc880_threestack_ch2_init[] = {
1021         /* set line-in to input, mute it */
1022         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1023         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1024         /* set mic-in to input vref 80%, mute it */
1025         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1026         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1027         { } /* end */
1028 };
1029
1030 /* 6ch mode */
1031 static struct hda_verb alc880_threestack_ch6_init[] = {
1032         /* set line-in to output, unmute it */
1033         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1034         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1035         /* set mic-in to output, unmute it */
1036         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1037         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1038         { } /* end */
1039 };
1040
1041 static struct hda_channel_mode alc880_threestack_modes[2] = {
1042         { 2, alc880_threestack_ch2_init },
1043         { 6, alc880_threestack_ch6_init },
1044 };
1045
1046 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1047         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1048         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1049         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1050         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1051         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1052         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1053         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1054         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1055         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1056         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1057         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1058         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1059         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1060         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1061         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
1062         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
1063         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1064         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1065         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
1066         {
1067                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1068                 .name = "Channel Mode",
1069                 .info = alc_ch_mode_info,
1070                 .get = alc_ch_mode_get,
1071                 .put = alc_ch_mode_put,
1072         },
1073         { } /* end */
1074 };
1075
1076 /* capture mixer elements */
1077 static struct snd_kcontrol_new alc880_capture_mixer[] = {
1078         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
1079         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
1080         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
1081         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
1082         HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
1083         HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
1084         {
1085                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1086                 /* The multiple "Capture Source" controls confuse alsamixer
1087                  * So call somewhat different..
1088                  */
1089                 /* .name = "Capture Source", */
1090                 .name = "Input Source",
1091                 .count = 3,
1092                 .info = alc_mux_enum_info,
1093                 .get = alc_mux_enum_get,
1094                 .put = alc_mux_enum_put,
1095         },
1096         { } /* end */
1097 };
1098
1099 /* capture mixer elements (in case NID 0x07 not available) */
1100 static struct snd_kcontrol_new alc880_capture_alt_mixer[] = {
1101         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1102         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1103         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
1104         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
1105         {
1106                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1107                 /* The multiple "Capture Source" controls confuse alsamixer
1108                  * So call somewhat different..
1109                  */
1110                 /* .name = "Capture Source", */
1111                 .name = "Input Source",
1112                 .count = 2,
1113                 .info = alc_mux_enum_info,
1114                 .get = alc_mux_enum_get,
1115                 .put = alc_mux_enum_put,
1116         },
1117         { } /* end */
1118 };
1119
1120
1121
1122 /*
1123  * ALC880 5-stack model
1124  *
1125  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
1126  *      Side = 0x02 (0xd)
1127  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
1128  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
1129  */
1130
1131 /* additional mixers to alc880_three_stack_mixer */
1132 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
1133         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1134         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
1135         { } /* end */
1136 };
1137
1138 /* channel source setting (6/8 channel selection for 5-stack) */
1139 /* 6ch mode */
1140 static struct hda_verb alc880_fivestack_ch6_init[] = {
1141         /* set line-in to input, mute it */
1142         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1143         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1144         { } /* end */
1145 };
1146
1147 /* 8ch mode */
1148 static struct hda_verb alc880_fivestack_ch8_init[] = {
1149         /* set line-in to output, unmute it */
1150         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1151         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1152         { } /* end */
1153 };
1154
1155 static struct hda_channel_mode alc880_fivestack_modes[2] = {
1156         { 6, alc880_fivestack_ch6_init },
1157         { 8, alc880_fivestack_ch8_init },
1158 };
1159
1160
1161 /*
1162  * ALC880 6-stack model
1163  *
1164  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
1165  *      Side = 0x05 (0x0f)
1166  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
1167  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
1168  */
1169
1170 static hda_nid_t alc880_6st_dac_nids[4] = {
1171         /* front, rear, clfe, rear_surr */
1172         0x02, 0x03, 0x04, 0x05
1173 };
1174
1175 static struct hda_input_mux alc880_6stack_capture_source = {
1176         .num_items = 4,
1177         .items = {
1178                 { "Mic", 0x0 },
1179                 { "Front Mic", 0x1 },
1180                 { "Line", 0x2 },
1181                 { "CD", 0x4 },
1182         },
1183 };
1184
1185 /* fixed 8-channels */
1186 static struct hda_channel_mode alc880_sixstack_modes[1] = {
1187         { 8, NULL },
1188 };
1189
1190 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
1191         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1192         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1193         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1194         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1195         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1196         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1197         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1198         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1199         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1200         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1201         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1202         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1203         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1204         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1205         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1206         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1207         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1208         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1209         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1210         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1211         {
1212                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1213                 .name = "Channel Mode",
1214                 .info = alc_ch_mode_info,
1215                 .get = alc_ch_mode_get,
1216                 .put = alc_ch_mode_put,
1217         },
1218         { } /* end */
1219 };
1220
1221
1222 /*
1223  * ALC880 W810 model
1224  *
1225  * W810 has rear IO for:
1226  * Front (DAC 02)
1227  * Surround (DAC 03)
1228  * Center/LFE (DAC 04)
1229  * Digital out (06)
1230  *
1231  * The system also has a pair of internal speakers, and a headphone jack.
1232  * These are both connected to Line2 on the codec, hence to DAC 02.
1233  * 
1234  * There is a variable resistor to control the speaker or headphone
1235  * volume. This is a hardware-only device without a software API.
1236  *
1237  * Plugging headphones in will disable the internal speakers. This is
1238  * implemented in hardware, not via the driver using jack sense. In
1239  * a similar fashion, plugging into the rear socket marked "front" will
1240  * disable both the speakers and headphones.
1241  *
1242  * For input, there's a microphone jack, and an "audio in" jack.
1243  * These may not do anything useful with this driver yet, because I
1244  * haven't setup any initialization verbs for these yet...
1245  */
1246
1247 static hda_nid_t alc880_w810_dac_nids[3] = {
1248         /* front, rear/surround, clfe */
1249         0x02, 0x03, 0x04
1250 };
1251
1252 /* fixed 6 channels */
1253 static struct hda_channel_mode alc880_w810_modes[1] = {
1254         { 6, NULL }
1255 };
1256
1257 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
1258 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
1259         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1260         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1261         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1262         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1263         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1264         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1265         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1266         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1267         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1268         { } /* end */
1269 };
1270
1271
1272 /*
1273  * Z710V model
1274  *
1275  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
1276  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
1277  *                 Line = 0x1a
1278  */
1279
1280 static hda_nid_t alc880_z71v_dac_nids[1] = {
1281         0x02
1282 };
1283 #define ALC880_Z71V_HP_DAC      0x03
1284
1285 /* fixed 2 channels */
1286 static struct hda_channel_mode alc880_2_jack_modes[1] = {
1287         { 2, NULL }
1288 };
1289
1290 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
1291         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1292         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1293         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1294         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
1295         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1296         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1297         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1298         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1299         { } /* end */
1300 };
1301
1302
1303 /*
1304  * ALC880 F1734 model
1305  *
1306  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
1307  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
1308  */
1309
1310 static hda_nid_t alc880_f1734_dac_nids[1] = {
1311         0x03
1312 };
1313 #define ALC880_F1734_HP_DAC     0x02
1314
1315 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
1316         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1317         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1318         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1319         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1320         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1321         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1322         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1323         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1324         { } /* end */
1325 };
1326
1327 static struct hda_input_mux alc880_f1734_capture_source = {
1328         .num_items = 2,
1329         .items = {
1330                 { "Mic", 0x1 },
1331                 { "CD", 0x4 },
1332         },
1333 };
1334
1335
1336 /*
1337  * ALC880 ASUS model
1338  *
1339  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1340  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1341  *  Mic = 0x18, Line = 0x1a
1342  */
1343
1344 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
1345 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
1346
1347 static struct snd_kcontrol_new alc880_asus_mixer[] = {
1348         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1349         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1350         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1351         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1352         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1353         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1354         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1355         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1356         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1357         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1358         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1359         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1360         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1361         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1362         {
1363                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1364                 .name = "Channel Mode",
1365                 .info = alc_ch_mode_info,
1366                 .get = alc_ch_mode_get,
1367                 .put = alc_ch_mode_put,
1368         },
1369         { } /* end */
1370 };
1371
1372 /*
1373  * ALC880 ASUS W1V model
1374  *
1375  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1376  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1377  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
1378  */
1379
1380 /* additional mixers to alc880_asus_mixer */
1381 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
1382         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
1383         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
1384         { } /* end */
1385 };
1386
1387 /* additional mixers to alc880_asus_mixer */
1388 static struct snd_kcontrol_new alc880_pcbeep_mixer[] = {
1389         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1390         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1391         { } /* end */
1392 };
1393
1394 /* TCL S700 */
1395 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
1396         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1397         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1398         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1399         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
1400         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
1401         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
1402         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
1403         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1404         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1405         {
1406                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1407                 /* The multiple "Capture Source" controls confuse alsamixer
1408                  * So call somewhat different..
1409                  */
1410                 /* .name = "Capture Source", */
1411                 .name = "Input Source",
1412                 .count = 1,
1413                 .info = alc_mux_enum_info,
1414                 .get = alc_mux_enum_get,
1415                 .put = alc_mux_enum_put,
1416         },
1417         { } /* end */
1418 };
1419
1420 /* Uniwill */
1421 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
1422         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1423         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1424         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1425         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1426         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1427         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1428         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1429         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1430         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1431         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1432         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1433         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1434         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1435         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1436         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1437         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1438         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1439         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1440         {
1441                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1442                 .name = "Channel Mode",
1443                 .info = alc_ch_mode_info,
1444                 .get = alc_ch_mode_get,
1445                 .put = alc_ch_mode_put,
1446         },
1447         { } /* end */
1448 };
1449
1450 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
1451         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1452         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1453         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1454         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1455         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1456         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1457         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1458         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1459         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1460         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1461         { } /* end */
1462 };
1463
1464 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
1465         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1466         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1467         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1468         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1469         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1470         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1471         { } /* end */
1472 };
1473
1474 /*
1475  * virtual master controls
1476  */
1477
1478 /*
1479  * slave controls for virtual master
1480  */
1481 static const char *alc_slave_vols[] = {
1482         "Front Playback Volume",
1483         "Surround Playback Volume",
1484         "Center Playback Volume",
1485         "LFE Playback Volume",
1486         "Side Playback Volume",
1487         "Headphone Playback Volume",
1488         "Speaker Playback Volume",
1489         "Mono Playback Volume",
1490         "Line-Out Playback Volume",
1491         NULL,
1492 };
1493
1494 static const char *alc_slave_sws[] = {
1495         "Front Playback Switch",
1496         "Surround Playback Switch",
1497         "Center Playback Switch",
1498         "LFE Playback Switch",
1499         "Side Playback Switch",
1500         "Headphone Playback Switch",
1501         "Speaker Playback Switch",
1502         "Mono Playback Switch",
1503         "IEC958 Playback Switch",
1504         NULL,
1505 };
1506
1507 /*
1508  * build control elements
1509  */
1510 static int alc_build_controls(struct hda_codec *codec)
1511 {
1512         struct alc_spec *spec = codec->spec;
1513         int err;
1514         int i;
1515
1516         for (i = 0; i < spec->num_mixers; i++) {
1517                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1518                 if (err < 0)
1519                         return err;
1520         }
1521
1522         if (spec->multiout.dig_out_nid) {
1523                 err = snd_hda_create_spdif_out_ctls(codec,
1524                                                     spec->multiout.dig_out_nid);
1525                 if (err < 0)
1526                         return err;
1527                 err = snd_hda_create_spdif_share_sw(codec,
1528                                                     &spec->multiout);
1529                 if (err < 0)
1530                         return err;
1531                 spec->multiout.share_spdif = 1;
1532         }
1533         if (spec->dig_in_nid) {
1534                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1535                 if (err < 0)
1536                         return err;
1537         }
1538
1539         /* if we have no master control, let's create it */
1540         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1541                 unsigned int vmaster_tlv[4];
1542                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1543                                         HDA_OUTPUT, vmaster_tlv);
1544                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1545                                           vmaster_tlv, alc_slave_vols);
1546                 if (err < 0)
1547                         return err;
1548         }
1549         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1550                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1551                                           NULL, alc_slave_sws);
1552                 if (err < 0)
1553                         return err;
1554         }
1555
1556         return 0;
1557 }
1558
1559
1560 /*
1561  * initialize the codec volumes, etc
1562  */
1563
1564 /*
1565  * generic initialization of ADC, input mixers and output mixers
1566  */
1567 static struct hda_verb alc880_volume_init_verbs[] = {
1568         /*
1569          * Unmute ADC0-2 and set the default input to mic-in
1570          */
1571         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
1572         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1573         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
1574         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1575         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
1576         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1577
1578         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1579          * mixer widget
1580          * Note: PASD motherboards uses the Line In 2 as the input for front
1581          * panel mic (mic 2)
1582          */
1583         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
1584         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1585         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1586         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
1587         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
1588         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
1589         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
1590         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
1591
1592         /*
1593          * Set up output mixers (0x0c - 0x0f)
1594          */
1595         /* set vol=0 to output mixers */
1596         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1597         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1598         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1599         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1600         /* set up input amps for analog loopback */
1601         /* Amp Indices: DAC = 0, mixer = 1 */
1602         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1603         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1604         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1605         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1606         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1607         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1608         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1609         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1610
1611         { }
1612 };
1613
1614 /*
1615  * 3-stack pin configuration:
1616  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
1617  */
1618 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
1619         /*
1620          * preset connection lists of input pins
1621          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1622          */
1623         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
1624         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1625         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
1626
1627         /*
1628          * Set pin mode and muting
1629          */
1630         /* set front pin widgets 0x14 for output */
1631         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1632         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1633         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1634         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1635         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1636         /* Mic2 (as headphone out) for HP output */
1637         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1638         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1639         /* Line In pin widget for input */
1640         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1641         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1642         /* Line2 (as front mic) pin widget for input and vref at 80% */
1643         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1644         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1645         /* CD pin widget for input */
1646         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1647
1648         { }
1649 };
1650
1651 /*
1652  * 5-stack pin configuration:
1653  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
1654  * line-in/side = 0x1a, f-mic = 0x1b
1655  */
1656 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
1657         /*
1658          * preset connection lists of input pins
1659          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1660          */
1661         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1662         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
1663
1664         /*
1665          * Set pin mode and muting
1666          */
1667         /* set pin widgets 0x14-0x17 for output */
1668         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1669         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1670         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1671         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1672         /* unmute pins for output (no gain on this amp) */
1673         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1674         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1675         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1676         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1677
1678         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1679         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1680         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1681         /* Mic2 (as headphone out) for HP output */
1682         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1683         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1684         /* Line In pin widget for input */
1685         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1686         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1687         /* Line2 (as front mic) pin widget for input and vref at 80% */
1688         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1689         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1690         /* CD pin widget for input */
1691         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1692
1693         { }
1694 };
1695
1696 /*
1697  * W810 pin configuration:
1698  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
1699  */
1700 static struct hda_verb alc880_pin_w810_init_verbs[] = {
1701         /* hphone/speaker input selector: front DAC */
1702         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
1703
1704         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1705         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1706         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1707         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1708         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1709         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1710
1711         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1712         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1713
1714         { }
1715 };
1716
1717 /*
1718  * Z71V pin configuration:
1719  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
1720  */
1721 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
1722         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1723         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1724         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1725         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1726
1727         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1728         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1729         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1730         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1731
1732         { }
1733 };
1734
1735 /*
1736  * 6-stack pin configuration:
1737  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
1738  * f-mic = 0x19, line = 0x1a, HP = 0x1b
1739  */
1740 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
1741         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1742
1743         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1744         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1745         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1746         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1747         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1748         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1749         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1750         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1751
1752         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1753         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1754         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1755         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1756         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1757         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1758         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1759         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1760         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1761         
1762         { }
1763 };
1764
1765 /*
1766  * Uniwill pin configuration:
1767  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
1768  * line = 0x1a
1769  */
1770 static struct hda_verb alc880_uniwill_init_verbs[] = {
1771         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1772
1773         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1774         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1775         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1776         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1777         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1778         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1779         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1780         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1781         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1782         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1783         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1784         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1785         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1786         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1787
1788         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1789         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1790         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1791         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1792         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1793         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1794         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
1795         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
1796         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1797
1798         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
1799         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
1800
1801         { }
1802 };
1803
1804 /*
1805 * Uniwill P53
1806 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19, 
1807  */
1808 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
1809         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1810
1811         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1812         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1813         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1814         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1815         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1816         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1817         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1818         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1819         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1820         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1821         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1822         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1823
1824         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1825         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1826         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1827         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1828         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1829         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1830
1831         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
1832         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
1833
1834         { }
1835 };
1836
1837 static struct hda_verb alc880_beep_init_verbs[] = {
1838         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
1839         { }
1840 };
1841
1842 /* toggle speaker-output according to the hp-jack state */
1843 static void alc880_uniwill_hp_automute(struct hda_codec *codec)
1844 {
1845         unsigned int present;
1846         unsigned char bits;
1847
1848         present = snd_hda_codec_read(codec, 0x14, 0,
1849                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1850         bits = present ? HDA_AMP_MUTE : 0;
1851         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
1852                                  HDA_AMP_MUTE, bits);
1853         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
1854                                  HDA_AMP_MUTE, bits);
1855 }
1856
1857 /* auto-toggle front mic */
1858 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
1859 {
1860         unsigned int present;
1861         unsigned char bits;
1862
1863         present = snd_hda_codec_read(codec, 0x18, 0,
1864                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1865         bits = present ? HDA_AMP_MUTE : 0;
1866         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
1867 }
1868
1869 static void alc880_uniwill_automute(struct hda_codec *codec)
1870 {
1871         alc880_uniwill_hp_automute(codec);
1872         alc880_uniwill_mic_automute(codec);
1873 }
1874
1875 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
1876                                        unsigned int res)
1877 {
1878         /* Looks like the unsol event is incompatible with the standard
1879          * definition.  4bit tag is placed at 28 bit!
1880          */
1881         switch (res >> 28) {
1882         case ALC880_HP_EVENT:
1883                 alc880_uniwill_hp_automute(codec);
1884                 break;
1885         case ALC880_MIC_EVENT:
1886                 alc880_uniwill_mic_automute(codec);
1887                 break;
1888         }
1889 }
1890
1891 static void alc880_uniwill_p53_hp_automute(struct hda_codec *codec)
1892 {
1893         unsigned int present;
1894         unsigned char bits;
1895
1896         present = snd_hda_codec_read(codec, 0x14, 0,
1897                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1898         bits = present ? HDA_AMP_MUTE : 0;
1899         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, HDA_AMP_MUTE, bits);
1900 }
1901
1902 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
1903 {
1904         unsigned int present;
1905         
1906         present = snd_hda_codec_read(codec, 0x21, 0,
1907                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
1908         present &= HDA_AMP_VOLMASK;
1909         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
1910                                  HDA_AMP_VOLMASK, present);
1911         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
1912                                  HDA_AMP_VOLMASK, present);
1913 }
1914
1915 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
1916                                            unsigned int res)
1917 {
1918         /* Looks like the unsol event is incompatible with the standard
1919          * definition.  4bit tag is placed at 28 bit!
1920          */
1921         if ((res >> 28) == ALC880_HP_EVENT)
1922                 alc880_uniwill_p53_hp_automute(codec);
1923         if ((res >> 28) == ALC880_DCVOL_EVENT)
1924                 alc880_uniwill_p53_dcvol_automute(codec);
1925 }
1926
1927 /*
1928  * F1734 pin configuration:
1929  * HP = 0x14, speaker-out = 0x15, mic = 0x18
1930  */
1931 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
1932         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
1933         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
1934         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
1935         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
1936         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
1937
1938         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1939         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1940         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1941         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1942
1943         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1944         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1945         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
1946         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1947         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1948         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1949         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1950         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1951         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1952
1953         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
1954         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
1955
1956         { }
1957 };
1958
1959 /*
1960  * ASUS pin configuration:
1961  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
1962  */
1963 static struct hda_verb alc880_pin_asus_init_verbs[] = {
1964         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
1965         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
1966         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
1967         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
1968
1969         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1970         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1971         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1972         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1973         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1974         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1975         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1976         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1977
1978         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1979         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1980         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1981         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1982         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1983         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1984         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1985         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1986         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1987         
1988         { }
1989 };
1990
1991 /* Enable GPIO mask and set output */
1992 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
1993 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
1994
1995 /* Clevo m520g init */
1996 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
1997         /* headphone output */
1998         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
1999         /* line-out */
2000         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2001         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2002         /* Line-in */
2003         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2004         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2005         /* CD */
2006         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2007         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2008         /* Mic1 (rear panel) */
2009         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2010         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2011         /* Mic2 (front panel) */
2012         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2013         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2014         /* headphone */
2015         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2016         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2017         /* change to EAPD mode */
2018         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2019         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2020
2021         { }
2022 };
2023
2024 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
2025         /* change to EAPD mode */
2026         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2027         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2028
2029         /* Headphone output */
2030         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2031         /* Front output*/
2032         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2033         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2034
2035         /* Line In pin widget for input */
2036         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2037         /* CD pin widget for input */
2038         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2039         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2040         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2041
2042         /* change to EAPD mode */
2043         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2044         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
2045
2046         { }
2047 };
2048
2049 /*
2050  * LG m1 express dual
2051  *
2052  * Pin assignment:
2053  *   Rear Line-In/Out (blue): 0x14
2054  *   Build-in Mic-In: 0x15
2055  *   Speaker-out: 0x17
2056  *   HP-Out (green): 0x1b
2057  *   Mic-In/Out (red): 0x19
2058  *   SPDIF-Out: 0x1e
2059  */
2060
2061 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
2062 static hda_nid_t alc880_lg_dac_nids[3] = {
2063         0x05, 0x02, 0x03
2064 };
2065
2066 /* seems analog CD is not working */
2067 static struct hda_input_mux alc880_lg_capture_source = {
2068         .num_items = 3,
2069         .items = {
2070                 { "Mic", 0x1 },
2071                 { "Line", 0x5 },
2072                 { "Internal Mic", 0x6 },
2073         },
2074 };
2075
2076 /* 2,4,6 channel modes */
2077 static struct hda_verb alc880_lg_ch2_init[] = {
2078         /* set line-in and mic-in to input */
2079         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2080         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2081         { }
2082 };
2083
2084 static struct hda_verb alc880_lg_ch4_init[] = {
2085         /* set line-in to out and mic-in to input */
2086         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2087         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2088         { }
2089 };
2090
2091 static struct hda_verb alc880_lg_ch6_init[] = {
2092         /* set line-in and mic-in to output */
2093         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2094         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2095         { }
2096 };
2097
2098 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
2099         { 2, alc880_lg_ch2_init },
2100         { 4, alc880_lg_ch4_init },
2101         { 6, alc880_lg_ch6_init },
2102 };
2103
2104 static struct snd_kcontrol_new alc880_lg_mixer[] = {
2105         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2106         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
2107         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2108         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
2109         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
2110         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
2111         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
2112         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
2113         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2114         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2115         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
2116         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
2117         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
2118         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
2119         {
2120                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2121                 .name = "Channel Mode",
2122                 .info = alc_ch_mode_info,
2123                 .get = alc_ch_mode_get,
2124                 .put = alc_ch_mode_put,
2125         },
2126         { } /* end */
2127 };
2128
2129 static struct hda_verb alc880_lg_init_verbs[] = {
2130         /* set capture source to mic-in */
2131         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2132         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2133         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2134         /* mute all amp mixer inputs */
2135         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
2136         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2137         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2138         /* line-in to input */
2139         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2140         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2141         /* built-in mic */
2142         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2143         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2144         /* speaker-out */
2145         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2146         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2147         /* mic-in to input */
2148         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2149         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2150         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2151         /* HP-out */
2152         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
2153         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2154         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2155         /* jack sense */
2156         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2157         { }
2158 };
2159
2160 /* toggle speaker-output according to the hp-jack state */
2161 static void alc880_lg_automute(struct hda_codec *codec)
2162 {
2163         unsigned int present;
2164         unsigned char bits;
2165
2166         present = snd_hda_codec_read(codec, 0x1b, 0,
2167                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2168         bits = present ? HDA_AMP_MUTE : 0;
2169         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
2170                                  HDA_AMP_MUTE, bits);
2171 }
2172
2173 static void alc880_lg_unsol_event(struct hda_codec *codec, unsigned int res)
2174 {
2175         /* Looks like the unsol event is incompatible with the standard
2176          * definition.  4bit tag is placed at 28 bit!
2177          */
2178         if ((res >> 28) == 0x01)
2179                 alc880_lg_automute(codec);
2180 }
2181
2182 /*
2183  * LG LW20
2184  *
2185  * Pin assignment:
2186  *   Speaker-out: 0x14
2187  *   Mic-In: 0x18
2188  *   Built-in Mic-In: 0x19
2189  *   Line-In: 0x1b
2190  *   HP-Out: 0x1a
2191  *   SPDIF-Out: 0x1e
2192  */
2193
2194 static struct hda_input_mux alc880_lg_lw_capture_source = {
2195         .num_items = 3,
2196         .items = {
2197                 { "Mic", 0x0 },
2198                 { "Internal Mic", 0x1 },
2199                 { "Line In", 0x2 },
2200         },
2201 };
2202
2203 #define alc880_lg_lw_modes alc880_threestack_modes
2204
2205 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
2206         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2207         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2208         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2209         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
2210         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2211         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2212         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2213         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2214         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2215         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2216         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2217         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2218         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
2219         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
2220         {
2221                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2222                 .name = "Channel Mode",
2223                 .info = alc_ch_mode_info,
2224                 .get = alc_ch_mode_get,
2225                 .put = alc_ch_mode_put,
2226         },
2227         { } /* end */
2228 };
2229
2230 static struct hda_verb alc880_lg_lw_init_verbs[] = {
2231         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2232         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2233         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2234
2235         /* set capture source to mic-in */
2236         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2237         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2238         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2239         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2240         /* speaker-out */
2241         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2242         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2243         /* HP-out */
2244         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2245         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2246         /* mic-in to input */
2247         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2248         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2249         /* built-in mic */
2250         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2251         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2252         /* jack sense */
2253         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2254         { }
2255 };
2256
2257 /* toggle speaker-output according to the hp-jack state */
2258 static void alc880_lg_lw_automute(struct hda_codec *codec)
2259 {
2260         unsigned int present;
2261         unsigned char bits;
2262
2263         present = snd_hda_codec_read(codec, 0x1b, 0,
2264                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2265         bits = present ? HDA_AMP_MUTE : 0;
2266         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
2267                                  HDA_AMP_MUTE, bits);
2268 }
2269
2270 static void alc880_lg_lw_unsol_event(struct hda_codec *codec, unsigned int res)
2271 {
2272         /* Looks like the unsol event is incompatible with the standard
2273          * definition.  4bit tag is placed at 28 bit!
2274          */
2275         if ((res >> 28) == 0x01)
2276                 alc880_lg_lw_automute(codec);
2277 }
2278
2279 static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
2280         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2281         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
2282         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2283         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2284         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2285         HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
2286         { } /* end */
2287 };
2288
2289 static struct hda_input_mux alc880_medion_rim_capture_source = {
2290         .num_items = 2,
2291         .items = {
2292                 { "Mic", 0x0 },
2293                 { "Internal Mic", 0x1 },
2294         },
2295 };
2296
2297 static struct hda_verb alc880_medion_rim_init_verbs[] = {
2298         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2299
2300         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2301         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2302
2303         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2304         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2305         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2306         /* Mic2 (as headphone out) for HP output */
2307         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2308         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2309         /* Internal Speaker */
2310         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2311         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2312
2313         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2314         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2315
2316         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2317         { }
2318 };
2319
2320 /* toggle speaker-output according to the hp-jack state */
2321 static void alc880_medion_rim_automute(struct hda_codec *codec)
2322 {
2323         unsigned int present;
2324         unsigned char bits;
2325
2326         present = snd_hda_codec_read(codec, 0x14, 0,
2327                                      AC_VERB_GET_PIN_SENSE, 0)
2328                 & AC_PINSENSE_PRESENCE;
2329         bits = present ? HDA_AMP_MUTE : 0;
2330         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
2331                                  HDA_AMP_MUTE, bits);
2332         if (present)
2333                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
2334         else
2335                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
2336 }
2337
2338 static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
2339                                           unsigned int res)
2340 {
2341         /* Looks like the unsol event is incompatible with the standard
2342          * definition.  4bit tag is placed at 28 bit!
2343          */
2344         if ((res >> 28) == ALC880_HP_EVENT)
2345                 alc880_medion_rim_automute(codec);
2346 }
2347
2348 #ifdef CONFIG_SND_HDA_POWER_SAVE
2349 static struct hda_amp_list alc880_loopbacks[] = {
2350         { 0x0b, HDA_INPUT, 0 },
2351         { 0x0b, HDA_INPUT, 1 },
2352         { 0x0b, HDA_INPUT, 2 },
2353         { 0x0b, HDA_INPUT, 3 },
2354         { 0x0b, HDA_INPUT, 4 },
2355         { } /* end */
2356 };
2357
2358 static struct hda_amp_list alc880_lg_loopbacks[] = {
2359         { 0x0b, HDA_INPUT, 1 },
2360         { 0x0b, HDA_INPUT, 6 },
2361         { 0x0b, HDA_INPUT, 7 },
2362         { } /* end */
2363 };
2364 #endif
2365
2366 /*
2367  * Common callbacks
2368  */
2369
2370 static int alc_init(struct hda_codec *codec)
2371 {
2372         struct alc_spec *spec = codec->spec;
2373         unsigned int i;
2374
2375         for (i = 0; i < spec->num_init_verbs; i++)
2376                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2377
2378         if (spec->init_hook)
2379                 spec->init_hook(codec);
2380
2381         return 0;
2382 }
2383
2384 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2385 {
2386         struct alc_spec *spec = codec->spec;
2387
2388         if (spec->unsol_event)
2389                 spec->unsol_event(codec, res);
2390 }
2391
2392 #ifdef CONFIG_SND_HDA_POWER_SAVE
2393 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2394 {
2395         struct alc_spec *spec = codec->spec;
2396         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2397 }
2398 #endif
2399
2400 /*
2401  * Analog playback callbacks
2402  */
2403 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
2404                                     struct hda_codec *codec,
2405                                     struct snd_pcm_substream *substream)
2406 {
2407         struct alc_spec *spec = codec->spec;
2408         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2409                                              hinfo);
2410 }
2411
2412 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2413                                        struct hda_codec *codec,
2414                                        unsigned int stream_tag,
2415                                        unsigned int format,
2416                                        struct snd_pcm_substream *substream)
2417 {
2418         struct alc_spec *spec = codec->spec;
2419         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2420                                                 stream_tag, format, substream);
2421 }
2422
2423 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2424                                        struct hda_codec *codec,
2425                                        struct snd_pcm_substream *substream)
2426 {
2427         struct alc_spec *spec = codec->spec;
2428         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2429 }
2430
2431 /*
2432  * Digital out
2433  */
2434 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2435                                         struct hda_codec *codec,
2436                                         struct snd_pcm_substream *substream)
2437 {
2438         struct alc_spec *spec = codec->spec;
2439         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2440 }
2441
2442 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2443                                            struct hda_codec *codec,
2444                                            unsigned int stream_tag,
2445                                            unsigned int format,
2446                                            struct snd_pcm_substream *substream)
2447 {
2448         struct alc_spec *spec = codec->spec;
2449         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2450                                              stream_tag, format, substream);
2451 }
2452
2453 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2454                                          struct hda_codec *codec,
2455                                          struct snd_pcm_substream *substream)
2456 {
2457         struct alc_spec *spec = codec->spec;
2458         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2459 }
2460
2461 /*
2462  * Analog capture
2463  */
2464 static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2465                                       struct hda_codec *codec,
2466                                       unsigned int stream_tag,
2467                                       unsigned int format,
2468                                       struct snd_pcm_substream *substream)
2469 {
2470         struct alc_spec *spec = codec->spec;
2471
2472         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2473                                    stream_tag, 0, format);
2474         return 0;
2475 }
2476
2477 static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2478                                       struct hda_codec *codec,
2479                                       struct snd_pcm_substream *substream)
2480 {
2481         struct alc_spec *spec = codec->spec;
2482
2483         snd_hda_codec_cleanup_stream(codec,
2484                                      spec->adc_nids[substream->number + 1]);
2485         return 0;
2486 }
2487
2488
2489 /*
2490  */
2491 static struct hda_pcm_stream alc880_pcm_analog_playback = {
2492         .substreams = 1,
2493         .channels_min = 2,
2494         .channels_max = 8,
2495         /* NID is set in alc_build_pcms */
2496         .ops = {
2497                 .open = alc880_playback_pcm_open,
2498                 .prepare = alc880_playback_pcm_prepare,
2499                 .cleanup = alc880_playback_pcm_cleanup
2500         },
2501 };
2502
2503 static struct hda_pcm_stream alc880_pcm_analog_capture = {
2504         .substreams = 1,
2505         .channels_min = 2,
2506         .channels_max = 2,
2507         /* NID is set in alc_build_pcms */
2508 };
2509
2510 static struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
2511         .substreams = 1,
2512         .channels_min = 2,
2513         .channels_max = 2,
2514         /* NID is set in alc_build_pcms */
2515 };
2516
2517 static struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
2518         .substreams = 2, /* can be overridden */
2519         .channels_min = 2,
2520         .channels_max = 2,
2521         /* NID is set in alc_build_pcms */
2522         .ops = {
2523                 .prepare = alc880_alt_capture_pcm_prepare,
2524                 .cleanup = alc880_alt_capture_pcm_cleanup
2525         },
2526 };
2527
2528 static struct hda_pcm_stream alc880_pcm_digital_playback = {
2529         .substreams = 1,
2530         .channels_min = 2,
2531         .channels_max = 2,
2532         /* NID is set in alc_build_pcms */
2533         .ops = {
2534                 .open = alc880_dig_playback_pcm_open,
2535                 .close = alc880_dig_playback_pcm_close,
2536                 .prepare = alc880_dig_playback_pcm_prepare
2537         },
2538 };
2539
2540 static struct hda_pcm_stream alc880_pcm_digital_capture = {
2541         .substreams = 1,
2542         .channels_min = 2,
2543         .channels_max = 2,
2544         /* NID is set in alc_build_pcms */
2545 };
2546
2547 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2548 static struct hda_pcm_stream alc_pcm_null_stream = {
2549         .substreams = 0,
2550         .channels_min = 0,
2551         .channels_max = 0,
2552 };
2553
2554 static int alc_build_pcms(struct hda_codec *codec)
2555 {
2556         struct alc_spec *spec = codec->spec;
2557         struct hda_pcm *info = spec->pcm_rec;
2558         int i;
2559
2560         codec->num_pcms = 1;
2561         codec->pcm_info = info;
2562
2563         info->name = spec->stream_name_analog;
2564         if (spec->stream_analog_playback) {
2565                 snd_assert(spec->multiout.dac_nids, return -EINVAL);
2566                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
2567                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2568         }
2569         if (spec->stream_analog_capture) {
2570                 snd_assert(spec->adc_nids, return -EINVAL);
2571                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
2572                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2573         }
2574
2575         if (spec->channel_mode) {
2576                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2577                 for (i = 0; i < spec->num_channel_mode; i++) {
2578                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2579                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2580                         }
2581                 }
2582         }
2583
2584         /* SPDIF for stream index #1 */
2585         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2586                 codec->num_pcms = 2;
2587                 info = spec->pcm_rec + 1;
2588                 info->name = spec->stream_name_digital;
2589                 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2590                 if (spec->multiout.dig_out_nid &&
2591                     spec->stream_digital_playback) {
2592                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
2593                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2594                 }
2595                 if (spec->dig_in_nid &&
2596                     spec->stream_digital_capture) {
2597                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
2598                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2599                 }
2600         }
2601
2602         /* If the use of more than one ADC is requested for the current
2603          * model, configure a second analog capture-only PCM.
2604          */
2605         /* Additional Analaog capture for index #2 */
2606         if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
2607             (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
2608                 codec->num_pcms = 3;
2609                 info = spec->pcm_rec + 2;
2610                 info->name = spec->stream_name_analog;
2611                 if (spec->alt_dac_nid) {
2612                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2613                                 *spec->stream_analog_alt_playback;
2614                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2615                                 spec->alt_dac_nid;
2616                 } else {
2617                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2618                                 alc_pcm_null_stream;
2619                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2620                 }
2621                 if (spec->num_adc_nids > 1) {
2622                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2623                                 *spec->stream_analog_alt_capture;
2624                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2625                                 spec->adc_nids[1];
2626                         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2627                                 spec->num_adc_nids - 1;
2628                 } else {
2629                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2630                                 alc_pcm_null_stream;
2631                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
2632                 }
2633         }
2634
2635         return 0;
2636 }
2637
2638 static void alc_free(struct hda_codec *codec)
2639 {
2640         struct alc_spec *spec = codec->spec;
2641         unsigned int i;
2642
2643         if (!spec)
2644                 return;
2645
2646         if (spec->kctl_alloc) {
2647                 for (i = 0; i < spec->num_kctl_used; i++)
2648                         kfree(spec->kctl_alloc[i].name);
2649                 kfree(spec->kctl_alloc);
2650         }
2651         kfree(spec);
2652         codec->spec = NULL; /* to be sure */
2653 }
2654
2655 /*
2656  */
2657 static struct hda_codec_ops alc_patch_ops = {
2658         .build_controls = alc_build_controls,
2659         .build_pcms = alc_build_pcms,
2660         .init = alc_init,
2661         .free = alc_free,
2662         .unsol_event = alc_unsol_event,
2663 #ifdef CONFIG_SND_HDA_POWER_SAVE
2664         .check_power_status = alc_check_power_status,
2665 #endif
2666 };
2667
2668
2669 /*
2670  * Test configuration for debugging
2671  *
2672  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
2673  * enum controls.
2674  */
2675 #ifdef CONFIG_SND_DEBUG
2676 static hda_nid_t alc880_test_dac_nids[4] = {
2677         0x02, 0x03, 0x04, 0x05
2678 };
2679
2680 static struct hda_input_mux alc880_test_capture_source = {
2681         .num_items = 7,
2682         .items = {
2683                 { "In-1", 0x0 },
2684                 { "In-2", 0x1 },
2685                 { "In-3", 0x2 },
2686                 { "In-4", 0x3 },
2687                 { "CD", 0x4 },
2688                 { "Front", 0x5 },
2689                 { "Surround", 0x6 },
2690         },
2691 };
2692
2693 static struct hda_channel_mode alc880_test_modes[4] = {
2694         { 2, NULL },
2695         { 4, NULL },
2696         { 6, NULL },
2697         { 8, NULL },
2698 };
2699
2700 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
2701                                  struct snd_ctl_elem_info *uinfo)
2702 {
2703         static char *texts[] = {
2704                 "N/A", "Line Out", "HP Out",
2705                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
2706         };
2707         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2708         uinfo->count = 1;
2709         uinfo->value.enumerated.items = 8;
2710         if (uinfo->value.enumerated.item >= 8)
2711                 uinfo->value.enumerated.item = 7;
2712         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2713         return 0;
2714 }
2715
2716 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
2717                                 struct snd_ctl_elem_value *ucontrol)
2718 {
2719         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2720         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2721         unsigned int pin_ctl, item = 0;
2722
2723         pin_ctl = snd_hda_codec_read(codec, nid, 0,
2724                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2725         if (pin_ctl & AC_PINCTL_OUT_EN) {
2726                 if (pin_ctl & AC_PINCTL_HP_EN)
2727                         item = 2;
2728                 else
2729                         item = 1;
2730         } else if (pin_ctl & AC_PINCTL_IN_EN) {
2731                 switch (pin_ctl & AC_PINCTL_VREFEN) {
2732                 case AC_PINCTL_VREF_HIZ: item = 3; break;
2733                 case AC_PINCTL_VREF_50:  item = 4; break;
2734                 case AC_PINCTL_VREF_GRD: item = 5; break;
2735                 case AC_PINCTL_VREF_80:  item = 6; break;
2736                 case AC_PINCTL_VREF_100: item = 7; break;
2737                 }
2738         }
2739         ucontrol->value.enumerated.item[0] = item;
2740         return 0;
2741 }
2742
2743 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
2744                                 struct snd_ctl_elem_value *ucontrol)
2745 {
2746         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2747         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2748         static unsigned int ctls[] = {
2749                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
2750                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
2751                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
2752                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
2753                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
2754                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
2755         };
2756         unsigned int old_ctl, new_ctl;
2757
2758         old_ctl = snd_hda_codec_read(codec, nid, 0,
2759                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2760         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
2761         if (old_ctl != new_ctl) {
2762                 int val;
2763                 snd_hda_codec_write_cache(codec, nid, 0,
2764                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
2765                                           new_ctl);
2766                 val = ucontrol->value.enumerated.item[0] >= 3 ?
2767                         HDA_AMP_MUTE : 0;
2768                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
2769                                          HDA_AMP_MUTE, val);
2770                 return 1;
2771         }
2772         return 0;
2773 }
2774
2775 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
2776                                  struct snd_ctl_elem_info *uinfo)
2777 {
2778         static char *texts[] = {
2779                 "Front", "Surround", "CLFE", "Side"
2780         };
2781         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2782         uinfo->count = 1;
2783         uinfo->value.enumerated.items = 4;
2784         if (uinfo->value.enumerated.item >= 4)
2785                 uinfo->value.enumerated.item = 3;
2786         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2787         return 0;
2788 }
2789
2790 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
2791                                 struct snd_ctl_elem_value *ucontrol)
2792 {
2793         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2794         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2795         unsigned int sel;
2796
2797         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
2798         ucontrol->value.enumerated.item[0] = sel & 3;
2799         return 0;
2800 }
2801
2802 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
2803                                 struct snd_ctl_elem_value *ucontrol)
2804 {
2805         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2806         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2807         unsigned int sel;
2808
2809         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
2810         if (ucontrol->value.enumerated.item[0] != sel) {
2811                 sel = ucontrol->value.enumerated.item[0] & 3;
2812                 snd_hda_codec_write_cache(codec, nid, 0,
2813                                           AC_VERB_SET_CONNECT_SEL, sel);
2814                 return 1;
2815         }
2816         return 0;
2817 }
2818
2819 #define PIN_CTL_TEST(xname,nid) {                       \
2820                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
2821                         .name = xname,                 \
2822                         .info = alc_test_pin_ctl_info, \
2823                         .get = alc_test_pin_ctl_get,   \
2824                         .put = alc_test_pin_ctl_put,   \
2825                         .private_value = nid           \
2826                         }
2827
2828 #define PIN_SRC_TEST(xname,nid) {                       \
2829                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
2830                         .name = xname,                 \
2831                         .info = alc_test_pin_src_info, \
2832                         .get = alc_test_pin_src_get,   \
2833                         .put = alc_test_pin_src_put,   \
2834                         .private_value = nid           \
2835                         }
2836
2837 static struct snd_kcontrol_new alc880_test_mixer[] = {
2838         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2839         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2840         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
2841         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2842         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2843         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2844         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
2845         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2846         PIN_CTL_TEST("Front Pin Mode", 0x14),
2847         PIN_CTL_TEST("Surround Pin Mode", 0x15),
2848         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
2849         PIN_CTL_TEST("Side Pin Mode", 0x17),
2850         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
2851         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
2852         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
2853         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
2854         PIN_SRC_TEST("In-1 Pin Source", 0x18),
2855         PIN_SRC_TEST("In-2 Pin Source", 0x19),
2856         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
2857         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
2858         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
2859         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
2860         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
2861         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
2862         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
2863         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
2864         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
2865         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
2866         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
2867         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
2868         {
2869                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2870                 .name = "Channel Mode",
2871                 .info = alc_ch_mode_info,
2872                 .get = alc_ch_mode_get,
2873                 .put = alc_ch_mode_put,
2874         },
2875         { } /* end */
2876 };
2877
2878 static struct hda_verb alc880_test_init_verbs[] = {
2879         /* Unmute inputs of 0x0c - 0x0f */
2880         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2881         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2882         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2883         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2884         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2885         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2886         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2887         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2888         /* Vol output for 0x0c-0x0f */
2889         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2890         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2891         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2892         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2893         /* Set output pins 0x14-0x17 */
2894         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2895         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2896         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2897         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2898         /* Unmute output pins 0x14-0x17 */
2899         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2900         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2901         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2902         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2903         /* Set input pins 0x18-0x1c */
2904         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2905         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2906         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2907         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2908         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2909         /* Mute input pins 0x18-0x1b */
2910         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2911         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2912         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2913         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2914         /* ADC set up */
2915         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2916         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2917         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2918         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2919         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2920         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2921         /* Analog input/passthru */
2922         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2923         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2924         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2925         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2926         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2927         { }
2928 };
2929 #endif
2930
2931 /*
2932  */
2933
2934 static const char *alc880_models[ALC880_MODEL_LAST] = {
2935         [ALC880_3ST]            = "3stack",
2936         [ALC880_TCL_S700]       = "tcl",
2937         [ALC880_3ST_DIG]        = "3stack-digout",
2938         [ALC880_CLEVO]          = "clevo",
2939         [ALC880_5ST]            = "5stack",
2940         [ALC880_5ST_DIG]        = "5stack-digout",
2941         [ALC880_W810]           = "w810",
2942         [ALC880_Z71V]           = "z71v",
2943         [ALC880_6ST]            = "6stack",
2944         [ALC880_6ST_DIG]        = "6stack-digout",
2945         [ALC880_ASUS]           = "asus",
2946         [ALC880_ASUS_W1V]       = "asus-w1v",
2947         [ALC880_ASUS_DIG]       = "asus-dig",
2948         [ALC880_ASUS_DIG2]      = "asus-dig2",
2949         [ALC880_UNIWILL_DIG]    = "uniwill",
2950         [ALC880_UNIWILL_P53]    = "uniwill-p53",
2951         [ALC880_FUJITSU]        = "fujitsu",
2952         [ALC880_F1734]          = "F1734",
2953         [ALC880_LG]             = "lg",
2954         [ALC880_LG_LW]          = "lg-lw",
2955         [ALC880_MEDION_RIM]     = "medion",
2956 #ifdef CONFIG_SND_DEBUG
2957         [ALC880_TEST]           = "test",
2958 #endif
2959         [ALC880_AUTO]           = "auto",
2960 };
2961
2962 static struct snd_pci_quirk alc880_cfg_tbl[] = {
2963         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
2964         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
2965         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
2966         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
2967         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
2968         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
2969         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
2970         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
2971         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
2972         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
2973         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
2974         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
2975         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
2976         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
2977         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
2978         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
2979         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
2980         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
2981         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
2982         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
2983         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
2984         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS", ALC880_ASUS),
2985         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
2986         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
2987         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
2988         SND_PCI_QUIRK(0x1043, 0, "ASUS", ALC880_ASUS), /* default ASUS */
2989         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
2990         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
2991         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
2992         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
2993         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
2994         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
2995         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
2996         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
2997         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
2998         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
2999         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
3000         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
3001         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
3002         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
3003         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
3004         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
3005         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
3006         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
3007         SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_MEDION_RIM),
3008         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
3009         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
3010         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
3011         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
3012         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
3013         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
3014         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
3015         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
3016         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
3017         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
3018         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
3019         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
3020         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
3021         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
3022         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
3023         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
3024         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
3025         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
3026         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
3027         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
3028         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
3029         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
3030         SND_PCI_QUIRK(0x8086, 0, "Intel mobo", ALC880_3ST), /* default Intel */
3031         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
3032         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
3033         {}
3034 };
3035
3036 /*
3037  * ALC880 codec presets
3038  */
3039 static struct alc_config_preset alc880_presets[] = {
3040         [ALC880_3ST] = {
3041                 .mixers = { alc880_three_stack_mixer },
3042                 .init_verbs = { alc880_volume_init_verbs,
3043                                 alc880_pin_3stack_init_verbs },
3044                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3045                 .dac_nids = alc880_dac_nids,
3046                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3047                 .channel_mode = alc880_threestack_modes,
3048                 .need_dac_fix = 1,
3049                 .input_mux = &alc880_capture_source,
3050         },
3051         [ALC880_3ST_DIG] = {
3052                 .mixers = { alc880_three_stack_mixer },
3053                 .init_verbs = { alc880_volume_init_verbs,
3054                                 alc880_pin_3stack_init_verbs },
3055                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3056                 .dac_nids = alc880_dac_nids,
3057                 .dig_out_nid = ALC880_DIGOUT_NID,
3058                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3059                 .channel_mode = alc880_threestack_modes,
3060                 .need_dac_fix = 1,
3061                 .input_mux = &alc880_capture_source,
3062         },
3063         [ALC880_TCL_S700] = {
3064                 .mixers = { alc880_tcl_s700_mixer },
3065                 .init_verbs = { alc880_volume_init_verbs,
3066                                 alc880_pin_tcl_S700_init_verbs,
3067                                 alc880_gpio2_init_verbs },
3068                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3069                 .dac_nids = alc880_dac_nids,
3070                 .hp_nid = 0x03,
3071                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3072                 .channel_mode = alc880_2_jack_modes,
3073                 .input_mux = &alc880_capture_source,
3074         },
3075         [ALC880_5ST] = {
3076                 .mixers = { alc880_three_stack_mixer,
3077                             alc880_five_stack_mixer},
3078                 .init_verbs = { alc880_volume_init_verbs,
3079                                 alc880_pin_5stack_init_verbs },
3080                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3081                 .dac_nids = alc880_dac_nids,
3082                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3083                 .channel_mode = alc880_fivestack_modes,
3084                 .input_mux = &alc880_capture_source,
3085         },
3086         [ALC880_5ST_DIG] = {
3087                 .mixers = { alc880_three_stack_mixer,
3088                             alc880_five_stack_mixer },
3089                 .init_verbs = { alc880_volume_init_verbs,
3090                                 alc880_pin_5stack_init_verbs },
3091                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3092                 .dac_nids = alc880_dac_nids,
3093                 .dig_out_nid = ALC880_DIGOUT_NID,
3094                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3095                 .channel_mode = alc880_fivestack_modes,
3096                 .input_mux = &alc880_capture_source,
3097         },
3098         [ALC880_6ST] = {
3099                 .mixers = { alc880_six_stack_mixer },
3100                 .init_verbs = { alc880_volume_init_verbs,
3101                                 alc880_pin_6stack_init_verbs },
3102                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3103                 .dac_nids = alc880_6st_dac_nids,
3104                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3105                 .channel_mode = alc880_sixstack_modes,
3106                 .input_mux = &alc880_6stack_capture_source,
3107         },
3108         [ALC880_6ST_DIG] = {
3109                 .mixers = { alc880_six_stack_mixer },
3110                 .init_verbs = { alc880_volume_init_verbs,
3111                                 alc880_pin_6stack_init_verbs },
3112                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3113                 .dac_nids = alc880_6st_dac_nids,
3114                 .dig_out_nid = ALC880_DIGOUT_NID,
3115                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3116                 .channel_mode = alc880_sixstack_modes,
3117                 .input_mux = &alc880_6stack_capture_source,
3118         },
3119         [ALC880_W810] = {
3120                 .mixers = { alc880_w810_base_mixer },
3121                 .init_verbs = { alc880_volume_init_verbs,
3122                                 alc880_pin_w810_init_verbs,
3123                                 alc880_gpio2_init_verbs },
3124                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
3125                 .dac_nids = alc880_w810_dac_nids,
3126                 .dig_out_nid = ALC880_DIGOUT_NID,
3127                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3128                 .channel_mode = alc880_w810_modes,
3129                 .input_mux = &alc880_capture_source,
3130         },
3131         [ALC880_Z71V] = {
3132                 .mixers = { alc880_z71v_mixer },
3133                 .init_verbs = { alc880_volume_init_verbs,
3134                                 alc880_pin_z71v_init_verbs },
3135                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
3136                 .dac_nids = alc880_z71v_dac_nids,
3137                 .dig_out_nid = ALC880_DIGOUT_NID,
3138                 .hp_nid = 0x03,
3139                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3140                 .channel_mode = alc880_2_jack_modes,
3141                 .input_mux = &alc880_capture_source,
3142         },
3143         [ALC880_F1734] = {
3144                 .mixers = { alc880_f1734_mixer },
3145                 .init_verbs = { alc880_volume_init_verbs,
3146                                 alc880_pin_f1734_init_verbs },
3147                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
3148                 .dac_nids = alc880_f1734_dac_nids,
3149                 .hp_nid = 0x02,
3150                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3151                 .channel_mode = alc880_2_jack_modes,
3152                 .input_mux = &alc880_f1734_capture_source,
3153                 .unsol_event = alc880_uniwill_p53_unsol_event,
3154                 .init_hook = alc880_uniwill_p53_hp_automute,
3155         },
3156         [ALC880_ASUS] = {
3157                 .mixers = { alc880_asus_mixer },
3158                 .init_verbs = { alc880_volume_init_verbs,
3159                                 alc880_pin_asus_init_verbs,
3160                                 alc880_gpio1_init_verbs },
3161                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3162                 .dac_nids = alc880_asus_dac_nids,
3163                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3164                 .channel_mode = alc880_asus_modes,
3165                 .need_dac_fix = 1,
3166                 .input_mux = &alc880_capture_source,
3167         },
3168         [ALC880_ASUS_DIG] = {
3169                 .mixers = { alc880_asus_mixer },
3170                 .init_verbs = { alc880_volume_init_verbs,
3171                                 alc880_pin_asus_init_verbs,
3172                                 alc880_gpio1_init_verbs },
3173                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3174                 .dac_nids = alc880_asus_dac_nids,
3175                 .dig_out_nid = ALC880_DIGOUT_NID,
3176                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3177                 .channel_mode = alc880_asus_modes,
3178                 .need_dac_fix = 1,
3179                 .input_mux = &alc880_capture_source,
3180         },
3181         [ALC880_ASUS_DIG2] = {
3182                 .mixers = { alc880_asus_mixer },
3183                 .init_verbs = { alc880_volume_init_verbs,
3184                                 alc880_pin_asus_init_verbs,
3185                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
3186                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3187                 .dac_nids = alc880_asus_dac_nids,
3188                 .dig_out_nid = ALC880_DIGOUT_NID,
3189                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3190                 .channel_mode = alc880_asus_modes,
3191                 .need_dac_fix = 1,
3192                 .input_mux = &alc880_capture_source,
3193         },
3194         [ALC880_ASUS_W1V] = {
3195                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
3196                 .init_verbs = { alc880_volume_init_verbs,
3197                                 alc880_pin_asus_init_verbs,
3198                                 alc880_gpio1_init_verbs },
3199                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3200                 .dac_nids = alc880_asus_dac_nids,
3201                 .dig_out_nid = ALC880_DIGOUT_NID,
3202                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3203                 .channel_mode = alc880_asus_modes,
3204                 .need_dac_fix = 1,
3205                 .input_mux = &alc880_capture_source,
3206         },
3207         [ALC880_UNIWILL_DIG] = {
3208                 .mixers = { alc880_asus_mixer, alc880_pcbeep_mixer },
3209                 .init_verbs = { alc880_volume_init_verbs,
3210                                 alc880_pin_asus_init_verbs },
3211                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3212                 .dac_nids = alc880_asus_dac_nids,
3213                 .dig_out_nid = ALC880_DIGOUT_NID,
3214                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3215                 .channel_mode = alc880_asus_modes,
3216                 .need_dac_fix = 1,
3217                 .input_mux = &alc880_capture_source,
3218         },
3219         [ALC880_UNIWILL] = {
3220                 .mixers = { alc880_uniwill_mixer },
3221                 .init_verbs = { alc880_volume_init_verbs,
3222                                 alc880_uniwill_init_verbs },
3223                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3224                 .dac_nids = alc880_asus_dac_nids,
3225                 .dig_out_nid = ALC880_DIGOUT_NID,
3226                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3227                 .channel_mode = alc880_threestack_modes,
3228                 .need_dac_fix = 1,
3229                 .input_mux = &alc880_capture_source,
3230                 .unsol_event = alc880_uniwill_unsol_event,
3231                 .init_hook = alc880_uniwill_automute,
3232         },
3233         [ALC880_UNIWILL_P53] = {
3234                 .mixers = { alc880_uniwill_p53_mixer },
3235                 .init_verbs = { alc880_volume_init_verbs,
3236                                 alc880_uniwill_p53_init_verbs },
3237                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3238                 .dac_nids = alc880_asus_dac_nids,
3239                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3240                 .channel_mode = alc880_threestack_modes,
3241                 .input_mux = &alc880_capture_source,
3242                 .unsol_event = alc880_uniwill_p53_unsol_event,
3243                 .init_hook = alc880_uniwill_p53_hp_automute,
3244         },
3245         [ALC880_FUJITSU] = {
3246                 .mixers = { alc880_fujitsu_mixer,
3247                             alc880_pcbeep_mixer, },
3248                 .init_verbs = { alc880_volume_init_verbs,
3249                                 alc880_uniwill_p53_init_verbs,
3250                                 alc880_beep_init_verbs },
3251                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3252                 .dac_nids = alc880_dac_nids,
3253                 .dig_out_nid = ALC880_DIGOUT_NID,
3254                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3255                 .channel_mode = alc880_2_jack_modes,
3256                 .input_mux = &alc880_capture_source,
3257                 .unsol_event = alc880_uniwill_p53_unsol_event,
3258                 .init_hook = alc880_uniwill_p53_hp_automute,
3259         },
3260         [ALC880_CLEVO] = {
3261                 .mixers = { alc880_three_stack_mixer },
3262                 .init_verbs = { alc880_volume_init_verbs,
3263                                 alc880_pin_clevo_init_verbs },
3264                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3265                 .dac_nids = alc880_dac_nids,
3266                 .hp_nid = 0x03,
3267                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3268                 .channel_mode = alc880_threestack_modes,
3269                 .need_dac_fix = 1,
3270                 .input_mux = &alc880_capture_source,
3271         },
3272         [ALC880_LG] = {
3273                 .mixers = { alc880_lg_mixer },
3274                 .init_verbs = { alc880_volume_init_verbs,
3275                                 alc880_lg_init_verbs },
3276                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
3277                 .dac_nids = alc880_lg_dac_nids,
3278                 .dig_out_nid = ALC880_DIGOUT_NID,
3279                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
3280                 .channel_mode = alc880_lg_ch_modes,
3281                 .need_dac_fix = 1,
3282                 .input_mux = &alc880_lg_capture_source,
3283                 .unsol_event = alc880_lg_unsol_event,
3284                 .init_hook = alc880_lg_automute,
3285 #ifdef CONFIG_SND_HDA_POWER_SAVE
3286                 .loopbacks = alc880_lg_loopbacks,
3287 #endif
3288         },
3289         [ALC880_LG_LW] = {
3290                 .mixers = { alc880_lg_lw_mixer },
3291                 .init_verbs = { alc880_volume_init_verbs,
3292                                 alc880_lg_lw_init_verbs },
3293                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3294                 .dac_nids = alc880_dac_nids,
3295                 .dig_out_nid = ALC880_DIGOUT_NID,
3296                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
3297                 .channel_mode = alc880_lg_lw_modes,
3298                 .input_mux = &alc880_lg_lw_capture_source,
3299                 .unsol_event = alc880_lg_lw_unsol_event,
3300                 .init_hook = alc880_lg_lw_automute,
3301         },
3302         [ALC880_MEDION_RIM] = {
3303                 .mixers = { alc880_medion_rim_mixer },
3304                 .init_verbs = { alc880_volume_init_verbs,
3305                                 alc880_medion_rim_init_verbs,
3306                                 alc_gpio2_init_verbs },
3307                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3308                 .dac_nids = alc880_dac_nids,
3309                 .dig_out_nid = ALC880_DIGOUT_NID,
3310                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3311                 .channel_mode = alc880_2_jack_modes,
3312                 .input_mux = &alc880_medion_rim_capture_source,
3313                 .unsol_event = alc880_medion_rim_unsol_event,
3314                 .init_hook = alc880_medion_rim_automute,
3315         },
3316 #ifdef CONFIG_SND_DEBUG
3317         [ALC880_TEST] = {
3318                 .mixers = { alc880_test_mixer },
3319                 .init_verbs = { alc880_test_init_verbs },
3320                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
3321                 .dac_nids = alc880_test_dac_nids,
3322                 .dig_out_nid = ALC880_DIGOUT_NID,
3323                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
3324                 .channel_mode = alc880_test_modes,
3325                 .input_mux = &alc880_test_capture_source,
3326         },
3327 #endif
3328 };
3329
3330 /*
3331  * Automatic parse of I/O pins from the BIOS configuration
3332  */
3333
3334 #define NUM_CONTROL_ALLOC       32
3335 #define NUM_VERB_ALLOC          32
3336
3337 enum {
3338         ALC_CTL_WIDGET_VOL,
3339         ALC_CTL_WIDGET_MUTE,
3340         ALC_CTL_BIND_MUTE,
3341 };
3342 static struct snd_kcontrol_new alc880_control_templates[] = {
3343         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
3344         HDA_CODEC_MUTE(NULL, 0, 0, 0),
3345         HDA_BIND_MUTE(NULL, 0, 0, 0),
3346 };
3347
3348 /* add dynamic controls */
3349 static int add_control(struct alc_spec *spec, int type, const char *name,
3350                        unsigned long val)
3351 {
3352         struct snd_kcontrol_new *knew;
3353
3354         if (spec->num_kctl_used >= spec->num_kctl_alloc) {
3355                 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
3356
3357                 /* array + terminator */
3358                 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL);
3359                 if (!knew)
3360                         return -ENOMEM;
3361                 if (spec->kctl_alloc) {
3362                         memcpy(knew, spec->kctl_alloc,
3363                                sizeof(*knew) * spec->num_kctl_alloc);
3364                         kfree(spec->kctl_alloc);
3365                 }
3366                 spec->kctl_alloc = knew;
3367                 spec->num_kctl_alloc = num;
3368         }
3369
3370         knew = &spec->kctl_alloc[spec->num_kctl_used];
3371         *knew = alc880_control_templates[type];
3372         knew->name = kstrdup(name, GFP_KERNEL);
3373         if (!knew->name)
3374                 return -ENOMEM;
3375         knew->private_value = val;
3376         spec->num_kctl_used++;
3377         return 0;
3378 }
3379
3380 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
3381 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
3382 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
3383 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
3384 #define alc880_is_input_pin(nid)        ((nid) >= 0x18)
3385 #define alc880_input_pin_idx(nid)       ((nid) - 0x18)
3386 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
3387 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
3388 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
3389 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
3390 #define ALC880_PIN_CD_NID               0x1c
3391
3392 /* fill in the dac_nids table from the parsed pin configuration */
3393 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
3394                                      const struct auto_pin_cfg *cfg)
3395 {
3396         hda_nid_t nid;
3397         int assigned[4];
3398         int i, j;
3399
3400         memset(assigned, 0, sizeof(assigned));
3401         spec->multiout.dac_nids = spec->private_dac_nids;
3402
3403         /* check the pins hardwired to audio widget */
3404         for (i = 0; i < cfg->line_outs; i++) {
3405                 nid = cfg->line_out_pins[i];
3406                 if (alc880_is_fixed_pin(nid)) {
3407                         int idx = alc880_fixed_pin_idx(nid);
3408                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
3409                         assigned[idx] = 1;
3410                 }
3411         }
3412         /* left pins can be connect to any audio widget */
3413         for (i = 0; i < cfg->line_outs; i++) {
3414                 nid = cfg->line_out_pins[i];
3415                 if (alc880_is_fixed_pin(nid))
3416                         continue;
3417                 /* search for an empty channel */
3418                 for (j = 0; j < cfg->line_outs; j++) {
3419                         if (!assigned[j]) {
3420                                 spec->multiout.dac_nids[i] =
3421                                         alc880_idx_to_dac(j);
3422                                 assigned[j] = 1;
3423                                 break;
3424                         }
3425                 }
3426         }
3427         spec->multiout.num_dacs = cfg->line_outs;
3428         return 0;
3429 }
3430
3431 /* add playback controls from the parsed DAC table */
3432 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
3433                                              const struct auto_pin_cfg *cfg)
3434 {
3435         char name[32];
3436         static const char *chname[4] = {
3437                 "Front", "Surround", NULL /*CLFE*/, "Side"
3438         };
3439         hda_nid_t nid;
3440         int i, err;
3441
3442         for (i = 0; i < cfg->line_outs; i++) {
3443                 if (!spec->multiout.dac_nids[i])
3444                         continue;
3445                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
3446                 if (i == 2) {
3447                         /* Center/LFE */
3448                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3449                                           "Center Playback Volume",
3450                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
3451                                                               HDA_OUTPUT));
3452                         if (err < 0)
3453                                 return err;
3454                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3455                                           "LFE Playback Volume",
3456                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
3457                                                               HDA_OUTPUT));
3458                         if (err < 0)
3459                                 return err;
3460                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3461                                           "Center Playback Switch",
3462                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
3463                                                               HDA_INPUT));
3464                         if (err < 0)
3465                                 return err;
3466                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3467                                           "LFE Playback Switch",
3468                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
3469                                                               HDA_INPUT));
3470                         if (err < 0)
3471                                 return err;
3472                 } else {
3473                         sprintf(name, "%s Playback Volume", chname[i]);
3474                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3475                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3476                                                               HDA_OUTPUT));
3477                         if (err < 0)
3478                                 return err;
3479                         sprintf(name, "%s Playback Switch", chname[i]);
3480                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3481                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
3482                                                               HDA_INPUT));
3483                         if (err < 0)
3484                                 return err;
3485                 }
3486         }
3487         return 0;
3488 }
3489
3490 /* add playback controls for speaker and HP outputs */
3491 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
3492                                         const char *pfx)
3493 {
3494         hda_nid_t nid;
3495         int err;
3496         char name[32];
3497
3498         if (!pin)
3499                 return 0;
3500
3501         if (alc880_is_fixed_pin(pin)) {
3502                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
3503                 /* specify the DAC as the extra output */
3504                 if (!spec->multiout.hp_nid)
3505                         spec->multiout.hp_nid = nid;
3506                 else
3507                         spec->multiout.extra_out_nid[0] = nid;
3508                 /* control HP volume/switch on the output mixer amp */
3509                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
3510                 sprintf(name, "%s Playback Volume", pfx);
3511                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3512                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3513                 if (err < 0)
3514                         return err;
3515                 sprintf(name, "%s Playback Switch", pfx);
3516                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3517                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
3518                 if (err < 0)
3519                         return err;
3520         } else if (alc880_is_multi_pin(pin)) {
3521                 /* set manual connection */
3522                 /* we have only a switch on HP-out PIN */
3523                 sprintf(name, "%s Playback Switch", pfx);
3524                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3525                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3526                 if (err < 0)
3527                         return err;
3528         }
3529         return 0;
3530 }
3531
3532 /* create input playback/capture controls for the given pin */
3533 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
3534                             const char *ctlname,
3535                             int idx, hda_nid_t mix_nid)
3536 {
3537         char name[32];
3538         int err;
3539
3540         sprintf(name, "%s Playback Volume", ctlname);
3541         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3542                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3543         if (err < 0)
3544                 return err;
3545         sprintf(name, "%s Playback Switch", ctlname);
3546         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3547                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3548         if (err < 0)
3549                 return err;
3550         return 0;
3551 }
3552
3553 /* create playback/capture controls for input pins */
3554 static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
3555                                                 const struct auto_pin_cfg *cfg)
3556 {
3557         struct hda_input_mux *imux = &spec->private_imux;
3558         int i, err, idx;
3559
3560         for (i = 0; i < AUTO_PIN_LAST; i++) {
3561                 if (alc880_is_input_pin(cfg->input_pins[i])) {
3562                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
3563                         err = new_analog_input(spec, cfg->input_pins[i],
3564                                                auto_pin_cfg_labels[i],
3565                                                idx, 0x0b);
3566                         if (err < 0)
3567                                 return err;
3568                         imux->items[imux->num_items].label =
3569                                 auto_pin_cfg_labels[i];
3570                         imux->items[imux->num_items].index =
3571                                 alc880_input_pin_idx(cfg->input_pins[i]);
3572                         imux->num_items++;
3573                 }
3574         }
3575         return 0;
3576 }
3577
3578 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
3579                                unsigned int pin_type)
3580 {
3581         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3582                             pin_type);
3583         /* unmute pin */
3584         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3585                             AMP_OUT_UNMUTE);
3586 }
3587
3588 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
3589                                               hda_nid_t nid, int pin_type,
3590                                               int dac_idx)
3591 {
3592         alc_set_pin_output(codec, nid, pin_type);
3593         /* need the manual connection? */
3594         if (alc880_is_multi_pin(nid)) {
3595                 struct alc_spec *spec = codec->spec;
3596                 int idx = alc880_multi_pin_idx(nid);
3597                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
3598                                     AC_VERB_SET_CONNECT_SEL,
3599                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
3600         }
3601 }
3602
3603 static int get_pin_type(int line_out_type)
3604 {
3605         if (line_out_type == AUTO_PIN_HP_OUT)
3606                 return PIN_HP;
3607         else
3608                 return PIN_OUT;
3609 }
3610
3611 static void alc880_auto_init_multi_out(struct hda_codec *codec)
3612 {
3613         struct alc_spec *spec = codec->spec;
3614         int i;
3615         
3616         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
3617         for (i = 0; i < spec->autocfg.line_outs; i++) {
3618                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3619                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3620                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
3621         }
3622 }
3623
3624 static void alc880_auto_init_extra_out(struct hda_codec *codec)
3625 {
3626         struct alc_spec *spec = codec->spec;
3627         hda_nid_t pin;
3628
3629         pin = spec->autocfg.speaker_pins[0];
3630         if (pin) /* connect to front */
3631                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
3632         pin = spec->autocfg.hp_pins[0];
3633         if (pin) /* connect to front */
3634                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
3635 }
3636
3637 static void alc880_auto_init_analog_input(struct hda_codec *codec)
3638 {
3639         struct alc_spec *spec = codec->spec;
3640         int i;
3641
3642         for (i = 0; i < AUTO_PIN_LAST; i++) {
3643                 hda_nid_t nid = spec->autocfg.input_pins[i];
3644                 if (alc880_is_input_pin(nid)) {
3645                         snd_hda_codec_write(codec, nid, 0,
3646                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
3647                                             i <= AUTO_PIN_FRONT_MIC ?
3648                                             PIN_VREF80 : PIN_IN);
3649                         if (nid != ALC880_PIN_CD_NID)
3650                                 snd_hda_codec_write(codec, nid, 0,
3651                                                     AC_VERB_SET_AMP_GAIN_MUTE,
3652                                                     AMP_OUT_MUTE);
3653                 }
3654         }
3655 }
3656
3657 /* parse the BIOS configuration and set up the alc_spec */
3658 /* return 1 if successful, 0 if the proper config is not found,
3659  * or a negative error code
3660  */
3661 static int alc880_parse_auto_config(struct hda_codec *codec)
3662 {
3663         struct alc_spec *spec = codec->spec;
3664         int err;
3665         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
3666
3667         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
3668                                            alc880_ignore);
3669         if (err < 0)
3670                 return err;
3671         if (!spec->autocfg.line_outs)
3672                 return 0; /* can't find valid BIOS pin config */
3673
3674         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
3675         if (err < 0)
3676                 return err;
3677         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
3678         if (err < 0)
3679                 return err;
3680         err = alc880_auto_create_extra_out(spec,
3681                                            spec->autocfg.speaker_pins[0],
3682                                            "Speaker");
3683         if (err < 0)
3684                 return err;
3685         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
3686                                            "Headphone");
3687         if (err < 0)
3688                 return err;
3689         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
3690         if (err < 0)
3691                 return err;
3692
3693         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3694
3695         if (spec->autocfg.dig_out_pin)
3696                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
3697         if (spec->autocfg.dig_in_pin)
3698                 spec->dig_in_nid = ALC880_DIGIN_NID;
3699
3700         if (spec->kctl_alloc)
3701                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
3702
3703         spec->init_verbs[spec->num_init_verbs++] = alc880_volume_init_verbs;
3704
3705         spec->num_mux_defs = 1;
3706         spec->input_mux = &spec->private_imux;
3707
3708         return 1;
3709 }
3710
3711 /* additional initialization for auto-configuration model */
3712 static void alc880_auto_init(struct hda_codec *codec)
3713 {
3714         struct alc_spec *spec = codec->spec;
3715         alc880_auto_init_multi_out(codec);
3716         alc880_auto_init_extra_out(codec);
3717         alc880_auto_init_analog_input(codec);
3718         if (spec->unsol_event)
3719                 alc_sku_automute(codec);
3720 }
3721
3722 /*
3723  * OK, here we have finally the patch for ALC880
3724  */
3725
3726 static int patch_alc880(struct hda_codec *codec)
3727 {
3728         struct alc_spec *spec;
3729         int board_config;
3730         int err;
3731
3732         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3733         if (spec == NULL)
3734                 return -ENOMEM;
3735
3736         codec->spec = spec;
3737
3738         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
3739                                                   alc880_models,
3740                                                   alc880_cfg_tbl);
3741         if (board_config < 0) {
3742                 printk(KERN_INFO "hda_codec: Unknown model for ALC880, "
3743                        "trying auto-probe from BIOS...\n");
3744                 board_config = ALC880_AUTO;
3745         }
3746
3747         if (board_config == ALC880_AUTO) {
3748                 /* automatic parse from the BIOS config */
3749                 err = alc880_parse_auto_config(codec);
3750                 if (err < 0) {
3751                         alc_free(codec);
3752                         return err;
3753                 } else if (!err) {
3754                         printk(KERN_INFO
3755                                "hda_codec: Cannot set up configuration "
3756                                "from BIOS.  Using 3-stack mode...\n");
3757                         board_config = ALC880_3ST;
3758                 }
3759         }
3760
3761         if (board_config != ALC880_AUTO)
3762                 setup_preset(spec, &alc880_presets[board_config]);
3763
3764         spec->stream_name_analog = "ALC880 Analog";
3765         spec->stream_analog_playback = &alc880_pcm_analog_playback;
3766         spec->stream_analog_capture = &alc880_pcm_analog_capture;
3767         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
3768
3769         spec->stream_name_digital = "ALC880 Digital";
3770         spec->stream_digital_playback = &alc880_pcm_digital_playback;
3771         spec->stream_digital_capture = &alc880_pcm_digital_capture;
3772
3773         if (!spec->adc_nids && spec->input_mux) {
3774                 /* check whether NID 0x07 is valid */
3775                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
3776                 /* get type */
3777                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
3778                 if (wcap != AC_WID_AUD_IN) {
3779                         spec->adc_nids = alc880_adc_nids_alt;
3780                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
3781                         spec->mixers[spec->num_mixers] =
3782                                 alc880_capture_alt_mixer;
3783                         spec->num_mixers++;
3784                 } else {
3785                         spec->adc_nids = alc880_adc_nids;
3786                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
3787                         spec->mixers[spec->num_mixers] = alc880_capture_mixer;
3788                         spec->num_mixers++;
3789                 }
3790         }
3791
3792         spec->vmaster_nid = 0x0c;
3793
3794         codec->patch_ops = alc_patch_ops;
3795         if (board_config == ALC880_AUTO)
3796                 spec->init_hook = alc880_auto_init;
3797 #ifdef CONFIG_SND_HDA_POWER_SAVE
3798         if (!spec->loopback.amplist)
3799                 spec->loopback.amplist = alc880_loopbacks;
3800 #endif
3801
3802         return 0;
3803 }
3804
3805
3806 /*
3807  * ALC260 support
3808  */
3809
3810 static hda_nid_t alc260_dac_nids[1] = {
3811         /* front */
3812         0x02,
3813 };
3814
3815 static hda_nid_t alc260_adc_nids[1] = {
3816         /* ADC0 */
3817         0x04,
3818 };
3819
3820 static hda_nid_t alc260_adc_nids_alt[1] = {
3821         /* ADC1 */
3822         0x05,
3823 };
3824
3825 static hda_nid_t alc260_hp_adc_nids[2] = {
3826         /* ADC1, 0 */
3827         0x05, 0x04
3828 };
3829
3830 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
3831  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
3832  */
3833 static hda_nid_t alc260_dual_adc_nids[2] = {
3834         /* ADC0, ADC1 */
3835         0x04, 0x05
3836 };
3837
3838 #define ALC260_DIGOUT_NID       0x03
3839 #define ALC260_DIGIN_NID        0x06
3840
3841 static struct hda_input_mux alc260_capture_source = {
3842         .num_items = 4,
3843         .items = {
3844                 { "Mic", 0x0 },
3845                 { "Front Mic", 0x1 },
3846                 { "Line", 0x2 },
3847                 { "CD", 0x4 },
3848         },
3849 };
3850
3851 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
3852  * headphone jack and the internal CD lines since these are the only pins at
3853  * which audio can appear.  For flexibility, also allow the option of
3854  * recording the mixer output on the second ADC (ADC0 doesn't have a
3855  * connection to the mixer output).
3856  */
3857 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
3858         {
3859                 .num_items = 3,
3860                 .items = {
3861                         { "Mic/Line", 0x0 },
3862                         { "CD", 0x4 },
3863                         { "Headphone", 0x2 },
3864                 },
3865         },
3866         {
3867                 .num_items = 4,
3868                 .items = {
3869                         { "Mic/Line", 0x0 },
3870                         { "CD", 0x4 },
3871                         { "Headphone", 0x2 },
3872                         { "Mixer", 0x5 },
3873                 },
3874         },
3875
3876 };
3877
3878 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
3879  * the Fujitsu S702x, but jacks are marked differently.
3880  */
3881 static struct hda_input_mux alc260_acer_capture_sources[2] = {
3882         {
3883                 .num_items = 4,
3884                 .items = {
3885                         { "Mic", 0x0 },
3886                         { "Line", 0x2 },
3887                         { "CD", 0x4 },
3888                         { "Headphone", 0x5 },
3889                 },
3890         },
3891         {
3892                 .num_items = 5,
3893                 .items = {
3894                         { "Mic", 0x0 },
3895                         { "Line", 0x2 },
3896                         { "CD", 0x4 },
3897                         { "Headphone", 0x6 },
3898                         { "Mixer", 0x5 },
3899                 },
3900         },
3901 };
3902 /*
3903  * This is just place-holder, so there's something for alc_build_pcms to look
3904  * at when it calculates the maximum number of channels. ALC260 has no mixer
3905  * element which allows changing the channel mode, so the verb list is
3906  * never used.
3907  */
3908 static struct hda_channel_mode alc260_modes[1] = {
3909         { 2, NULL },
3910 };
3911
3912
3913 /* Mixer combinations
3914  *
3915  * basic: base_output + input + pc_beep + capture
3916  * HP: base_output + input + capture_alt
3917  * HP_3013: hp_3013 + input + capture
3918  * fujitsu: fujitsu + capture
3919  * acer: acer + capture
3920  */
3921
3922 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
3923         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3924         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
3925         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
3926         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
3927         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
3928         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
3929         { } /* end */
3930 };
3931
3932 static struct snd_kcontrol_new alc260_input_mixer[] = {
3933         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3934         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3935         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
3936         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
3937         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
3938         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
3939         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
3940         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
3941         { } /* end */
3942 };
3943
3944 static struct snd_kcontrol_new alc260_pc_beep_mixer[] = {
3945         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT),
3946         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT),
3947         { } /* end */
3948 };
3949
3950 /* update HP, line and mono out pins according to the master switch */
3951 static void alc260_hp_master_update(struct hda_codec *codec,
3952                                     hda_nid_t hp, hda_nid_t line,
3953                                     hda_nid_t mono)
3954 {
3955         struct alc_spec *spec = codec->spec;
3956         unsigned int val = spec->master_sw ? PIN_HP : 0;
3957         /* change HP and line-out pins */
3958         snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3959                             val);
3960         snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3961                             val);
3962         /* mono (speaker) depending on the HP jack sense */
3963         val = (val && !spec->jack_present) ? PIN_OUT : 0;
3964         snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3965                             val);
3966 }
3967
3968 static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
3969                                    struct snd_ctl_elem_value *ucontrol)
3970 {
3971         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3972         struct alc_spec *spec = codec->spec;
3973         *ucontrol->value.integer.value = spec->master_sw;
3974         return 0;
3975 }
3976
3977 static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
3978                                    struct snd_ctl_elem_value *ucontrol)
3979 {
3980         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3981         struct alc_spec *spec = codec->spec;
3982         int val = !!*ucontrol->value.integer.value;
3983         hda_nid_t hp, line, mono;
3984
3985         if (val == spec->master_sw)
3986                 return 0;
3987         spec->master_sw = val;
3988         hp = (kcontrol->private_value >> 16) & 0xff;
3989         line = (kcontrol->private_value >> 8) & 0xff;
3990         mono = kcontrol->private_value & 0xff;
3991         alc260_hp_master_update(codec, hp, line, mono);
3992         return 1;
3993 }
3994
3995 static struct snd_kcontrol_new alc260_hp_output_mixer[] = {
3996         {
3997                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3998                 .name = "Master Playback Switch",
3999                 .info = snd_ctl_boolean_mono_info,
4000                 .get = alc260_hp_master_sw_get,
4001                 .put = alc260_hp_master_sw_put,
4002                 .private_value = (0x0f << 16) | (0x10 << 8) | 0x11
4003         },
4004         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4005         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4006         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4007         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4008         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4009                               HDA_OUTPUT),
4010         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4011         { } /* end */
4012 };
4013
4014 static struct hda_verb alc260_hp_unsol_verbs[] = {
4015         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4016         {},
4017 };
4018
4019 static void alc260_hp_automute(struct hda_codec *codec)
4020 {
4021         struct alc_spec *spec = codec->spec;
4022         unsigned int present;
4023
4024         present = snd_hda_codec_read(codec, 0x10, 0,
4025                                      AC_VERB_GET_PIN_SENSE, 0);
4026         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4027         alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
4028 }
4029
4030 static void alc260_hp_unsol_event(struct hda_codec *codec, unsigned int res)
4031 {
4032         if ((res >> 26) == ALC880_HP_EVENT)
4033                 alc260_hp_automute(codec);
4034 }
4035
4036 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
4037         {
4038                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4039                 .name = "Master Playback Switch",
4040                 .info = snd_ctl_boolean_mono_info,
4041                 .get = alc260_hp_master_sw_get,
4042                 .put = alc260_hp_master_sw_put,
4043                 .private_value = (0x10 << 16) | (0x15 << 8) | 0x11
4044         },
4045         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4046         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4047         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
4048         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
4049         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4050         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
4051         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4052         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
4053         { } /* end */
4054 };
4055
4056 static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
4057         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4058         {},
4059 };
4060
4061 static void alc260_hp_3013_automute(struct hda_codec *codec)
4062 {
4063         struct alc_spec *spec = codec->spec;
4064         unsigned int present;
4065
4066         present = snd_hda_codec_read(codec, 0x15, 0,
4067                                      AC_VERB_GET_PIN_SENSE, 0);
4068         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4069         alc260_hp_master_update(codec, 0x10, 0x15, 0x11);
4070 }
4071
4072 static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
4073                                        unsigned int res)
4074 {
4075         if ((res >> 26) == ALC880_HP_EVENT)
4076                 alc260_hp_3013_automute(codec);
4077 }
4078
4079 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12, 
4080  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
4081  */
4082 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
4083         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4084         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
4085         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4086         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4087         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4088         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
4089         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
4090         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
4091         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4092         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4093         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4094         HDA_BIND_MUTE("Speaker Playback Switch", 0x09, 2, HDA_INPUT),
4095         { } /* end */
4096 };
4097
4098 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
4099  * versions of the ALC260 don't act on requests to enable mic bias from NID
4100  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
4101  * datasheet doesn't mention this restriction.  At this stage it's not clear
4102  * whether this behaviour is intentional or is a hardware bug in chip
4103  * revisions available in early 2006.  Therefore for now allow the
4104  * "Headphone Jack Mode" control to span all choices, but if it turns out
4105  * that the lack of mic bias for this NID is intentional we could change the
4106  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4107  *
4108  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
4109  * don't appear to make the mic bias available from the "line" jack, even
4110  * though the NID used for this jack (0x14) can supply it.  The theory is
4111  * that perhaps Acer have included blocking capacitors between the ALC260
4112  * and the output jack.  If this turns out to be the case for all such
4113  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
4114  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
4115  *
4116  * The C20x Tablet series have a mono internal speaker which is controlled
4117  * via the chip's Mono sum widget and pin complex, so include the necessary
4118  * controls for such models.  On models without a "mono speaker" the control
4119  * won't do anything.
4120  */
4121 static struct snd_kcontrol_new alc260_acer_mixer[] = {
4122         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4123         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
4124         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
4125         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4126                               HDA_OUTPUT),
4127         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2,
4128                            HDA_INPUT),
4129         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4130         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4131         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4132         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4133         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4134         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4135         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4136         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4137         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4138         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4139         { } /* end */
4140 };
4141
4142 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
4143  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
4144  */
4145 static struct snd_kcontrol_new alc260_will_mixer[] = {
4146         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4147         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4148         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4149         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4150         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4151         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4152         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4153         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4154         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4155         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4156         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4157         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4158         { } /* end */
4159 };
4160
4161 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
4162  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
4163  */
4164 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
4165         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4166         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4167         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4168         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4169         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4170         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
4171         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
4172         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4173         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4174         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4175         { } /* end */
4176 };
4177
4178 /* capture mixer elements */
4179 static struct snd_kcontrol_new alc260_capture_mixer[] = {
4180         HDA_CODEC_VOLUME("Capture Volume", 0x04, 0x0, HDA_INPUT),
4181         HDA_CODEC_MUTE("Capture Switch", 0x04, 0x0, HDA_INPUT),
4182         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x05, 0x0, HDA_INPUT),
4183         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x05, 0x0, HDA_INPUT),
4184         {
4185                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4186                 /* The multiple "Capture Source" controls confuse alsamixer
4187                  * So call somewhat different..
4188                  */
4189                 /* .name = "Capture Source", */
4190                 .name = "Input Source",
4191                 .count = 2,
4192                 .info = alc_mux_enum_info,
4193                 .get = alc_mux_enum_get,
4194                 .put = alc_mux_enum_put,
4195         },
4196         { } /* end */
4197 };
4198
4199 static struct snd_kcontrol_new alc260_capture_alt_mixer[] = {
4200         HDA_CODEC_VOLUME("Capture Volume", 0x05, 0x0, HDA_INPUT),
4201         HDA_CODEC_MUTE("Capture Switch", 0x05, 0x0, HDA_INPUT),
4202         {
4203                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4204                 /* The multiple "Capture Source" controls confuse alsamixer
4205                  * So call somewhat different..
4206                  */
4207                 /* .name = "Capture Source", */
4208                 .name = "Input Source",
4209                 .count = 1,
4210                 .info = alc_mux_enum_info,
4211                 .get = alc_mux_enum_get,
4212                 .put = alc_mux_enum_put,
4213         },
4214         { } /* end */
4215 };
4216
4217 /*
4218  * initialization verbs
4219  */
4220 static struct hda_verb alc260_init_verbs[] = {
4221         /* Line In pin widget for input */
4222         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4223         /* CD pin widget for input */
4224         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4225         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4226         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4227         /* Mic2 (front panel) pin widget for input and vref at 80% */
4228         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4229         /* LINE-2 is used for line-out in rear */
4230         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4231         /* select line-out */
4232         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
4233         /* LINE-OUT pin */
4234         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4235         /* enable HP */
4236         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4237         /* enable Mono */
4238         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4239         /* mute capture amp left and right */
4240         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4241         /* set connection select to line in (default select for this ADC) */
4242         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4243         /* mute capture amp left and right */
4244         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4245         /* set connection select to line in (default select for this ADC) */
4246         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
4247         /* set vol=0 Line-Out mixer amp left and right */
4248         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4249         /* unmute pin widget amp left and right (no gain on this amp) */
4250         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4251         /* set vol=0 HP mixer amp left and right */
4252         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4253         /* unmute pin widget amp left and right (no gain on this amp) */
4254         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4255         /* set vol=0 Mono mixer amp left and right */
4256         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4257         /* unmute pin widget amp left and right (no gain on this amp) */
4258         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4259         /* unmute LINE-2 out pin */
4260         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4261         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4262          * Line In 2 = 0x03
4263          */
4264         /* mute analog inputs */
4265         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4266         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4267         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4268         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4269         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4270         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4271         /* mute Front out path */
4272         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4273         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4274         /* mute Headphone out path */
4275         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4276         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4277         /* mute Mono out path */
4278         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4279         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4280         { }
4281 };
4282
4283 #if 0 /* should be identical with alc260_init_verbs? */
4284 static struct hda_verb alc260_hp_init_verbs[] = {
4285         /* Headphone and output */
4286         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4287         /* mono output */
4288         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4289         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4290         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4291         /* Mic2 (front panel) pin widget for input and vref at 80% */
4292         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4293         /* Line In pin widget for input */
4294         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4295         /* Line-2 pin widget for output */
4296         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4297         /* CD pin widget for input */
4298         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4299         /* unmute amp left and right */
4300         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4301         /* set connection select to line in (default select for this ADC) */
4302         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4303         /* unmute Line-Out mixer amp left and right (volume = 0) */
4304         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4305         /* mute pin widget amp left and right (no gain on this amp) */
4306         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4307         /* unmute HP mixer amp left and right (volume = 0) */
4308         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4309         /* mute pin widget amp left and right (no gain on this amp) */
4310         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4311         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4312          * Line In 2 = 0x03
4313          */
4314         /* mute analog inputs */
4315         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4316         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4317         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4318         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4319         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4320         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4321         /* Unmute Front out path */
4322         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4323         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4324         /* Unmute Headphone out path */
4325         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4326         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4327         /* Unmute Mono out path */
4328         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4329         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4330         { }
4331 };
4332 #endif
4333
4334 static struct hda_verb alc260_hp_3013_init_verbs[] = {
4335         /* Line out and output */
4336         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4337         /* mono output */
4338         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4339         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4340         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4341         /* Mic2 (front panel) pin widget for input and vref at 80% */
4342         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4343         /* Line In pin widget for input */
4344         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4345         /* Headphone pin widget for output */
4346         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4347         /* CD pin widget for input */
4348         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4349         /* unmute amp left and right */
4350         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4351         /* set connection select to line in (default select for this ADC) */
4352         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4353         /* unmute Line-Out mixer amp left and right (volume = 0) */
4354         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4355         /* mute pin widget amp left and right (no gain on this amp) */
4356         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4357         /* unmute HP mixer amp left and right (volume = 0) */
4358         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4359         /* mute pin widget amp left and right (no gain on this amp) */
4360         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4361         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4362          * Line In 2 = 0x03
4363          */
4364         /* mute analog inputs */
4365         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4366         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4367         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4368         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4369         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4370         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4371         /* Unmute Front out path */
4372         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4373         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4374         /* Unmute Headphone out path */
4375         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4376         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4377         /* Unmute Mono out path */
4378         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4379         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4380         { }
4381 };
4382
4383 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
4384  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
4385  * audio = 0x16, internal speaker = 0x10.
4386  */
4387 static struct hda_verb alc260_fujitsu_init_verbs[] = {
4388         /* Disable all GPIOs */
4389         {0x01, AC_VERB_SET_GPIO_MASK, 0},
4390         /* Internal speaker is connected to headphone pin */
4391         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4392         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
4393         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4394         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
4395         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4396         /* Ensure all other unused pins are disabled and muted. */
4397         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4398         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4399         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4400         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4401         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4402         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4403         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4404         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4405
4406         /* Disable digital (SPDIF) pins */
4407         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4408         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4409
4410         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus 
4411          * when acting as an output.
4412          */
4413         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4414
4415         /* Start with output sum widgets muted and their output gains at min */
4416         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4417         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4418         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4419         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4420         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4421         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4422         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4423         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4424         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4425
4426         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
4427         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4428         /* Unmute Line1 pin widget output buffer since it starts as an output.
4429          * If the pin mode is changed by the user the pin mode control will
4430          * take care of enabling the pin's input/output buffers as needed.
4431          * Therefore there's no need to enable the input buffer at this
4432          * stage.
4433          */
4434         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4435         /* Unmute input buffer of pin widget used for Line-in (no equiv 
4436          * mixer ctrl)
4437          */
4438         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4439
4440         /* Mute capture amp left and right */
4441         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4442         /* Set ADC connection select to match default mixer setting - line 
4443          * in (on mic1 pin)
4444          */
4445         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4446
4447         /* Do the same for the second ADC: mute capture input amp and
4448          * set ADC connection to line in (on mic1 pin)
4449          */
4450         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4451         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4452
4453         /* Mute all inputs to mixer widget (even unconnected ones) */
4454         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4455         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4456         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4457         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4458         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4459         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4460         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4461         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4462
4463         { }
4464 };
4465
4466 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
4467  * similar laptops (adapted from Fujitsu init verbs).
4468  */
4469 static struct hda_verb alc260_acer_init_verbs[] = {
4470         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
4471          * the headphone jack.  Turn this on and rely on the standard mute
4472          * methods whenever the user wants to turn these outputs off.
4473          */
4474         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
4475         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4476         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
4477         /* Internal speaker/Headphone jack is connected to Line-out pin */
4478         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4479         /* Internal microphone/Mic jack is connected to Mic1 pin */
4480         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
4481         /* Line In jack is connected to Line1 pin */
4482         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4483         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
4484         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4485         /* Ensure all other unused pins are disabled and muted. */
4486         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4487         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4488         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4489         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4490         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4491         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4492         /* Disable digital (SPDIF) pins */
4493         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4494         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4495
4496         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum 
4497          * bus when acting as outputs.
4498          */
4499         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
4500         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4501
4502         /* Start with output sum widgets muted and their output gains at min */
4503         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4504         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4505         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4506         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4507         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4508         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4509         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4510         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4511         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4512
4513         /* Unmute Line-out pin widget amp left and right
4514          * (no equiv mixer ctrl)
4515          */
4516         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4517         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
4518         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4519         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
4520          * inputs. If the pin mode is changed by the user the pin mode control
4521          * will take care of enabling the pin's input/output buffers as needed.
4522          * Therefore there's no need to enable the input buffer at this
4523          * stage.
4524          */
4525         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4526         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4527
4528         /* Mute capture amp left and right */
4529         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4530         /* Set ADC connection select to match default mixer setting - mic
4531          * (on mic1 pin)
4532          */
4533         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4534
4535         /* Do similar with the second ADC: mute capture input amp and
4536          * set ADC connection to mic to match ALSA's default state.
4537          */
4538         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4539         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4540
4541         /* Mute all inputs to mixer widget (even unconnected ones) */
4542         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4543         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4544         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4545         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4546         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4547         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4548         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4549         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4550
4551         { }
4552 };
4553
4554 static struct hda_verb alc260_will_verbs[] = {
4555         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4556         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
4557         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
4558         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4559         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
4560         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
4561         {}
4562 };
4563
4564 static struct hda_verb alc260_replacer_672v_verbs[] = {
4565         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4566         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
4567         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
4568
4569         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
4570         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4571         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4572
4573         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4574         {}
4575 };
4576
4577 /* toggle speaker-output according to the hp-jack state */
4578 static void alc260_replacer_672v_automute(struct hda_codec *codec)
4579 {
4580         unsigned int present;
4581
4582         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
4583         present = snd_hda_codec_read(codec, 0x0f, 0,
4584                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
4585         if (present) {
4586                 snd_hda_codec_write_cache(codec, 0x01, 0,
4587                                           AC_VERB_SET_GPIO_DATA, 1);
4588                 snd_hda_codec_write_cache(codec, 0x0f, 0,
4589                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4590                                           PIN_HP);
4591         } else {
4592                 snd_hda_codec_write_cache(codec, 0x01, 0,
4593                                           AC_VERB_SET_GPIO_DATA, 0);
4594                 snd_hda_codec_write_cache(codec, 0x0f, 0,
4595                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4596                                           PIN_OUT);
4597         }
4598 }
4599
4600 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
4601                                        unsigned int res)
4602 {
4603         if ((res >> 26) == ALC880_HP_EVENT)
4604                 alc260_replacer_672v_automute(codec);
4605 }
4606
4607 /* Test configuration for debugging, modelled after the ALC880 test
4608  * configuration.
4609  */
4610 #ifdef CONFIG_SND_DEBUG
4611 static hda_nid_t alc260_test_dac_nids[1] = {
4612         0x02,
4613 };
4614 static hda_nid_t alc260_test_adc_nids[2] = {
4615         0x04, 0x05,
4616 };
4617 /* For testing the ALC260, each input MUX needs its own definition since
4618  * the signal assignments are different.  This assumes that the first ADC 
4619  * is NID 0x04.
4620  */
4621 static struct hda_input_mux alc260_test_capture_sources[2] = {
4622         {
4623                 .num_items = 7,
4624                 .items = {
4625                         { "MIC1 pin", 0x0 },
4626                         { "MIC2 pin", 0x1 },
4627                         { "LINE1 pin", 0x2 },
4628                         { "LINE2 pin", 0x3 },
4629                         { "CD pin", 0x4 },
4630                         { "LINE-OUT pin", 0x5 },
4631                         { "HP-OUT pin", 0x6 },
4632                 },
4633         },
4634         {
4635                 .num_items = 8,
4636                 .items = {
4637                         { "MIC1 pin", 0x0 },
4638                         { "MIC2 pin", 0x1 },
4639                         { "LINE1 pin", 0x2 },
4640                         { "LINE2 pin", 0x3 },
4641                         { "CD pin", 0x4 },
4642                         { "Mixer", 0x5 },
4643                         { "LINE-OUT pin", 0x6 },
4644                         { "HP-OUT pin", 0x7 },
4645                 },
4646         },
4647 };
4648 static struct snd_kcontrol_new alc260_test_mixer[] = {
4649         /* Output driver widgets */
4650         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4651         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4652         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4653         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
4654         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4655         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
4656
4657         /* Modes for retasking pin widgets
4658          * Note: the ALC260 doesn't seem to act on requests to enable mic
4659          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
4660          * mention this restriction.  At this stage it's not clear whether
4661          * this behaviour is intentional or is a hardware bug in chip
4662          * revisions available at least up until early 2006.  Therefore for
4663          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
4664          * choices, but if it turns out that the lack of mic bias for these
4665          * NIDs is intentional we could change their modes from
4666          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4667          */
4668         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
4669         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
4670         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
4671         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
4672         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
4673         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
4674
4675         /* Loopback mixer controls */
4676         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
4677         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
4678         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
4679         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
4680         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
4681         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
4682         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
4683         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
4684         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4685         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4686         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4687         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4688         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
4689         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
4690         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
4691         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
4692
4693         /* Controls for GPIO pins, assuming they are configured as outputs */
4694         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
4695         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
4696         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
4697         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
4698
4699         /* Switches to allow the digital IO pins to be enabled.  The datasheet
4700          * is ambigious as to which NID is which; testing on laptops which
4701          * make this output available should provide clarification. 
4702          */
4703         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
4704         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
4705
4706         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
4707          * this output to turn on an external amplifier.
4708          */
4709         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
4710         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
4711
4712         { } /* end */
4713 };
4714 static struct hda_verb alc260_test_init_verbs[] = {
4715         /* Enable all GPIOs as outputs with an initial value of 0 */
4716         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
4717         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4718         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
4719
4720         /* Enable retasking pins as output, initially without power amp */
4721         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4722         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4723         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4724         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4725         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4726         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4727
4728         /* Disable digital (SPDIF) pins initially, but users can enable
4729          * them via a mixer switch.  In the case of SPDIF-out, this initverb
4730          * payload also sets the generation to 0, output to be in "consumer"
4731          * PCM format, copyright asserted, no pre-emphasis and no validity
4732          * control.
4733          */
4734         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4735         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4736
4737         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the 
4738          * OUT1 sum bus when acting as an output.
4739          */
4740         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
4741         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
4742         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4743         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
4744
4745         /* Start with output sum widgets muted and their output gains at min */
4746         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4747         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4748         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4749         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4750         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4751         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4752         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4753         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4754         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4755
4756         /* Unmute retasking pin widget output buffers since the default
4757          * state appears to be output.  As the pin mode is changed by the
4758          * user the pin mode control will take care of enabling the pin's
4759          * input/output buffers as needed.
4760          */
4761         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4762         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4763         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4764         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4765         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4766         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4767         /* Also unmute the mono-out pin widget */
4768         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4769
4770         /* Mute capture amp left and right */
4771         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4772         /* Set ADC connection select to match default mixer setting (mic1
4773          * pin)
4774          */
4775         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4776
4777         /* Do the same for the second ADC: mute capture input amp and
4778          * set ADC connection to mic1 pin
4779          */
4780         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4781         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4782
4783         /* Mute all inputs to mixer widget (even unconnected ones) */
4784         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4785         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4786         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4787         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4788         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4789         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4790         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4791         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4792
4793         { }
4794 };
4795 #endif
4796
4797 #define alc260_pcm_analog_playback      alc880_pcm_analog_alt_playback
4798 #define alc260_pcm_analog_capture       alc880_pcm_analog_capture
4799
4800 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
4801 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
4802
4803 /*
4804  * for BIOS auto-configuration
4805  */
4806
4807 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
4808                                         const char *pfx)
4809 {
4810         hda_nid_t nid_vol;
4811         unsigned long vol_val, sw_val;
4812         char name[32];
4813         int err;
4814
4815         if (nid >= 0x0f && nid < 0x11) {
4816                 nid_vol = nid - 0x7;
4817                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
4818                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
4819         } else if (nid == 0x11) {
4820                 nid_vol = nid - 0x7;
4821                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
4822                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
4823         } else if (nid >= 0x12 && nid <= 0x15) {
4824                 nid_vol = 0x08;
4825                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
4826                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
4827         } else
4828                 return 0; /* N/A */
4829         
4830         snprintf(name, sizeof(name), "%s Playback Volume", pfx);
4831         err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val);
4832         if (err < 0)
4833                 return err;
4834         snprintf(name, sizeof(name), "%s Playback Switch", pfx);
4835         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val);
4836         if (err < 0)
4837                 return err;
4838         return 1;
4839 }
4840
4841 /* add playback controls from the parsed DAC table */
4842 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
4843                                              const struct auto_pin_cfg *cfg)
4844 {
4845         hda_nid_t nid;
4846         int err;
4847
4848         spec->multiout.num_dacs = 1;
4849         spec->multiout.dac_nids = spec->private_dac_nids;
4850         spec->multiout.dac_nids[0] = 0x02;
4851
4852         nid = cfg->line_out_pins[0];
4853         if (nid) {
4854                 err = alc260_add_playback_controls(spec, nid, "Front");
4855                 if (err < 0)
4856                         return err;
4857         }
4858
4859         nid = cfg->speaker_pins[0];
4860         if (nid) {
4861                 err = alc260_add_playback_controls(spec, nid, "Speaker");
4862                 if (err < 0)
4863                         return err;
4864         }
4865
4866         nid = cfg->hp_pins[0];
4867         if (nid) {
4868                 err = alc260_add_playback_controls(spec, nid, "Headphone");
4869                 if (err < 0)
4870                         return err;
4871         }
4872         return 0;
4873 }
4874
4875 /* create playback/capture controls for input pins */
4876 static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec,
4877                                                 const struct auto_pin_cfg *cfg)
4878 {
4879         struct hda_input_mux *imux = &spec->private_imux;
4880         int i, err, idx;
4881
4882         for (i = 0; i < AUTO_PIN_LAST; i++) {
4883                 if (cfg->input_pins[i] >= 0x12) {
4884                         idx = cfg->input_pins[i] - 0x12;
4885                         err = new_analog_input(spec, cfg->input_pins[i],
4886                                                auto_pin_cfg_labels[i], idx,
4887                                                0x07);
4888                         if (err < 0)
4889                                 return err;
4890                         imux->items[imux->num_items].label =
4891                                 auto_pin_cfg_labels[i];
4892                         imux->items[imux->num_items].index = idx;
4893                         imux->num_items++;
4894                 }
4895                 if (cfg->input_pins[i] >= 0x0f && cfg->input_pins[i] <= 0x10){
4896                         idx = cfg->input_pins[i] - 0x09;
4897                         err = new_analog_input(spec, cfg->input_pins[i],
4898                                                auto_pin_cfg_labels[i], idx,
4899                                                0x07);
4900                         if (err < 0)
4901                                 return err;
4902                         imux->items[imux->num_items].label =
4903                                 auto_pin_cfg_labels[i];
4904                         imux->items[imux->num_items].index = idx;
4905                         imux->num_items++;
4906                 }
4907         }
4908         return 0;
4909 }
4910
4911 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
4912                                               hda_nid_t nid, int pin_type,
4913                                               int sel_idx)
4914 {
4915         alc_set_pin_output(codec, nid, pin_type);
4916         /* need the manual connection? */
4917         if (nid >= 0x12) {
4918                 int idx = nid - 0x12;
4919                 snd_hda_codec_write(codec, idx + 0x0b, 0,
4920                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
4921         }
4922 }
4923
4924 static void alc260_auto_init_multi_out(struct hda_codec *codec)
4925 {
4926         struct alc_spec *spec = codec->spec;
4927         hda_nid_t nid;
4928
4929         alc_subsystem_id(codec, 0x10, 0x15, 0x0f);
4930         nid = spec->autocfg.line_out_pins[0];
4931         if (nid) {
4932                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
4933                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
4934         }
4935         
4936         nid = spec->autocfg.speaker_pins[0];
4937         if (nid)
4938                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
4939
4940         nid = spec->autocfg.hp_pins[0];
4941         if (nid)
4942                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
4943 }
4944
4945 #define ALC260_PIN_CD_NID               0x16
4946 static void alc260_auto_init_analog_input(struct hda_codec *codec)
4947 {
4948         struct alc_spec *spec = codec->spec;
4949         int i;
4950
4951         for (i = 0; i < AUTO_PIN_LAST; i++) {
4952                 hda_nid_t nid = spec->autocfg.input_pins[i];
4953                 if (nid >= 0x12) {
4954                         snd_hda_codec_write(codec, nid, 0,
4955                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
4956                                             i <= AUTO_PIN_FRONT_MIC ?
4957                                             PIN_VREF80 : PIN_IN);
4958                         if (nid != ALC260_PIN_CD_NID)
4959                                 snd_hda_codec_write(codec, nid, 0,
4960                                                     AC_VERB_SET_AMP_GAIN_MUTE,
4961                                                     AMP_OUT_MUTE);
4962                 }
4963         }
4964 }
4965
4966 /*
4967  * generic initialization of ADC, input mixers and output mixers
4968  */
4969 static struct hda_verb alc260_volume_init_verbs[] = {
4970         /*
4971          * Unmute ADC0-1 and set the default input to mic-in
4972          */
4973         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4974         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4975         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4976         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4977         
4978         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4979          * mixer widget
4980          * Note: PASD motherboards uses the Line In 2 as the input for
4981          * front panel mic (mic 2)
4982          */
4983         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
4984         /* mute analog inputs */
4985         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4986         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4987         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4988         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4989         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4990
4991         /*
4992          * Set up output mixers (0x08 - 0x0a)
4993          */
4994         /* set vol=0 to output mixers */
4995         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4996         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4997         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4998         /* set up input amps for analog loopback */
4999         /* Amp Indices: DAC = 0, mixer = 1 */
5000         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5001         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5002         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5003         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5004         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5005         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5006         
5007         { }
5008 };
5009
5010 static int alc260_parse_auto_config(struct hda_codec *codec)
5011 {
5012         struct alc_spec *spec = codec->spec;
5013         unsigned int wcap;
5014         int err;
5015         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
5016
5017         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
5018                                            alc260_ignore);
5019         if (err < 0)
5020                 return err;
5021         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
5022         if (err < 0)
5023                 return err;
5024         if (!spec->kctl_alloc)
5025                 return 0; /* can't find valid BIOS pin config */
5026         err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg);
5027         if (err < 0)
5028                 return err;
5029
5030         spec->multiout.max_channels = 2;
5031
5032         if (spec->autocfg.dig_out_pin)
5033                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
5034         if (spec->kctl_alloc)
5035                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
5036
5037         spec->init_verbs[spec->num_init_verbs++] = alc260_volume_init_verbs;
5038
5039         spec->num_mux_defs = 1;
5040         spec->input_mux = &spec->private_imux;
5041
5042         /* check whether NID 0x04 is valid */
5043         wcap = get_wcaps(codec, 0x04);
5044         wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */
5045         if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
5046                 spec->adc_nids = alc260_adc_nids_alt;
5047                 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
5048                 spec->mixers[spec->num_mixers] = alc260_capture_alt_mixer;
5049         } else {
5050                 spec->adc_nids = alc260_adc_nids;
5051                 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
5052                 spec->mixers[spec->num_mixers] = alc260_capture_mixer;
5053         }
5054         spec->num_mixers++;
5055
5056         return 1;
5057 }
5058
5059 /* additional initialization for auto-configuration model */
5060 static void alc260_auto_init(struct hda_codec *codec)
5061 {
5062         struct alc_spec *spec = codec->spec;
5063         alc260_auto_init_multi_out(codec);
5064         alc260_auto_init_analog_input(codec);
5065         if (spec->unsol_event)
5066                 alc_sku_automute(codec);
5067 }
5068
5069 #ifdef CONFIG_SND_HDA_POWER_SAVE
5070 static struct hda_amp_list alc260_loopbacks[] = {
5071         { 0x07, HDA_INPUT, 0 },
5072         { 0x07, HDA_INPUT, 1 },
5073         { 0x07, HDA_INPUT, 2 },
5074         { 0x07, HDA_INPUT, 3 },
5075         { 0x07, HDA_INPUT, 4 },
5076         { } /* end */
5077 };
5078 #endif
5079
5080 /*
5081  * ALC260 configurations
5082  */
5083 static const char *alc260_models[ALC260_MODEL_LAST] = {
5084         [ALC260_BASIC]          = "basic",
5085         [ALC260_HP]             = "hp",
5086         [ALC260_HP_3013]        = "hp-3013",
5087         [ALC260_FUJITSU_S702X]  = "fujitsu",
5088         [ALC260_ACER]           = "acer",
5089         [ALC260_WILL]           = "will",
5090         [ALC260_REPLACER_672V]  = "replacer",
5091 #ifdef CONFIG_SND_DEBUG
5092         [ALC260_TEST]           = "test",
5093 #endif
5094         [ALC260_AUTO]           = "auto",
5095 };
5096
5097 static struct snd_pci_quirk alc260_cfg_tbl[] = {
5098         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
5099         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
5100         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
5101         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013),
5102         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
5103         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP),
5104         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_3013),
5105         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
5106         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
5107         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
5108         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
5109         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
5110         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
5111         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
5112         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
5113         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
5114         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
5115         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
5116         {}
5117 };
5118
5119 static struct alc_config_preset alc260_presets[] = {
5120         [ALC260_BASIC] = {
5121                 .mixers = { alc260_base_output_mixer,
5122                             alc260_input_mixer,
5123                             alc260_pc_beep_mixer,
5124                             alc260_capture_mixer },
5125                 .init_verbs = { alc260_init_verbs },
5126                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5127                 .dac_nids = alc260_dac_nids,
5128                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5129                 .adc_nids = alc260_adc_nids,
5130                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5131                 .channel_mode = alc260_modes,
5132                 .input_mux = &alc260_capture_source,
5133         },
5134         [ALC260_HP] = {
5135                 .mixers = { alc260_hp_output_mixer,
5136                             alc260_input_mixer,
5137                             alc260_capture_alt_mixer },
5138                 .init_verbs = { alc260_init_verbs,
5139                                 alc260_hp_unsol_verbs },
5140                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5141                 .dac_nids = alc260_dac_nids,
5142                 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
5143                 .adc_nids = alc260_hp_adc_nids,
5144                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5145                 .channel_mode = alc260_modes,
5146                 .input_mux = &alc260_capture_source,
5147                 .unsol_event = alc260_hp_unsol_event,
5148                 .init_hook = alc260_hp_automute,
5149         },
5150         [ALC260_HP_3013] = {
5151                 .mixers = { alc260_hp_3013_mixer,
5152                             alc260_input_mixer,
5153                             alc260_capture_alt_mixer },
5154                 .init_verbs = { alc260_hp_3013_init_verbs,
5155                                 alc260_hp_3013_unsol_verbs },
5156                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5157                 .dac_nids = alc260_dac_nids,
5158                 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
5159                 .adc_nids = alc260_hp_adc_nids,
5160                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5161                 .channel_mode = alc260_modes,
5162                 .input_mux = &alc260_capture_source,
5163                 .unsol_event = alc260_hp_3013_unsol_event,
5164                 .init_hook = alc260_hp_3013_automute,
5165         },
5166         [ALC260_FUJITSU_S702X] = {
5167                 .mixers = { alc260_fujitsu_mixer,
5168                             alc260_capture_mixer },
5169                 .init_verbs = { alc260_fujitsu_init_verbs },
5170                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5171                 .dac_nids = alc260_dac_nids,
5172                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5173                 .adc_nids = alc260_dual_adc_nids,
5174                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5175                 .channel_mode = alc260_modes,
5176                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
5177                 .input_mux = alc260_fujitsu_capture_sources,
5178         },
5179         [ALC260_ACER] = {
5180                 .mixers = { alc260_acer_mixer,
5181                             alc260_capture_mixer },
5182                 .init_verbs = { alc260_acer_init_verbs },
5183                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5184                 .dac_nids = alc260_dac_nids,
5185                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5186                 .adc_nids = alc260_dual_adc_nids,
5187                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5188                 .channel_mode = alc260_modes,
5189                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
5190                 .input_mux = alc260_acer_capture_sources,
5191         },
5192         [ALC260_WILL] = {
5193                 .mixers = { alc260_will_mixer,
5194                             alc260_capture_mixer },
5195                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
5196                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5197                 .dac_nids = alc260_dac_nids,
5198                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5199                 .adc_nids = alc260_adc_nids,
5200                 .dig_out_nid = ALC260_DIGOUT_NID,
5201                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5202                 .channel_mode = alc260_modes,
5203                 .input_mux = &alc260_capture_source,
5204         },
5205         [ALC260_REPLACER_672V] = {
5206                 .mixers = { alc260_replacer_672v_mixer,
5207                             alc260_capture_mixer },
5208                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
5209                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5210                 .dac_nids = alc260_dac_nids,
5211                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5212                 .adc_nids = alc260_adc_nids,
5213                 .dig_out_nid = ALC260_DIGOUT_NID,
5214                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5215                 .channel_mode = alc260_modes,
5216                 .input_mux = &alc260_capture_source,
5217                 .unsol_event = alc260_replacer_672v_unsol_event,
5218                 .init_hook = alc260_replacer_672v_automute,
5219         },
5220 #ifdef CONFIG_SND_DEBUG
5221         [ALC260_TEST] = {
5222                 .mixers = { alc260_test_mixer,
5223                             alc260_capture_mixer },
5224                 .init_verbs = { alc260_test_init_verbs },
5225                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
5226                 .dac_nids = alc260_test_dac_nids,
5227                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
5228                 .adc_nids = alc260_test_adc_nids,
5229                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5230                 .channel_mode = alc260_modes,
5231                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
5232                 .input_mux = alc260_test_capture_sources,
5233         },
5234 #endif
5235 };
5236
5237 static int patch_alc260(struct hda_codec *codec)
5238 {
5239         struct alc_spec *spec;
5240         int err, board_config;
5241
5242         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5243         if (spec == NULL)
5244                 return -ENOMEM;
5245
5246         codec->spec = spec;
5247
5248         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
5249                                                   alc260_models,
5250                                                   alc260_cfg_tbl);
5251         if (board_config < 0) {
5252                 snd_printd(KERN_INFO "hda_codec: Unknown model for ALC260, "
5253                            "trying auto-probe from BIOS...\n");
5254                 board_config = ALC260_AUTO;
5255         }
5256
5257         if (board_config == ALC260_AUTO) {
5258                 /* automatic parse from the BIOS config */
5259                 err = alc260_parse_auto_config(codec);
5260                 if (err < 0) {
5261                         alc_free(codec);
5262                         return err;
5263                 } else if (!err) {
5264                         printk(KERN_INFO
5265                                "hda_codec: Cannot set up configuration "
5266                                "from BIOS.  Using base mode...\n");
5267                         board_config = ALC260_BASIC;
5268                 }
5269         }
5270
5271         if (board_config != ALC260_AUTO)
5272                 setup_preset(spec, &alc260_presets[board_config]);
5273
5274         spec->stream_name_analog = "ALC260 Analog";
5275         spec->stream_analog_playback = &alc260_pcm_analog_playback;
5276         spec->stream_analog_capture = &alc260_pcm_analog_capture;
5277
5278         spec->stream_name_digital = "ALC260 Digital";
5279         spec->stream_digital_playback = &alc260_pcm_digital_playback;
5280         spec->stream_digital_capture = &alc260_pcm_digital_capture;
5281
5282         spec->vmaster_nid = 0x08;
5283
5284         codec->patch_ops = alc_patch_ops;
5285         if (board_config == ALC260_AUTO)
5286                 spec->init_hook = alc260_auto_init;
5287 #ifdef CONFIG_SND_HDA_POWER_SAVE
5288         if (!spec->loopback.amplist)
5289                 spec->loopback.amplist = alc260_loopbacks;
5290 #endif
5291
5292         return 0;
5293 }
5294
5295
5296 /*
5297  * ALC882 support
5298  *
5299  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5300  * configuration.  Each pin widget can choose any input DACs and a mixer.
5301  * Each ADC is connected from a mixer of all inputs.  This makes possible
5302  * 6-channel independent captures.
5303  *
5304  * In addition, an independent DAC for the multi-playback (not used in this
5305  * driver yet).
5306  */
5307 #define ALC882_DIGOUT_NID       0x06
5308 #define ALC882_DIGIN_NID        0x0a
5309
5310 static struct hda_channel_mode alc882_ch_modes[1] = {
5311         { 8, NULL }
5312 };
5313
5314 static hda_nid_t alc882_dac_nids[4] = {
5315         /* front, rear, clfe, rear_surr */
5316         0x02, 0x03, 0x04, 0x05
5317 };
5318
5319 /* identical with ALC880 */
5320 #define alc882_adc_nids         alc880_adc_nids
5321 #define alc882_adc_nids_alt     alc880_adc_nids_alt
5322
5323 static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
5324 static hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 };
5325
5326 /* input MUX */
5327 /* FIXME: should be a matrix-type input source selection */
5328
5329 static struct hda_input_mux alc882_capture_source = {
5330         .num_items = 4,
5331         .items = {
5332                 { "Mic", 0x0 },
5333                 { "Front Mic", 0x1 },
5334                 { "Line", 0x2 },
5335                 { "CD", 0x4 },
5336         },
5337 };
5338 #define alc882_mux_enum_info alc_mux_enum_info
5339 #define alc882_mux_enum_get alc_mux_enum_get
5340
5341 static int alc882_mux_enum_put(struct snd_kcontrol *kcontrol,
5342                                struct snd_ctl_elem_value *ucontrol)
5343 {
5344         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5345         struct alc_spec *spec = codec->spec;
5346         const struct hda_input_mux *imux = spec->input_mux;
5347         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
5348         hda_nid_t nid = spec->capsrc_nids ?
5349                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
5350         unsigned int *cur_val = &spec->cur_mux[adc_idx];
5351         unsigned int i, idx;
5352
5353         idx = ucontrol->value.enumerated.item[0];
5354         if (idx >= imux->num_items)
5355                 idx = imux->num_items - 1;
5356         if (*cur_val == idx)
5357                 return 0;
5358         for (i = 0; i < imux->num_items; i++) {
5359                 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
5360                 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
5361                                          imux->items[i].index,
5362                                          HDA_AMP_MUTE, v);
5363         }
5364         *cur_val = idx;
5365         return 1;
5366 }
5367
5368 /*
5369  * 2ch mode
5370  */
5371 static struct hda_verb alc882_3ST_ch2_init[] = {
5372         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
5373         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5374         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5375         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5376         { } /* end */
5377 };
5378
5379 /*
5380  * 6ch mode
5381  */
5382 static struct hda_verb alc882_3ST_ch6_init[] = {
5383         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5384         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5385         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
5386         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5387         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5388         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5389         { } /* end */
5390 };
5391
5392 static struct hda_channel_mode alc882_3ST_6ch_modes[2] = {
5393         { 2, alc882_3ST_ch2_init },
5394         { 6, alc882_3ST_ch6_init },
5395 };
5396
5397 /*
5398  * 6ch mode
5399  */
5400 static struct hda_verb alc882_sixstack_ch6_init[] = {
5401         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
5402         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5403         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5404         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5405         { } /* end */
5406 };
5407
5408 /*
5409  * 8ch mode
5410  */
5411 static struct hda_verb alc882_sixstack_ch8_init[] = {
5412         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5413         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5414         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5415         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5416         { } /* end */
5417 };
5418
5419 static struct hda_channel_mode alc882_sixstack_modes[2] = {
5420         { 6, alc882_sixstack_ch6_init },
5421         { 8, alc882_sixstack_ch8_init },
5422 };
5423
5424 /*
5425  * macbook pro ALC885 can switch LineIn to LineOut without loosing Mic
5426  */
5427
5428 /*
5429  * 2ch mode
5430  */
5431 static struct hda_verb alc885_mbp_ch2_init[] = {
5432         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5433         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5434         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5435         { } /* end */
5436 };
5437
5438 /*
5439  * 6ch mode
5440  */
5441 static struct hda_verb alc885_mbp_ch6_init[] = {
5442         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5443         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5444         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5445         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5446         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5447         { } /* end */
5448 };
5449
5450 static struct hda_channel_mode alc885_mbp_6ch_modes[2] = {
5451         { 2, alc885_mbp_ch2_init },
5452         { 6, alc885_mbp_ch6_init },
5453 };
5454
5455
5456 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
5457  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
5458  */
5459 static struct snd_kcontrol_new alc882_base_mixer[] = {
5460         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5461         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5462         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
5463         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
5464         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
5465         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
5466         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
5467         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
5468         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
5469         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
5470         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5471         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5472         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5473         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5474         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5475         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5476         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5477         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5478         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5479         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5480         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5481         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5482         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5483         { } /* end */
5484 };
5485
5486 static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
5487         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
5488         HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
5489         HDA_CODEC_MUTE  ("Speaker Playback Switch", 0x14, 0x00, HDA_OUTPUT),
5490         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
5491         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5492         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5493         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
5494         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
5495         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
5496         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
5497         { } /* end */
5498 };
5499 static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
5500         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5501         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5502         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5503         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5504         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5505         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5506         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5507         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5508         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5509         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5510         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5511         { } /* end */
5512 };
5513
5514 static struct snd_kcontrol_new alc882_targa_mixer[] = {
5515         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5516         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5517         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5518         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5519         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5520         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5521         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5522         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5523         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5524         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5525         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5526         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5527         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5528         { } /* end */
5529 };
5530
5531 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
5532  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
5533  */
5534 static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
5535         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5536         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
5537         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5538         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
5539         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5540         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5541         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5542         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5543         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
5544         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
5545         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5546         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5547         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5548         { } /* end */
5549 };
5550
5551 static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
5552         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5553         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5554         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5555         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5556         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5557         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5558         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5559         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5560         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5561         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5562         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5563         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5564         { } /* end */
5565 };
5566
5567 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
5568         {
5569                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5570                 .name = "Channel Mode",
5571                 .info = alc_ch_mode_info,
5572                 .get = alc_ch_mode_get,
5573                 .put = alc_ch_mode_put,
5574         },
5575         { } /* end */
5576 };
5577
5578 static struct hda_verb alc882_init_verbs[] = {
5579         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5580         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5581         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5582         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5583         /* Rear mixer */
5584         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5585         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5586         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5587         /* CLFE mixer */
5588         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5589         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5590         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5591         /* Side mixer */
5592         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5593         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5594         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5595
5596         /* Front Pin: output 0 (0x0c) */
5597         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5598         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5599         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5600         /* Rear Pin: output 1 (0x0d) */
5601         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5602         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5603         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5604         /* CLFE Pin: output 2 (0x0e) */
5605         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5606         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5607         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
5608         /* Side Pin: output 3 (0x0f) */
5609         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5610         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5611         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
5612         /* Mic (rear) pin: input vref at 80% */
5613         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5614         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5615         /* Front Mic pin: input vref at 80% */
5616         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5617         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5618         /* Line In pin: input */
5619         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5620         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5621         /* Line-2 In: Headphone output (output 0 - 0x0c) */
5622         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5623         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5624         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
5625         /* CD pin widget for input */
5626         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5627
5628         /* FIXME: use matrix-type input source selection */
5629         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5630         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5631         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5632         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5633         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5634         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5635         /* Input mixer2 */
5636         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5637         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5638         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5639         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5640         /* Input mixer3 */
5641         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5642         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5643         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5644         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5645         /* ADC1: mute amp left and right */
5646         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5647         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5648         /* ADC2: mute amp left and right */
5649         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5650         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5651         /* ADC3: mute amp left and right */
5652         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5653         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5654
5655         { }
5656 };
5657
5658 static struct hda_verb alc882_eapd_verbs[] = {
5659         /* change to EAPD mode */
5660         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
5661         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
5662         { }
5663 };
5664
5665 /* Mac Pro test */
5666 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
5667         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5668         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5669         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
5670         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
5671         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
5672         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT),
5673         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT),
5674         { } /* end */
5675 };
5676
5677 static struct hda_verb alc882_macpro_init_verbs[] = {
5678         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5679         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5680         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5681         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5682         /* Front Pin: output 0 (0x0c) */
5683         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5684         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5685         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
5686         /* Front Mic pin: input vref at 80% */
5687         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5688         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5689         /* Speaker:  output */
5690         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5691         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5692         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
5693         /* Headphone output (output 0 - 0x0c) */
5694         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5695         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5696         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
5697
5698         /* FIXME: use matrix-type input source selection */
5699         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5700         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5701         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5702         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5703         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5704         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5705         /* Input mixer2 */
5706         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5707         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5708         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5709         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5710         /* Input mixer3 */
5711         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5712         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5713         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5714         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5715         /* ADC1: mute amp left and right */
5716         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5717         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5718         /* ADC2: mute amp left and right */
5719         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5720         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5721         /* ADC3: mute amp left and right */
5722         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5723         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5724
5725         { }
5726 };
5727
5728 /* Macbook Pro rev3 */
5729 static struct hda_verb alc885_mbp3_init_verbs[] = {
5730         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5731         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5732         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5733         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5734         /* Rear mixer */
5735         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5736         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5737         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5738         /* Front Pin: output 0 (0x0c) */
5739         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5740         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5741         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5742         /* HP Pin: output 0 (0x0d) */
5743         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
5744         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5745         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
5746         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5747         /* Mic (rear) pin: input vref at 80% */
5748         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5749         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5750         /* Front Mic pin: input vref at 80% */
5751         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5752         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5753         /* Line In pin: use output 1 when in LineOut mode */
5754         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5755         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5756         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
5757
5758         /* FIXME: use matrix-type input source selection */
5759         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5760         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5761         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5762         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5763         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5764         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5765         /* Input mixer2 */
5766         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5767         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5768         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5769         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5770         /* Input mixer3 */
5771         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5772         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5773         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5774         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5775         /* ADC1: mute amp left and right */
5776         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5777         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5778         /* ADC2: mute amp left and right */
5779         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5780         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5781         /* ADC3: mute amp left and right */
5782         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5783         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5784
5785         { }
5786 };
5787
5788 /* iMac 24 mixer. */
5789 static struct snd_kcontrol_new alc885_imac24_mixer[] = {
5790         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
5791         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
5792         { } /* end */
5793 };
5794
5795 /* iMac 24 init verbs. */
5796 static struct hda_verb alc885_imac24_init_verbs[] = {
5797         /* Internal speakers: output 0 (0x0c) */
5798         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5799         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5800         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
5801         /* Internal speakers: output 0 (0x0c) */
5802         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5803         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5804         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
5805         /* Headphone: output 0 (0x0c) */
5806         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5807         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5808         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5809         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5810         /* Front Mic: input vref at 80% */
5811         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5812         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5813         { }
5814 };
5815
5816 /* Toggle speaker-output according to the hp-jack state */
5817 static void alc885_imac24_automute(struct hda_codec *codec)
5818 {
5819         unsigned int present;
5820
5821         present = snd_hda_codec_read(codec, 0x14, 0,
5822                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5823         snd_hda_codec_amp_stereo(codec, 0x18, HDA_OUTPUT, 0,
5824                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5825         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
5826                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5827 }
5828
5829 /* Processes unsolicited events. */
5830 static void alc885_imac24_unsol_event(struct hda_codec *codec,
5831                                       unsigned int res)
5832 {
5833         /* Headphone insertion or removal. */
5834         if ((res >> 26) == ALC880_HP_EVENT)
5835                 alc885_imac24_automute(codec);
5836 }
5837
5838 static void alc885_mbp3_automute(struct hda_codec *codec)
5839 {
5840         unsigned int present;
5841
5842         present = snd_hda_codec_read(codec, 0x15, 0,
5843                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5844         snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
5845                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5846         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
5847                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
5848
5849 }
5850 static void alc885_mbp3_unsol_event(struct hda_codec *codec,
5851                                     unsigned int res)
5852 {
5853         /* Headphone insertion or removal. */
5854         if ((res >> 26) == ALC880_HP_EVENT)
5855                 alc885_mbp3_automute(codec);
5856 }
5857
5858
5859 static struct hda_verb alc882_targa_verbs[] = {
5860         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5861         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5862
5863         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5864         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5865         
5866         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
5867         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
5868         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5869
5870         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5871         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5872         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
5873         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
5874         { } /* end */
5875 };
5876
5877 /* toggle speaker-output according to the hp-jack state */
5878 static void alc882_targa_automute(struct hda_codec *codec)
5879 {
5880         unsigned int present;
5881  
5882         present = snd_hda_codec_read(codec, 0x14, 0,
5883                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5884         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
5885                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5886         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
5887                                   present ? 1 : 3);
5888 }
5889
5890 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
5891 {
5892         /* Looks like the unsol event is incompatible with the standard
5893          * definition.  4bit tag is placed at 26 bit!
5894          */
5895         if (((res >> 26) == ALC880_HP_EVENT)) {
5896                 alc882_targa_automute(codec);
5897         }
5898 }
5899
5900 static struct hda_verb alc882_asus_a7j_verbs[] = {
5901         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5902         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5903
5904         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5905         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5906         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5907         
5908         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5909         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5910         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5911
5912         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
5913         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
5914         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5915         { } /* end */
5916 };
5917
5918 static struct hda_verb alc882_asus_a7m_verbs[] = {
5919         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5920         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5921
5922         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5923         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5924         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5925         
5926         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5927         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5928         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5929
5930         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
5931         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
5932         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5933         { } /* end */
5934 };
5935
5936 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5937 {
5938         unsigned int gpiostate, gpiomask, gpiodir;
5939
5940         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5941                                        AC_VERB_GET_GPIO_DATA, 0);
5942
5943         if (!muted)
5944                 gpiostate |= (1 << pin);
5945         else
5946                 gpiostate &= ~(1 << pin);
5947
5948         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5949                                       AC_VERB_GET_GPIO_MASK, 0);
5950         gpiomask |= (1 << pin);
5951
5952         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5953                                      AC_VERB_GET_GPIO_DIRECTION, 0);
5954         gpiodir |= (1 << pin);
5955
5956
5957         snd_hda_codec_write(codec, codec->afg, 0,
5958                             AC_VERB_SET_GPIO_MASK, gpiomask);
5959         snd_hda_codec_write(codec, codec->afg, 0,
5960                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5961
5962         msleep(1);
5963
5964         snd_hda_codec_write(codec, codec->afg, 0,
5965                             AC_VERB_SET_GPIO_DATA, gpiostate);
5966 }
5967
5968 /* set up GPIO at initialization */
5969 static void alc885_macpro_init_hook(struct hda_codec *codec)
5970 {
5971         alc882_gpio_mute(codec, 0, 0);
5972         alc882_gpio_mute(codec, 1, 0);
5973 }
5974
5975 /* set up GPIO and update auto-muting at initialization */
5976 static void alc885_imac24_init_hook(struct hda_codec *codec)
5977 {
5978         alc885_macpro_init_hook(codec);
5979         alc885_imac24_automute(codec);
5980 }
5981
5982 /*
5983  * generic initialization of ADC, input mixers and output mixers
5984  */
5985 static struct hda_verb alc882_auto_init_verbs[] = {
5986         /*
5987          * Unmute ADC0-2 and set the default input to mic-in
5988          */
5989         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5990         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5991         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5992         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5993         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5994         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5995
5996         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5997          * mixer widget
5998          * Note: PASD motherboards uses the Line In 2 as the input for
5999          * front panel mic (mic 2)
6000          */
6001         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
6002         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6003         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6004         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6005         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6006         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6007
6008         /*
6009          * Set up output mixers (0x0c - 0x0f)
6010          */
6011         /* set vol=0 to output mixers */
6012         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6013         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6014         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6015         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6016         /* set up input amps for analog loopback */
6017         /* Amp Indices: DAC = 0, mixer = 1 */
6018         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6019         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6020         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6021         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6022         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6023         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6024         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6025         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6026         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6027         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6028
6029         /* FIXME: use matrix-type input source selection */
6030         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6031         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6032         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6033         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6034         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6035         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6036         /* Input mixer2 */
6037         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6038         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6039         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6040         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6041         /* Input mixer3 */
6042         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6043         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6044         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6045         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6046
6047         { }
6048 };
6049
6050 /* capture mixer elements */
6051 static struct snd_kcontrol_new alc882_capture_alt_mixer[] = {
6052         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6053         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6054         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6055         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6056         {
6057                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6058                 /* The multiple "Capture Source" controls confuse alsamixer
6059                  * So call somewhat different..
6060                  */
6061                 /* .name = "Capture Source", */
6062                 .name = "Input Source",
6063                 .count = 2,
6064                 .info = alc882_mux_enum_info,
6065                 .get = alc882_mux_enum_get,
6066                 .put = alc882_mux_enum_put,
6067         },
6068         { } /* end */
6069 };
6070
6071 static struct snd_kcontrol_new alc882_capture_mixer[] = {
6072         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
6073         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
6074         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
6075         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
6076         HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
6077         HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
6078         {
6079                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6080                 /* The multiple "Capture Source" controls confuse alsamixer
6081                  * So call somewhat different..
6082                  */
6083                 /* .name = "Capture Source", */
6084                 .name = "Input Source",
6085                 .count = 3,
6086                 .info = alc882_mux_enum_info,
6087                 .get = alc882_mux_enum_get,
6088                 .put = alc882_mux_enum_put,
6089         },
6090         { } /* end */
6091 };
6092
6093 #ifdef CONFIG_SND_HDA_POWER_SAVE
6094 #define alc882_loopbacks        alc880_loopbacks
6095 #endif
6096
6097 /* pcm configuration: identiacal with ALC880 */
6098 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
6099 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
6100 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
6101 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
6102
6103 /*
6104  * configuration and preset
6105  */
6106 static const char *alc882_models[ALC882_MODEL_LAST] = {
6107         [ALC882_3ST_DIG]        = "3stack-dig",
6108         [ALC882_6ST_DIG]        = "6stack-dig",
6109         [ALC882_ARIMA]          = "arima",
6110         [ALC882_W2JC]           = "w2jc",
6111         [ALC882_TARGA]          = "targa",
6112         [ALC882_ASUS_A7J]       = "asus-a7j",
6113         [ALC882_ASUS_A7M]       = "asus-a7m",
6114         [ALC885_MACPRO]         = "macpro",
6115         [ALC885_MBP3]           = "mbp3",
6116         [ALC885_IMAC24]         = "imac24",
6117         [ALC882_AUTO]           = "auto",
6118 };
6119
6120 static struct snd_pci_quirk alc882_cfg_tbl[] = {
6121         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
6122         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
6123         SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
6124         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
6125         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
6126         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
6127         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
6128         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
6129         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),
6130         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
6131         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
6132         SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA),
6133         {}
6134 };
6135
6136 static struct alc_config_preset alc882_presets[] = {
6137         [ALC882_3ST_DIG] = {
6138                 .mixers = { alc882_base_mixer },
6139                 .init_verbs = { alc882_init_verbs },
6140                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6141                 .dac_nids = alc882_dac_nids,
6142                 .dig_out_nid = ALC882_DIGOUT_NID,
6143                 .dig_in_nid = ALC882_DIGIN_NID,
6144                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6145                 .channel_mode = alc882_ch_modes,
6146                 .need_dac_fix = 1,
6147                 .input_mux = &alc882_capture_source,
6148         },
6149         [ALC882_6ST_DIG] = {
6150                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6151                 .init_verbs = { alc882_init_verbs },
6152                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6153                 .dac_nids = alc882_dac_nids,
6154                 .dig_out_nid = ALC882_DIGOUT_NID,
6155                 .dig_in_nid = ALC882_DIGIN_NID,
6156                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6157                 .channel_mode = alc882_sixstack_modes,
6158                 .input_mux = &alc882_capture_source,
6159         },
6160         [ALC882_ARIMA] = {
6161                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6162                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs },
6163                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6164                 .dac_nids = alc882_dac_nids,
6165                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6166                 .channel_mode = alc882_sixstack_modes,
6167                 .input_mux = &alc882_capture_source,
6168         },
6169         [ALC882_W2JC] = {
6170                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
6171                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6172                                 alc880_gpio1_init_verbs },
6173                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6174                 .dac_nids = alc882_dac_nids,
6175                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6176                 .channel_mode = alc880_threestack_modes,
6177                 .need_dac_fix = 1,
6178                 .input_mux = &alc882_capture_source,
6179                 .dig_out_nid = ALC882_DIGOUT_NID,
6180         },
6181         [ALC885_MBP3] = {
6182                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
6183                 .init_verbs = { alc885_mbp3_init_verbs,
6184                                 alc880_gpio1_init_verbs },
6185                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6186                 .dac_nids = alc882_dac_nids,
6187                 .channel_mode = alc885_mbp_6ch_modes,
6188                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_6ch_modes),
6189                 .input_mux = &alc882_capture_source,
6190                 .dig_out_nid = ALC882_DIGOUT_NID,
6191                 .dig_in_nid = ALC882_DIGIN_NID,
6192                 .unsol_event = alc885_mbp3_unsol_event,
6193                 .init_hook = alc885_mbp3_automute,
6194         },
6195         [ALC885_MACPRO] = {
6196                 .mixers = { alc882_macpro_mixer },
6197                 .init_verbs = { alc882_macpro_init_verbs },
6198                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6199                 .dac_nids = alc882_dac_nids,
6200                 .dig_out_nid = ALC882_DIGOUT_NID,
6201                 .dig_in_nid = ALC882_DIGIN_NID,
6202                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6203                 .channel_mode = alc882_ch_modes,
6204                 .input_mux = &alc882_capture_source,
6205                 .init_hook = alc885_macpro_init_hook,
6206         },
6207         [ALC885_IMAC24] = {
6208                 .mixers = { alc885_imac24_mixer },
6209                 .init_verbs = { alc885_imac24_init_verbs },
6210                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6211                 .dac_nids = alc882_dac_nids,
6212                 .dig_out_nid = ALC882_DIGOUT_NID,
6213                 .dig_in_nid = ALC882_DIGIN_NID,
6214                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6215                 .channel_mode = alc882_ch_modes,
6216                 .input_mux = &alc882_capture_source,
6217                 .unsol_event = alc885_imac24_unsol_event,
6218                 .init_hook = alc885_imac24_init_hook,
6219         },
6220         [ALC882_TARGA] = {
6221                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer,
6222                             alc882_capture_mixer },
6223                 .init_verbs = { alc882_init_verbs, alc882_targa_verbs},
6224                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6225                 .dac_nids = alc882_dac_nids,
6226                 .dig_out_nid = ALC882_DIGOUT_NID,
6227                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6228                 .adc_nids = alc882_adc_nids,
6229                 .capsrc_nids = alc882_capsrc_nids,
6230                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6231                 .channel_mode = alc882_3ST_6ch_modes,
6232                 .need_dac_fix = 1,
6233                 .input_mux = &alc882_capture_source,
6234                 .unsol_event = alc882_targa_unsol_event,
6235                 .init_hook = alc882_targa_automute,
6236         },
6237         [ALC882_ASUS_A7J] = {
6238                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer,
6239                             alc882_capture_mixer },
6240                 .init_verbs = { alc882_init_verbs, alc882_asus_a7j_verbs},
6241                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6242                 .dac_nids = alc882_dac_nids,
6243                 .dig_out_nid = ALC882_DIGOUT_NID,
6244                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6245                 .adc_nids = alc882_adc_nids,
6246                 .capsrc_nids = alc882_capsrc_nids,
6247                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6248                 .channel_mode = alc882_3ST_6ch_modes,
6249                 .need_dac_fix = 1,
6250                 .input_mux = &alc882_capture_source,
6251         },      
6252         [ALC882_ASUS_A7M] = {
6253                 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
6254                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6255                                 alc880_gpio1_init_verbs,
6256                                 alc882_asus_a7m_verbs },
6257                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6258                 .dac_nids = alc882_dac_nids,
6259                 .dig_out_nid = ALC882_DIGOUT_NID,
6260                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6261                 .channel_mode = alc880_threestack_modes,
6262                 .need_dac_fix = 1,
6263                 .input_mux = &alc882_capture_source,
6264         },      
6265 };
6266
6267
6268 /*
6269  * Pin config fixes
6270  */
6271 enum { 
6272         PINFIX_ABIT_AW9D_MAX
6273 };
6274
6275 static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
6276         { 0x15, 0x01080104 }, /* side */
6277         { 0x16, 0x01011012 }, /* rear */
6278         { 0x17, 0x01016011 }, /* clfe */
6279         { }
6280 };
6281
6282 static const struct alc_pincfg *alc882_pin_fixes[] = {
6283         [PINFIX_ABIT_AW9D_MAX] = alc882_abit_aw9d_pinfix,
6284 };
6285
6286 static struct snd_pci_quirk alc882_pinfix_tbl[] = {
6287         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
6288         {}
6289 };
6290
6291 /*
6292  * BIOS auto configuration
6293  */
6294 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
6295                                               hda_nid_t nid, int pin_type,
6296                                               int dac_idx)
6297 {
6298         /* set as output */
6299         struct alc_spec *spec = codec->spec;
6300         int idx;
6301
6302         alc_set_pin_output(codec, nid, pin_type);
6303         if (spec->multiout.dac_nids[dac_idx] == 0x25)
6304                 idx = 4;
6305         else
6306                 idx = spec->multiout.dac_nids[dac_idx] - 2;
6307         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
6308
6309 }
6310
6311 static void alc882_auto_init_multi_out(struct hda_codec *codec)
6312 {
6313         struct alc_spec *spec = codec->spec;
6314         int i;
6315
6316         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
6317         for (i = 0; i <= HDA_SIDE; i++) {
6318                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
6319                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
6320                 if (nid)
6321                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
6322                                                           i);
6323         }
6324 }
6325
6326 static void alc882_auto_init_hp_out(struct hda_codec *codec)
6327 {
6328         struct alc_spec *spec = codec->spec;
6329         hda_nid_t pin;
6330
6331         pin = spec->autocfg.hp_pins[0];
6332         if (pin) /* connect to front */
6333                 /* use dac 0 */
6334                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
6335         pin = spec->autocfg.speaker_pins[0];
6336         if (pin)
6337                 alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
6338 }
6339
6340 #define alc882_is_input_pin(nid)        alc880_is_input_pin(nid)
6341 #define ALC882_PIN_CD_NID               ALC880_PIN_CD_NID
6342
6343 static void alc882_auto_init_analog_input(struct hda_codec *codec)
6344 {
6345         struct alc_spec *spec = codec->spec;
6346         int i;
6347
6348         for (i = 0; i < AUTO_PIN_LAST; i++) {
6349                 hda_nid_t nid = spec->autocfg.input_pins[i];
6350                 unsigned int vref;
6351                 if (!nid)
6352                         continue;
6353                 vref = PIN_IN;
6354                 if (1 /*i <= AUTO_PIN_FRONT_MIC*/) {
6355                         if (snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP) &
6356                             AC_PINCAP_VREF_80)
6357                                 vref = PIN_VREF80;
6358                 }
6359                 snd_hda_codec_write(codec, nid, 0,
6360                                     AC_VERB_SET_PIN_WIDGET_CONTROL, vref);
6361                 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
6362                         snd_hda_codec_write(codec, nid, 0,
6363                                             AC_VERB_SET_AMP_GAIN_MUTE,
6364                                             AMP_OUT_MUTE);
6365         }
6366 }
6367
6368 /* add mic boosts if needed */
6369 static int alc_auto_add_mic_boost(struct hda_codec *codec)
6370 {
6371         struct alc_spec *spec = codec->spec;
6372         int err;
6373         hda_nid_t nid;
6374
6375         nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
6376         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6377                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6378                                   "Mic Boost",
6379                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6380                 if (err < 0)
6381                         return err;
6382         }
6383         nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
6384         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6385                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6386                                   "Front Mic Boost",
6387                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6388                 if (err < 0)
6389                         return err;
6390         }
6391         return 0;
6392 }
6393
6394 /* almost identical with ALC880 parser... */
6395 static int alc882_parse_auto_config(struct hda_codec *codec)
6396 {
6397         struct alc_spec *spec = codec->spec;
6398         int err = alc880_parse_auto_config(codec);
6399
6400         if (err < 0)
6401                 return err;
6402         else if (!err)
6403                 return 0; /* no config found */
6404
6405         err = alc_auto_add_mic_boost(codec);
6406         if (err < 0)
6407                 return err;
6408
6409         /* hack - override the init verbs */
6410         spec->init_verbs[0] = alc882_auto_init_verbs;
6411
6412         return 1; /* config found */
6413 }
6414
6415 /* additional initialization for auto-configuration model */
6416 static void alc882_auto_init(struct hda_codec *codec)
6417 {
6418         struct alc_spec *spec = codec->spec;
6419         alc882_auto_init_multi_out(codec);
6420         alc882_auto_init_hp_out(codec);
6421         alc882_auto_init_analog_input(codec);
6422         if (spec->unsol_event)
6423                 alc_sku_automute(codec);
6424 }
6425
6426 static int patch_alc883(struct hda_codec *codec); /* called in patch_alc882() */
6427
6428 static int patch_alc882(struct hda_codec *codec)
6429 {
6430         struct alc_spec *spec;
6431         int err, board_config;
6432
6433         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6434         if (spec == NULL)
6435                 return -ENOMEM;
6436
6437         codec->spec = spec;
6438
6439         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
6440                                                   alc882_models,
6441                                                   alc882_cfg_tbl);
6442
6443         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
6444                 /* Pick up systems that don't supply PCI SSID */
6445                 switch (codec->subsystem_id) {
6446                 case 0x106b0c00: /* Mac Pro */
6447                         board_config = ALC885_MACPRO;
6448                         break;
6449                 case 0x106b1000: /* iMac 24 */
6450                         board_config = ALC885_IMAC24;
6451                         break;
6452                 case 0x106b00a1: /* Macbook */
6453                 case 0x106b2c00: /* Macbook Pro rev3 */
6454                         board_config = ALC885_MBP3;
6455                         break;
6456                 default:
6457                         /* ALC889A is handled better as ALC888-compatible */
6458                         if (codec->revision_id == 0x100103) {
6459                                 alc_free(codec);
6460                                 return patch_alc883(codec);
6461                         }
6462                         printk(KERN_INFO "hda_codec: Unknown model for ALC882, "
6463                                          "trying auto-probe from BIOS...\n");
6464                         board_config = ALC882_AUTO;
6465                 }
6466         }
6467
6468         alc_fix_pincfg(codec, alc882_pinfix_tbl, alc882_pin_fixes);
6469
6470         if (board_config == ALC882_AUTO) {
6471                 /* automatic parse from the BIOS config */
6472                 err = alc882_parse_auto_config(codec);
6473                 if (err < 0) {
6474                         alc_free(codec);
6475                         return err;
6476                 } else if (!err) {
6477                         printk(KERN_INFO
6478                                "hda_codec: Cannot set up configuration "
6479                                "from BIOS.  Using base mode...\n");
6480                         board_config = ALC882_3ST_DIG;
6481                 }
6482         }
6483
6484         if (board_config != ALC882_AUTO)
6485                 setup_preset(spec, &alc882_presets[board_config]);
6486
6487         spec->stream_name_analog = "ALC882 Analog";
6488         spec->stream_analog_playback = &alc882_pcm_analog_playback;
6489         spec->stream_analog_capture = &alc882_pcm_analog_capture;
6490         /* FIXME: setup DAC5 */
6491         /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
6492         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
6493
6494         spec->stream_name_digital = "ALC882 Digital";
6495         spec->stream_digital_playback = &alc882_pcm_digital_playback;
6496         spec->stream_digital_capture = &alc882_pcm_digital_capture;
6497
6498         if (!spec->adc_nids && spec->input_mux) {
6499                 /* check whether NID 0x07 is valid */
6500                 unsigned int wcap = get_wcaps(codec, 0x07);
6501                 /* get type */
6502                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
6503                 if (wcap != AC_WID_AUD_IN) {
6504                         spec->adc_nids = alc882_adc_nids_alt;
6505                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
6506                         spec->capsrc_nids = alc882_capsrc_nids_alt;
6507                         spec->mixers[spec->num_mixers] =
6508                                 alc882_capture_alt_mixer;
6509                         spec->num_mixers++;
6510                 } else {
6511                         spec->adc_nids = alc882_adc_nids;
6512                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
6513                         spec->capsrc_nids = alc882_capsrc_nids;
6514                         spec->mixers[spec->num_mixers] = alc882_capture_mixer;
6515                         spec->num_mixers++;
6516                 }
6517         }
6518
6519         spec->vmaster_nid = 0x0c;
6520
6521         codec->patch_ops = alc_patch_ops;
6522         if (board_config == ALC882_AUTO)
6523                 spec->init_hook = alc882_auto_init;
6524 #ifdef CONFIG_SND_HDA_POWER_SAVE
6525         if (!spec->loopback.amplist)
6526                 spec->loopback.amplist = alc882_loopbacks;
6527 #endif
6528
6529         return 0;
6530 }
6531
6532 /*
6533  * ALC883 support
6534  *
6535  * ALC883 is almost identical with ALC880 but has cleaner and more flexible
6536  * configuration.  Each pin widget can choose any input DACs and a mixer.
6537  * Each ADC is connected from a mixer of all inputs.  This makes possible
6538  * 6-channel independent captures.
6539  *
6540  * In addition, an independent DAC for the multi-playback (not used in this
6541  * driver yet).
6542  */
6543 #define ALC883_DIGOUT_NID       0x06
6544 #define ALC883_DIGIN_NID        0x0a
6545
6546 static hda_nid_t alc883_dac_nids[4] = {
6547         /* front, rear, clfe, rear_surr */
6548         0x02, 0x03, 0x04, 0x05
6549 };
6550
6551 static hda_nid_t alc883_adc_nids[2] = {
6552         /* ADC1-2 */
6553         0x08, 0x09,
6554 };
6555
6556 static hda_nid_t alc883_capsrc_nids[2] = { 0x23, 0x22 };
6557
6558 /* input MUX */
6559 /* FIXME: should be a matrix-type input source selection */
6560
6561 static struct hda_input_mux alc883_capture_source = {
6562         .num_items = 4,
6563         .items = {
6564                 { "Mic", 0x0 },
6565                 { "Front Mic", 0x1 },
6566                 { "Line", 0x2 },
6567                 { "CD", 0x4 },
6568         },
6569 };
6570
6571 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
6572         .num_items = 2,
6573         .items = {
6574                 { "Mic", 0x1 },
6575                 { "Line", 0x2 },
6576         },
6577 };
6578
6579 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
6580         .num_items = 4,
6581         .items = {
6582                 { "Mic", 0x0 },
6583                 { "iMic", 0x1 },
6584                 { "Line", 0x2 },
6585                 { "CD", 0x4 },
6586         },
6587 };
6588
6589 static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
6590         .num_items = 2,
6591         .items = {
6592                 { "Mic", 0x0 },
6593                 { "Int Mic", 0x1 },
6594         },
6595 };
6596
6597 #define alc883_mux_enum_info alc_mux_enum_info
6598 #define alc883_mux_enum_get alc_mux_enum_get
6599 /* ALC883 has the ALC882-type input selection */
6600 #define alc883_mux_enum_put alc882_mux_enum_put
6601
6602 /*
6603  * 2ch mode
6604  */
6605 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
6606         { 2, NULL }
6607 };
6608
6609 /*
6610  * 2ch mode
6611  */
6612 static struct hda_verb alc883_3ST_ch2_init[] = {
6613         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6614         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6615         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6616         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6617         { } /* end */
6618 };
6619
6620 /*
6621  * 4ch mode
6622  */
6623 static struct hda_verb alc883_3ST_ch4_init[] = {
6624         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6625         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6626         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6627         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6628         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6629         { } /* end */
6630 };
6631
6632 /*
6633  * 6ch mode
6634  */
6635 static struct hda_verb alc883_3ST_ch6_init[] = {
6636         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6637         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6638         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6639         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6640         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6641         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6642         { } /* end */
6643 };
6644
6645 static struct hda_channel_mode alc883_3ST_6ch_modes[3] = {
6646         { 2, alc883_3ST_ch2_init },
6647         { 4, alc883_3ST_ch4_init },
6648         { 6, alc883_3ST_ch6_init },
6649 };
6650
6651 /*
6652  * 6ch mode
6653  */
6654 static struct hda_verb alc883_sixstack_ch6_init[] = {
6655         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6656         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6657         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6658         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6659         { } /* end */
6660 };
6661
6662 /*
6663  * 8ch mode
6664  */
6665 static struct hda_verb alc883_sixstack_ch8_init[] = {
6666         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6667         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6668         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6669         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6670         { } /* end */
6671 };
6672
6673 static struct hda_channel_mode alc883_sixstack_modes[2] = {
6674         { 6, alc883_sixstack_ch6_init },
6675         { 8, alc883_sixstack_ch8_init },
6676 };
6677
6678 static struct hda_verb alc883_medion_eapd_verbs[] = {
6679         /* eanable EAPD on medion laptop */
6680         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
6681         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
6682         { }
6683 };
6684
6685 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
6686  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
6687  */
6688
6689 static struct snd_kcontrol_new alc883_base_mixer[] = {
6690         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6691         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6692         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6693         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6694         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6695         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6696         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6697         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6698         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6699         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6700         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6701         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6702         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6703         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6704         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6705         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6706         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6707         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6708         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6709         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6710         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6711         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6712         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6713         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6714         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6715         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6716         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6717         {
6718                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6719                 /* .name = "Capture Source", */
6720                 .name = "Input Source",
6721                 .count = 2,
6722                 .info = alc883_mux_enum_info,
6723                 .get = alc883_mux_enum_get,
6724                 .put = alc883_mux_enum_put,
6725         },
6726         { } /* end */
6727 };
6728
6729 static struct snd_kcontrol_new alc883_mitac_mixer[] = {
6730         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6731         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6732         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6733         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6734         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6735         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6736         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6737         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6738         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6739         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6740         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6741         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6742         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6743         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6744         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6745         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6746         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6747         {
6748                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6749                 /* .name = "Capture Source", */
6750                 .name = "Input Source",
6751                 .count = 2,
6752                 .info = alc883_mux_enum_info,
6753                 .get = alc883_mux_enum_get,
6754                 .put = alc883_mux_enum_put,
6755         },
6756         { } /* end */
6757 };
6758
6759 static struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
6760         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6761         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
6762         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6763         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
6764         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6765         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6766         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6767         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6768         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
6769         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6770         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6771         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6772         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6773         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6774         {
6775                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6776                 /* .name = "Capture Source", */
6777                 .name = "Input Source",
6778                 .count = 2,
6779                 .info = alc883_mux_enum_info,
6780                 .get = alc883_mux_enum_get,
6781                 .put = alc883_mux_enum_put,
6782         },
6783         { } /* end */
6784 };
6785
6786 static struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
6787         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6788         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
6789         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6790         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
6791         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6792         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6793         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6794         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6795         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
6796         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6797         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6798         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6799         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6800         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6801         {
6802                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6803                 /* .name = "Capture Source", */
6804                 .name = "Input Source",
6805                 .count = 2,
6806                 .info = alc883_mux_enum_info,
6807                 .get = alc883_mux_enum_get,
6808                 .put = alc883_mux_enum_put,
6809         },
6810         { } /* end */
6811 };
6812
6813 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
6814         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6815         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6816         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6817         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6818         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6819         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6820         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6821         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6822         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6823         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6824         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6825         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6826         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6827         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6828         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6829         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6830         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6831         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6832         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6833         {
6834                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6835                 /* .name = "Capture Source", */
6836                 .name = "Input Source",
6837                 .count = 2,
6838                 .info = alc883_mux_enum_info,
6839                 .get = alc883_mux_enum_get,
6840                 .put = alc883_mux_enum_put,
6841         },
6842         { } /* end */
6843 };
6844
6845 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
6846         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6847         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6848         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6849         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6850         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6851         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6852         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6853         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6854         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6855         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6856         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6857         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6858         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6859         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6860         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6861         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6862         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6863         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6864         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6865         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6866         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6867         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6868         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6869         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6870         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6871         {
6872                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6873                 /* .name = "Capture Source", */
6874                 .name = "Input Source",
6875                 .count = 2,
6876                 .info = alc883_mux_enum_info,
6877                 .get = alc883_mux_enum_get,
6878                 .put = alc883_mux_enum_put,
6879         },
6880         { } /* end */
6881 };
6882
6883 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
6884         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6885         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6886         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6887         HDA_CODEC_MUTE("Surround Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6888         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6889         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6890         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x16, 1, 0x0, HDA_OUTPUT),
6891         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
6892         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6893         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6894         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6895         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6896         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6897         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6898         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6899         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6900         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6901         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6902         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6903         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6904         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6905         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6906         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6907
6908         {
6909                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6910                 /* .name = "Capture Source", */
6911                 .name = "Input Source",
6912                 .count = 1,
6913                 .info = alc883_mux_enum_info,
6914                 .get = alc883_mux_enum_get,
6915                 .put = alc883_mux_enum_put,
6916         },
6917         { } /* end */
6918 };
6919
6920 static struct snd_kcontrol_new alc883_tagra_mixer[] = {
6921         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6922         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6923         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6924         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6925         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6926         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6927         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6928         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6929         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6930         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6931         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6932         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6933         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6934         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6935         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6936         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6937         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6938         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6939         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6940         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6941         {
6942                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6943                 /* .name = "Capture Source", */
6944                 .name = "Input Source",
6945                 .count = 2,
6946                 .info = alc883_mux_enum_info,
6947                 .get = alc883_mux_enum_get,
6948                 .put = alc883_mux_enum_put,
6949         },
6950         { } /* end */
6951 };
6952
6953 static struct snd_kcontrol_new alc883_tagra_2ch_mixer[] = {
6954         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6955         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6956         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6957         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6958         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6959         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6960         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6961         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6962         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6963         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
6964         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6965         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6966         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6967         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6968         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6969         {
6970                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6971                 /* .name = "Capture Source", */
6972                 .name = "Input Source",
6973                 .count = 2,
6974                 .info = alc883_mux_enum_info,
6975                 .get = alc883_mux_enum_get,
6976                 .put = alc883_mux_enum_put,
6977         },
6978         { } /* end */
6979 };
6980
6981 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
6982         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6983         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6984         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6985         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
6986         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6987         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6988         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6989         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6990         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6991         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6992         {
6993                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6994                 /* .name = "Capture Source", */
6995                 .name = "Input Source",
6996                 .count = 1,
6997                 .info = alc883_mux_enum_info,
6998                 .get = alc883_mux_enum_get,
6999                 .put = alc883_mux_enum_put,
7000         },
7001         { } /* end */
7002 };
7003
7004 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
7005         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7006         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
7007         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7008         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7009         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7010         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7011         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7012         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7013         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7014         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7015         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7016         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7017         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7018         {
7019                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7020                 /* .name = "Capture Source", */
7021                 .name = "Input Source",
7022                 .count = 2,
7023                 .info = alc883_mux_enum_info,
7024                 .get = alc883_mux_enum_get,
7025                 .put = alc883_mux_enum_put,
7026         },
7027         { } /* end */
7028 };
7029
7030 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
7031         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7032         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7033         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7034         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7035         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7036         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7037         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7038         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7039         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7040         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7041         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7042         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7043         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7044         {
7045                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7046                 /* .name = "Capture Source", */
7047                 .name = "Input Source",
7048                 .count = 2,
7049                 .info = alc883_mux_enum_info,
7050                 .get = alc883_mux_enum_get,
7051                 .put = alc883_mux_enum_put,
7052         },
7053         { } /* end */
7054 };      
7055
7056 static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
7057         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7058         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7059         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7060         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7061         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7062         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7063         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7064         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7065         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7066         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7067         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7068         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7069         {
7070                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7071                 /* .name = "Capture Source", */
7072                 .name = "Input Source",
7073                 .count = 2,
7074                 .info = alc883_mux_enum_info,
7075                 .get = alc883_mux_enum_get,
7076                 .put = alc883_mux_enum_put,
7077         },
7078         { } /* end */
7079 };
7080
7081 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
7082         {
7083                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7084                 .name = "Channel Mode",
7085                 .info = alc_ch_mode_info,
7086                 .get = alc_ch_mode_get,
7087                 .put = alc_ch_mode_put,
7088         },
7089         { } /* end */
7090 };
7091
7092 static struct hda_verb alc883_init_verbs[] = {
7093         /* ADC1: mute amp left and right */
7094         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7095         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7096         /* ADC2: mute amp left and right */
7097         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7098         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7099         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7100         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7101         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7102         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7103         /* Rear mixer */
7104         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7105         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7106         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7107         /* CLFE mixer */
7108         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7109         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7110         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7111         /* Side mixer */
7112         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7113         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7114         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7115
7116         /* mute analog input loopbacks */
7117         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7118         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7119         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7120         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7121         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7122
7123         /* Front Pin: output 0 (0x0c) */
7124         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7125         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7126         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7127         /* Rear Pin: output 1 (0x0d) */
7128         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7129         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7130         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7131         /* CLFE Pin: output 2 (0x0e) */
7132         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7133         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7134         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
7135         /* Side Pin: output 3 (0x0f) */
7136         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7137         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7138         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
7139         /* Mic (rear) pin: input vref at 80% */
7140         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7141         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7142         /* Front Mic pin: input vref at 80% */
7143         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7144         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7145         /* Line In pin: input */
7146         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7147         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7148         /* Line-2 In: Headphone output (output 0 - 0x0c) */
7149         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7150         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7151         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7152         /* CD pin widget for input */
7153         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7154
7155         /* FIXME: use matrix-type input source selection */
7156         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7157         /* Input mixer2 */
7158         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7159         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7160         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7161         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7162         /* Input mixer3 */
7163         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7164         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7165         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7166         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7167         { }
7168 };
7169
7170 /* toggle speaker-output according to the hp-jack state */
7171 static void alc883_mitac_hp_automute(struct hda_codec *codec)
7172 {
7173         unsigned int present;
7174
7175         present = snd_hda_codec_read(codec, 0x15, 0,
7176                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7177         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7178                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7179         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
7180                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7181 }
7182
7183 /* auto-toggle front mic */
7184 /*
7185 static void alc883_mitac_mic_automute(struct hda_codec *codec)
7186 {
7187         unsigned int present;
7188         unsigned char bits;
7189
7190         present = snd_hda_codec_read(codec, 0x18, 0,
7191                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7192         bits = present ? HDA_AMP_MUTE : 0;
7193         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
7194 }
7195 */
7196
7197 static void alc883_mitac_automute(struct hda_codec *codec)
7198 {
7199         alc883_mitac_hp_automute(codec);
7200         /* alc883_mitac_mic_automute(codec); */
7201 }
7202
7203 static void alc883_mitac_unsol_event(struct hda_codec *codec,
7204                                            unsigned int res)
7205 {
7206         switch (res >> 26) {
7207         case ALC880_HP_EVENT:
7208                 alc883_mitac_hp_automute(codec);
7209                 break;
7210         case ALC880_MIC_EVENT:
7211                 /* alc883_mitac_mic_automute(codec); */
7212                 break;
7213         }
7214 }
7215
7216 static struct hda_verb alc883_mitac_verbs[] = {
7217         /* HP */
7218         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7219         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7220         /* Subwoofer */
7221         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
7222         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7223
7224         /* enable unsolicited event */
7225         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7226         /* {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN}, */
7227
7228         { } /* end */
7229 };
7230
7231 static struct hda_verb alc883_clevo_m720_verbs[] = {
7232         /* HP */
7233         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7234         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7235         /* Int speaker */
7236         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
7237         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7238
7239         /* enable unsolicited event */
7240         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7241         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
7242
7243         { } /* end */
7244 };
7245
7246 static struct hda_verb alc883_2ch_fujitsu_pi2515_verbs[] = {
7247         /* HP */
7248         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7249         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7250         /* Subwoofer */
7251         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7252         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7253
7254         /* enable unsolicited event */
7255         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7256
7257         { } /* end */
7258 };
7259
7260 static struct hda_verb alc883_tagra_verbs[] = {
7261         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7262         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7263
7264         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7265         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7266         
7267         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7268         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7269         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7270
7271         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7272         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
7273         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
7274         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
7275
7276         { } /* end */
7277 };
7278
7279 static struct hda_verb alc883_lenovo_101e_verbs[] = {
7280         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7281         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
7282         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
7283         { } /* end */
7284 };
7285
7286 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
7287         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7288         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7289         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7290         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7291         { } /* end */
7292 };
7293
7294 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
7295         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7296         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7297         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7298         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
7299         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
7300         { } /* end */
7301 };
7302
7303 static struct hda_verb alc883_haier_w66_verbs[] = {
7304         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7305         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7306
7307         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7308
7309         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7310         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7311         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7312         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7313         { } /* end */
7314 };
7315
7316 static struct hda_verb alc888_3st_hp_verbs[] = {
7317         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
7318         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
7319         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
7320         { }
7321 };
7322
7323 static struct hda_verb alc888_6st_dell_verbs[] = {
7324         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7325         { }
7326 };
7327
7328 static struct hda_verb alc888_3st_hp_2ch_init[] = {
7329         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7330         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7331         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7332         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7333         { }
7334 };
7335
7336 static struct hda_verb alc888_3st_hp_6ch_init[] = {
7337         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7338         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7339         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7340         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7341         { }
7342 };
7343
7344 static struct hda_channel_mode alc888_3st_hp_modes[2] = {
7345         { 2, alc888_3st_hp_2ch_init },
7346         { 6, alc888_3st_hp_6ch_init },
7347 };
7348
7349 /* toggle front-jack and RCA according to the hp-jack state */
7350 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
7351 {
7352         unsigned int present;
7353  
7354         present = snd_hda_codec_read(codec, 0x1b, 0,
7355                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7356         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7357                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7358         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7359                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7360 }
7361
7362 /* toggle RCA according to the front-jack state */
7363 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
7364 {
7365         unsigned int present;
7366  
7367         present = snd_hda_codec_read(codec, 0x14, 0,
7368                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7369         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7370                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7371 }
7372
7373 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
7374                                              unsigned int res)
7375 {
7376         if ((res >> 26) == ALC880_HP_EVENT)
7377                 alc888_lenovo_ms7195_front_automute(codec);
7378         if ((res >> 26) == ALC880_FRONT_EVENT)
7379                 alc888_lenovo_ms7195_rca_automute(codec);
7380 }
7381
7382 static struct hda_verb alc883_medion_md2_verbs[] = {
7383         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7384         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7385
7386         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7387
7388         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7389         { } /* end */
7390 };
7391
7392 /* toggle speaker-output according to the hp-jack state */
7393 static void alc883_medion_md2_automute(struct hda_codec *codec)
7394 {
7395         unsigned int present;
7396  
7397         present = snd_hda_codec_read(codec, 0x14, 0,
7398                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7399         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7400                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7401 }
7402
7403 static void alc883_medion_md2_unsol_event(struct hda_codec *codec,
7404                                           unsigned int res)
7405 {
7406         if ((res >> 26) == ALC880_HP_EVENT)
7407                 alc883_medion_md2_automute(codec);
7408 }
7409
7410 /* toggle speaker-output according to the hp-jack state */
7411 static void alc883_tagra_automute(struct hda_codec *codec)
7412 {
7413         unsigned int present;
7414         unsigned char bits;
7415
7416         present = snd_hda_codec_read(codec, 0x14, 0,
7417                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7418         bits = present ? HDA_AMP_MUTE : 0;
7419         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
7420                                  HDA_AMP_MUTE, bits);
7421         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
7422                                   present ? 1 : 3);
7423 }
7424
7425 static void alc883_tagra_unsol_event(struct hda_codec *codec, unsigned int res)
7426 {
7427         if ((res >> 26) == ALC880_HP_EVENT)
7428                 alc883_tagra_automute(codec);
7429 }
7430
7431 /* toggle speaker-output according to the hp-jack state */
7432 static void alc883_clevo_m720_hp_automute(struct hda_codec *codec)
7433 {
7434         unsigned int present;
7435         unsigned char bits;
7436
7437         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
7438                 & AC_PINSENSE_PRESENCE;
7439         bits = present ? HDA_AMP_MUTE : 0;
7440         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7441                                  HDA_AMP_MUTE, bits);
7442 }
7443
7444 static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
7445 {
7446         unsigned int present;
7447
7448         present = snd_hda_codec_read(codec, 0x18, 0,
7449                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7450         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
7451                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7452 }
7453
7454 static void alc883_clevo_m720_automute(struct hda_codec *codec)
7455 {
7456         alc883_clevo_m720_hp_automute(codec);
7457         alc883_clevo_m720_mic_automute(codec);
7458 }
7459
7460 static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
7461                                            unsigned int res)
7462 {
7463         switch (res >> 26) {
7464         case ALC880_HP_EVENT:
7465                 alc883_clevo_m720_hp_automute(codec);
7466                 break;
7467         case ALC880_MIC_EVENT:
7468                 alc883_clevo_m720_mic_automute(codec);
7469                 break;
7470         }
7471 }
7472
7473 /* toggle speaker-output according to the hp-jack state */
7474 static void alc883_2ch_fujitsu_pi2515_automute(struct hda_codec *codec)
7475 {
7476         unsigned int present;
7477         unsigned char bits;
7478
7479         present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
7480                 & AC_PINSENSE_PRESENCE;
7481         bits = present ? HDA_AMP_MUTE : 0;
7482         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7483                                  HDA_AMP_MUTE, bits);
7484 }
7485
7486 static void alc883_2ch_fujitsu_pi2515_unsol_event(struct hda_codec *codec,
7487                                                   unsigned int res)
7488 {
7489         if ((res >> 26) == ALC880_HP_EVENT)
7490                 alc883_2ch_fujitsu_pi2515_automute(codec);
7491 }
7492
7493 static void alc883_haier_w66_automute(struct hda_codec *codec)
7494 {
7495         unsigned int present;
7496         unsigned char bits;
7497
7498         present = snd_hda_codec_read(codec, 0x1b, 0,
7499                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7500         bits = present ? 0x80 : 0;
7501         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7502                                  0x80, bits);
7503 }
7504
7505 static void alc883_haier_w66_unsol_event(struct hda_codec *codec,
7506                                          unsigned int res)
7507 {
7508         if ((res >> 26) == ALC880_HP_EVENT)
7509                 alc883_haier_w66_automute(codec);
7510 }
7511
7512 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
7513 {
7514         unsigned int present;
7515         unsigned char bits;
7516
7517         present = snd_hda_codec_read(codec, 0x14, 0,
7518                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7519         bits = present ? HDA_AMP_MUTE : 0;
7520         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7521                                  HDA_AMP_MUTE, bits);
7522 }
7523
7524 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
7525 {
7526         unsigned int present;
7527         unsigned char bits;
7528
7529         present = snd_hda_codec_read(codec, 0x1b, 0,
7530                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7531         bits = present ? HDA_AMP_MUTE : 0;
7532         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7533                                  HDA_AMP_MUTE, bits);
7534         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7535                                  HDA_AMP_MUTE, bits);
7536 }
7537
7538 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
7539                                            unsigned int res)
7540 {
7541         if ((res >> 26) == ALC880_HP_EVENT)
7542                 alc883_lenovo_101e_all_automute(codec);
7543         if ((res >> 26) == ALC880_FRONT_EVENT)
7544                 alc883_lenovo_101e_ispeaker_automute(codec);
7545 }
7546
7547 /* toggle speaker-output according to the hp-jack state */
7548 static void alc883_acer_aspire_automute(struct hda_codec *codec)
7549 {
7550         unsigned int present;
7551  
7552         present = snd_hda_codec_read(codec, 0x14, 0,
7553                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7554         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7555                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7556         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
7557                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7558 }
7559
7560 static void alc883_acer_aspire_unsol_event(struct hda_codec *codec,
7561                                            unsigned int res)
7562 {
7563         if ((res >> 26) == ALC880_HP_EVENT)
7564                 alc883_acer_aspire_automute(codec);
7565 }
7566
7567 static struct hda_verb alc883_acer_eapd_verbs[] = {
7568         /* HP Pin: output 0 (0x0c) */
7569         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7570         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7571         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7572         /* Front Pin: output 0 (0x0c) */
7573         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7574         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7575         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7576         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
7577         /* eanable EAPD on medion laptop */
7578         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7579         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
7580         /* enable unsolicited event */
7581         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7582         { }
7583 };
7584
7585 static void alc888_6st_dell_front_automute(struct hda_codec *codec)
7586 {
7587         unsigned int present;
7588  
7589         present = snd_hda_codec_read(codec, 0x1b, 0,
7590                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7591         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7592                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7593         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7594                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7595         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
7596                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7597         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
7598                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7599 }
7600
7601 static void alc888_6st_dell_unsol_event(struct hda_codec *codec,
7602                                              unsigned int res)
7603 {
7604         switch (res >> 26) {
7605         case ALC880_HP_EVENT:
7606                 printk("hp_event\n");
7607                 alc888_6st_dell_front_automute(codec);
7608                 break;
7609         }
7610 }
7611
7612 /*
7613  * generic initialization of ADC, input mixers and output mixers
7614  */
7615 static struct hda_verb alc883_auto_init_verbs[] = {
7616         /*
7617          * Unmute ADC0-2 and set the default input to mic-in
7618          */
7619         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7620         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7621         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7622         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7623
7624         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
7625          * mixer widget
7626          * Note: PASD motherboards uses the Line In 2 as the input for
7627          * front panel mic (mic 2)
7628          */
7629         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
7630         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7631         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7632         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7633         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7634         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7635
7636         /*
7637          * Set up output mixers (0x0c - 0x0f)
7638          */
7639         /* set vol=0 to output mixers */
7640         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7641         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7642         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7643         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7644         /* set up input amps for analog loopback */
7645         /* Amp Indices: DAC = 0, mixer = 1 */
7646         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7647         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7648         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7649         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7650         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7651         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7652         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7653         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7654         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7655         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7656
7657         /* FIXME: use matrix-type input source selection */
7658         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7659         /* Input mixer1 */
7660         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7661         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7662         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7663         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
7664         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7665         /* Input mixer2 */
7666         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7667         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7668         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7669         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
7670         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7671
7672         { }
7673 };
7674
7675 /* capture mixer elements */
7676 static struct snd_kcontrol_new alc883_capture_mixer[] = {
7677         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7678         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7679         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7680         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7681         {
7682                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7683                 /* The multiple "Capture Source" controls confuse alsamixer
7684                  * So call somewhat different..
7685                  */
7686                 /* .name = "Capture Source", */
7687                 .name = "Input Source",
7688                 .count = 2,
7689                 .info = alc882_mux_enum_info,
7690                 .get = alc882_mux_enum_get,
7691                 .put = alc882_mux_enum_put,
7692         },
7693         { } /* end */
7694 };
7695
7696 #ifdef CONFIG_SND_HDA_POWER_SAVE
7697 #define alc883_loopbacks        alc880_loopbacks
7698 #endif
7699
7700 /* pcm configuration: identiacal with ALC880 */
7701 #define alc883_pcm_analog_playback      alc880_pcm_analog_playback
7702 #define alc883_pcm_analog_capture       alc880_pcm_analog_capture
7703 #define alc883_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
7704 #define alc883_pcm_digital_playback     alc880_pcm_digital_playback
7705 #define alc883_pcm_digital_capture      alc880_pcm_digital_capture
7706
7707 /*
7708  * configuration and preset
7709  */
7710 static const char *alc883_models[ALC883_MODEL_LAST] = {
7711         [ALC883_3ST_2ch_DIG]    = "3stack-dig",
7712         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
7713         [ALC883_3ST_6ch]        = "3stack-6ch",
7714         [ALC883_6ST_DIG]        = "6stack-dig",
7715         [ALC883_TARGA_DIG]      = "targa-dig",
7716         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
7717         [ALC883_ACER]           = "acer",
7718         [ALC883_ACER_ASPIRE]    = "acer-aspire",
7719         [ALC883_MEDION]         = "medion",
7720         [ALC883_MEDION_MD2]     = "medion-md2",
7721         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
7722         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
7723         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
7724         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
7725         [ALC883_HAIER_W66]      = "haier-w66",
7726         [ALC888_3ST_HP]         = "3stack-hp",
7727         [ALC888_6ST_DELL]       = "6stack-dell",
7728         [ALC883_MITAC]          = "mitac",
7729         [ALC883_CLEVO_M720]     = "clevo-m720",
7730         [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
7731         [ALC883_AUTO]           = "auto",
7732 };
7733
7734 static struct snd_pci_quirk alc883_cfg_tbl[] = {
7735         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG),
7736         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
7737         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
7738         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
7739         SND_PCI_QUIRK(0x1025, 0, "Acer laptop", ALC883_ACER), /* default Acer */
7740         SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
7741         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
7742         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
7743         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
7744         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
7745         SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
7746         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
7747         SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
7748         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
7749         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
7750         SND_PCI_QUIRK(0x1458, 0xa002, "MSI", ALC883_6ST_DIG),
7751         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
7752         SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
7753         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
7754         SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC883_TARGA_2ch_DIG),
7755         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
7756         SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
7757         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
7758         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
7759         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
7760         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
7761         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
7762         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
7763         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
7764         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
7765         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
7766         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
7767         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
7768         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
7769         SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG),
7770         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
7771         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
7772         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
7773         SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
7774         SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
7775         SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
7776         SND_PCI_QUIRK(0x1558, 0, "Clevo laptop", ALC883_LAPTOP_EAPD),
7777         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
7778         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
7779         SND_PCI_QUIRK(0x1734, 0x1108, "Fujitsu AMILO Pi2515", ALC883_FUJITSU_PI2515),
7780         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
7781         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
7782         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
7783         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
7784         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
7785         SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
7786         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
7787         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
7788         {}
7789 };
7790
7791 static struct alc_config_preset alc883_presets[] = {
7792         [ALC883_3ST_2ch_DIG] = {
7793                 .mixers = { alc883_3ST_2ch_mixer },
7794                 .init_verbs = { alc883_init_verbs },
7795                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7796                 .dac_nids = alc883_dac_nids,
7797                 .dig_out_nid = ALC883_DIGOUT_NID,
7798                 .dig_in_nid = ALC883_DIGIN_NID,
7799                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7800                 .channel_mode = alc883_3ST_2ch_modes,
7801                 .input_mux = &alc883_capture_source,
7802         },
7803         [ALC883_3ST_6ch_DIG] = {
7804                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
7805                 .init_verbs = { alc883_init_verbs },
7806                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7807                 .dac_nids = alc883_dac_nids,
7808                 .dig_out_nid = ALC883_DIGOUT_NID,
7809                 .dig_in_nid = ALC883_DIGIN_NID,
7810                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7811                 .channel_mode = alc883_3ST_6ch_modes,
7812                 .need_dac_fix = 1,
7813                 .input_mux = &alc883_capture_source,
7814         },
7815         [ALC883_3ST_6ch] = {
7816                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
7817                 .init_verbs = { alc883_init_verbs },
7818                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7819                 .dac_nids = alc883_dac_nids,
7820                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7821                 .channel_mode = alc883_3ST_6ch_modes,
7822                 .need_dac_fix = 1,
7823                 .input_mux = &alc883_capture_source,
7824         },
7825         [ALC883_6ST_DIG] = {
7826                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
7827                 .init_verbs = { alc883_init_verbs },
7828                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7829                 .dac_nids = alc883_dac_nids,
7830                 .dig_out_nid = ALC883_DIGOUT_NID,
7831                 .dig_in_nid = ALC883_DIGIN_NID,
7832                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7833                 .channel_mode = alc883_sixstack_modes,
7834                 .input_mux = &alc883_capture_source,
7835         },
7836         [ALC883_TARGA_DIG] = {
7837                 .mixers = { alc883_tagra_mixer, alc883_chmode_mixer },
7838                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
7839                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7840                 .dac_nids = alc883_dac_nids,
7841                 .dig_out_nid = ALC883_DIGOUT_NID,
7842                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7843                 .channel_mode = alc883_3ST_6ch_modes,
7844                 .need_dac_fix = 1,
7845                 .input_mux = &alc883_capture_source,
7846                 .unsol_event = alc883_tagra_unsol_event,
7847                 .init_hook = alc883_tagra_automute,
7848         },
7849         [ALC883_TARGA_2ch_DIG] = {
7850                 .mixers = { alc883_tagra_2ch_mixer},
7851                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
7852                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7853                 .dac_nids = alc883_dac_nids,
7854                 .dig_out_nid = ALC883_DIGOUT_NID,
7855                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7856                 .channel_mode = alc883_3ST_2ch_modes,
7857                 .input_mux = &alc883_capture_source,
7858                 .unsol_event = alc883_tagra_unsol_event,
7859                 .init_hook = alc883_tagra_automute,
7860         },
7861         [ALC883_ACER] = {
7862                 .mixers = { alc883_base_mixer },
7863                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
7864                  * and the headphone jack.  Turn this on and rely on the
7865                  * standard mute methods whenever the user wants to turn
7866                  * these outputs off.
7867                  */
7868                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
7869                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7870                 .dac_nids = alc883_dac_nids,
7871                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7872                 .channel_mode = alc883_3ST_2ch_modes,
7873                 .input_mux = &alc883_capture_source,
7874         },
7875         [ALC883_ACER_ASPIRE] = {
7876                 .mixers = { alc883_acer_aspire_mixer },
7877                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
7878                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7879                 .dac_nids = alc883_dac_nids,
7880                 .dig_out_nid = ALC883_DIGOUT_NID,
7881                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7882                 .channel_mode = alc883_3ST_2ch_modes,
7883                 .input_mux = &alc883_capture_source,
7884                 .unsol_event = alc883_acer_aspire_unsol_event,
7885                 .init_hook = alc883_acer_aspire_automute,
7886         },
7887         [ALC883_MEDION] = {
7888                 .mixers = { alc883_fivestack_mixer,
7889                             alc883_chmode_mixer },
7890                 .init_verbs = { alc883_init_verbs,
7891                                 alc883_medion_eapd_verbs },
7892                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7893                 .dac_nids = alc883_dac_nids,
7894                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7895                 .channel_mode = alc883_sixstack_modes,
7896                 .input_mux = &alc883_capture_source,
7897         },
7898         [ALC883_MEDION_MD2] = {
7899                 .mixers = { alc883_medion_md2_mixer},
7900                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
7901                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7902                 .dac_nids = alc883_dac_nids,
7903                 .dig_out_nid = ALC883_DIGOUT_NID,
7904                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7905                 .channel_mode = alc883_3ST_2ch_modes,
7906                 .input_mux = &alc883_capture_source,
7907                 .unsol_event = alc883_medion_md2_unsol_event,
7908                 .init_hook = alc883_medion_md2_automute,
7909         },      
7910         [ALC883_LAPTOP_EAPD] = {
7911                 .mixers = { alc883_base_mixer },
7912                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
7913                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7914                 .dac_nids = alc883_dac_nids,
7915                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7916                 .channel_mode = alc883_3ST_2ch_modes,
7917                 .input_mux = &alc883_capture_source,
7918         },
7919         [ALC883_CLEVO_M720] = {
7920                 .mixers = { alc883_clevo_m720_mixer },
7921                 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
7922                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7923                 .dac_nids = alc883_dac_nids,
7924                 .dig_out_nid = ALC883_DIGOUT_NID,
7925                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7926                 .channel_mode = alc883_3ST_2ch_modes,
7927                 .input_mux = &alc883_capture_source,
7928                 .unsol_event = alc883_clevo_m720_unsol_event,
7929                 .init_hook = alc883_clevo_m720_automute,
7930         },
7931         [ALC883_LENOVO_101E_2ch] = {
7932                 .mixers = { alc883_lenovo_101e_2ch_mixer},
7933                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
7934                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7935                 .dac_nids = alc883_dac_nids,
7936                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7937                 .channel_mode = alc883_3ST_2ch_modes,
7938                 .input_mux = &alc883_lenovo_101e_capture_source,
7939                 .unsol_event = alc883_lenovo_101e_unsol_event,
7940                 .init_hook = alc883_lenovo_101e_all_automute,
7941         },
7942         [ALC883_LENOVO_NB0763] = {
7943                 .mixers = { alc883_lenovo_nb0763_mixer },
7944                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
7945                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7946                 .dac_nids = alc883_dac_nids,
7947                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7948                 .channel_mode = alc883_3ST_2ch_modes,
7949                 .need_dac_fix = 1,
7950                 .input_mux = &alc883_lenovo_nb0763_capture_source,
7951                 .unsol_event = alc883_medion_md2_unsol_event,
7952                 .init_hook = alc883_medion_md2_automute,
7953         },
7954         [ALC888_LENOVO_MS7195_DIG] = {
7955                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
7956                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
7957                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7958                 .dac_nids = alc883_dac_nids,
7959                 .dig_out_nid = ALC883_DIGOUT_NID,
7960                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7961                 .channel_mode = alc883_3ST_6ch_modes,
7962                 .need_dac_fix = 1,
7963                 .input_mux = &alc883_capture_source,
7964                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
7965                 .init_hook = alc888_lenovo_ms7195_front_automute,
7966         },
7967         [ALC883_HAIER_W66] = {
7968                 .mixers = { alc883_tagra_2ch_mixer},
7969                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
7970                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7971                 .dac_nids = alc883_dac_nids,
7972                 .dig_out_nid = ALC883_DIGOUT_NID,
7973                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7974                 .channel_mode = alc883_3ST_2ch_modes,
7975                 .input_mux = &alc883_capture_source,
7976                 .unsol_event = alc883_haier_w66_unsol_event,
7977                 .init_hook = alc883_haier_w66_automute,
7978         },
7979         [ALC888_3ST_HP] = {
7980                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
7981                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
7982                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7983                 .dac_nids = alc883_dac_nids,
7984                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
7985                 .channel_mode = alc888_3st_hp_modes,
7986                 .need_dac_fix = 1,
7987                 .input_mux = &alc883_capture_source,
7988         },
7989         [ALC888_6ST_DELL] = {
7990                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
7991                 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
7992                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7993                 .dac_nids = alc883_dac_nids,
7994                 .dig_out_nid = ALC883_DIGOUT_NID,
7995                 .dig_in_nid = ALC883_DIGIN_NID,
7996                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7997                 .channel_mode = alc883_sixstack_modes,
7998                 .input_mux = &alc883_capture_source,
7999                 .unsol_event = alc888_6st_dell_unsol_event,
8000                 .init_hook = alc888_6st_dell_front_automute,
8001         },
8002         [ALC883_MITAC] = {
8003                 .mixers = { alc883_mitac_mixer },
8004                 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
8005                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8006                 .dac_nids = alc883_dac_nids,
8007                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8008                 .channel_mode = alc883_3ST_2ch_modes,
8009                 .input_mux = &alc883_capture_source,
8010                 .unsol_event = alc883_mitac_unsol_event,
8011                 .init_hook = alc883_mitac_automute,
8012         },
8013         [ALC883_FUJITSU_PI2515] = {
8014                 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
8015                 .init_verbs = { alc883_init_verbs,
8016                                 alc883_2ch_fujitsu_pi2515_verbs},
8017                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8018                 .dac_nids = alc883_dac_nids,
8019                 .dig_out_nid = ALC883_DIGOUT_NID,
8020                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8021                 .channel_mode = alc883_3ST_2ch_modes,
8022                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
8023                 .unsol_event = alc883_2ch_fujitsu_pi2515_unsol_event,
8024                 .init_hook = alc883_2ch_fujitsu_pi2515_automute,
8025         },
8026 };
8027
8028
8029 /*
8030  * BIOS auto configuration
8031  */
8032 static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
8033                                               hda_nid_t nid, int pin_type,
8034                                               int dac_idx)
8035 {
8036         /* set as output */
8037         struct alc_spec *spec = codec->spec;
8038         int idx;
8039
8040         alc_set_pin_output(codec, nid, pin_type);
8041         if (spec->multiout.dac_nids[dac_idx] == 0x25)
8042                 idx = 4;
8043         else
8044                 idx = spec->multiout.dac_nids[dac_idx] - 2;
8045         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
8046
8047 }
8048
8049 static void alc883_auto_init_multi_out(struct hda_codec *codec)
8050 {
8051         struct alc_spec *spec = codec->spec;
8052         int i;
8053
8054         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
8055         for (i = 0; i <= HDA_SIDE; i++) {
8056                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
8057                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
8058                 if (nid)
8059                         alc883_auto_set_output_and_unmute(codec, nid, pin_type,
8060                                                           i);
8061         }
8062 }
8063
8064 static void alc883_auto_init_hp_out(struct hda_codec *codec)
8065 {
8066         struct alc_spec *spec = codec->spec;
8067         hda_nid_t pin;
8068
8069         pin = spec->autocfg.hp_pins[0];
8070         if (pin) /* connect to front */
8071                 /* use dac 0 */
8072                 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
8073         pin = spec->autocfg.speaker_pins[0];
8074         if (pin)
8075                 alc883_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
8076 }
8077
8078 #define alc883_is_input_pin(nid)        alc880_is_input_pin(nid)
8079 #define ALC883_PIN_CD_NID               ALC880_PIN_CD_NID
8080
8081 static void alc883_auto_init_analog_input(struct hda_codec *codec)
8082 {
8083         struct alc_spec *spec = codec->spec;
8084         int i;
8085
8086         for (i = 0; i < AUTO_PIN_LAST; i++) {
8087                 hda_nid_t nid = spec->autocfg.input_pins[i];
8088                 if (alc883_is_input_pin(nid)) {
8089                         snd_hda_codec_write(codec, nid, 0,
8090                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
8091                                             (i <= AUTO_PIN_FRONT_MIC ?
8092                                              PIN_VREF80 : PIN_IN));
8093                         if (nid != ALC883_PIN_CD_NID)
8094                                 snd_hda_codec_write(codec, nid, 0,
8095                                                     AC_VERB_SET_AMP_GAIN_MUTE,
8096                                                     AMP_OUT_MUTE);
8097                 }
8098         }
8099 }
8100
8101 /* almost identical with ALC880 parser... */
8102 static int alc883_parse_auto_config(struct hda_codec *codec)
8103 {
8104         struct alc_spec *spec = codec->spec;
8105         int err = alc880_parse_auto_config(codec);
8106
8107         if (err < 0)
8108                 return err;
8109         else if (!err)
8110                 return 0; /* no config found */
8111
8112         err = alc_auto_add_mic_boost(codec);
8113         if (err < 0)
8114                 return err;
8115
8116         /* hack - override the init verbs */
8117         spec->init_verbs[0] = alc883_auto_init_verbs;
8118         spec->mixers[spec->num_mixers] = alc883_capture_mixer;
8119         spec->num_mixers++;
8120
8121         return 1; /* config found */
8122 }
8123
8124 /* additional initialization for auto-configuration model */
8125 static void alc883_auto_init(struct hda_codec *codec)
8126 {
8127         struct alc_spec *spec = codec->spec;
8128         alc883_auto_init_multi_out(codec);
8129         alc883_auto_init_hp_out(codec);
8130         alc883_auto_init_analog_input(codec);
8131         if (spec->unsol_event)
8132                 alc_sku_automute(codec);
8133 }
8134
8135 static int patch_alc883(struct hda_codec *codec)
8136 {
8137         struct alc_spec *spec;
8138         int err, board_config;
8139
8140         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
8141         if (spec == NULL)
8142                 return -ENOMEM;
8143
8144         codec->spec = spec;
8145
8146         board_config = snd_hda_check_board_config(codec, ALC883_MODEL_LAST,
8147                                                   alc883_models,
8148                                                   alc883_cfg_tbl);
8149         if (board_config < 0) {
8150                 printk(KERN_INFO "hda_codec: Unknown model for ALC883, "
8151                        "trying auto-probe from BIOS...\n");
8152                 board_config = ALC883_AUTO;
8153         }
8154
8155         if (board_config == ALC883_AUTO) {
8156                 /* automatic parse from the BIOS config */
8157                 err = alc883_parse_auto_config(codec);
8158                 if (err < 0) {
8159                         alc_free(codec);
8160                         return err;
8161                 } else if (!err) {
8162                         printk(KERN_INFO
8163                                "hda_codec: Cannot set up configuration "
8164                                "from BIOS.  Using base mode...\n");
8165                         board_config = ALC883_3ST_2ch_DIG;
8166                 }
8167         }
8168
8169         if (board_config != ALC883_AUTO)
8170                 setup_preset(spec, &alc883_presets[board_config]);
8171
8172         spec->stream_name_analog = "ALC883 Analog";
8173         spec->stream_analog_playback = &alc883_pcm_analog_playback;
8174         spec->stream_analog_capture = &alc883_pcm_analog_capture;
8175         spec->stream_analog_alt_capture = &alc883_pcm_analog_alt_capture;
8176
8177         spec->stream_name_digital = "ALC883 Digital";
8178         spec->stream_digital_playback = &alc883_pcm_digital_playback;
8179         spec->stream_digital_capture = &alc883_pcm_digital_capture;
8180
8181         spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
8182         spec->adc_nids = alc883_adc_nids;
8183         spec->capsrc_nids = alc883_capsrc_nids;
8184
8185         spec->vmaster_nid = 0x0c;
8186
8187         codec->patch_ops = alc_patch_ops;
8188         if (board_config == ALC883_AUTO)
8189                 spec->init_hook = alc883_auto_init;
8190 #ifdef CONFIG_SND_HDA_POWER_SAVE
8191         if (!spec->loopback.amplist)
8192                 spec->loopback.amplist = alc883_loopbacks;
8193 #endif
8194
8195         return 0;
8196 }
8197
8198 /*
8199  * ALC262 support
8200  */
8201
8202 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
8203 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
8204
8205 #define alc262_dac_nids         alc260_dac_nids
8206 #define alc262_adc_nids         alc882_adc_nids
8207 #define alc262_adc_nids_alt     alc882_adc_nids_alt
8208 #define alc262_capsrc_nids      alc882_capsrc_nids
8209 #define alc262_capsrc_nids_alt  alc882_capsrc_nids_alt
8210
8211 #define alc262_modes            alc260_modes
8212 #define alc262_capture_source   alc882_capture_source
8213
8214 static struct snd_kcontrol_new alc262_base_mixer[] = {
8215         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8216         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8217         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8218         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8219         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8220         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8221         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8222         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8223         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8224         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8225         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8226         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8227         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8228            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
8229         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
8230         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8231         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
8232         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
8233         { } /* end */
8234 };
8235
8236 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
8237         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8238         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8239         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8240         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8241         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8242         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8243         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8244         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8245         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8246         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8247         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8248         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8249         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8250            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
8251         /*HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),*/
8252         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8253         { } /* end */
8254 };
8255
8256 /* update HP, line and mono-out pins according to the master switch */
8257 static void alc262_hp_master_update(struct hda_codec *codec)
8258 {
8259         struct alc_spec *spec = codec->spec;
8260         int val = spec->master_sw;
8261
8262         /* HP & line-out */
8263         snd_hda_codec_write_cache(codec, 0x1b, 0,
8264                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
8265                                   val ? PIN_HP : 0);
8266         snd_hda_codec_write_cache(codec, 0x15, 0,
8267                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
8268                                   val ? PIN_HP : 0);
8269         /* mono (speaker) depending on the HP jack sense */
8270         val = val && !spec->jack_present;
8271         snd_hda_codec_write_cache(codec, 0x16, 0,
8272                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
8273                                   val ? PIN_OUT : 0);
8274 }
8275
8276 static void alc262_hp_bpc_automute(struct hda_codec *codec)
8277 {
8278         struct alc_spec *spec = codec->spec;
8279         unsigned int presence;
8280         presence = snd_hda_codec_read(codec, 0x1b, 0,
8281                                       AC_VERB_GET_PIN_SENSE, 0);
8282         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
8283         alc262_hp_master_update(codec);
8284 }
8285
8286 static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res)
8287 {
8288         if ((res >> 26) != ALC880_HP_EVENT)
8289                 return;
8290         alc262_hp_bpc_automute(codec);
8291 }
8292
8293 static void alc262_hp_wildwest_automute(struct hda_codec *codec)
8294 {
8295         struct alc_spec *spec = codec->spec;
8296         unsigned int presence;
8297         presence = snd_hda_codec_read(codec, 0x15, 0,
8298                                       AC_VERB_GET_PIN_SENSE, 0);
8299         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
8300         alc262_hp_master_update(codec);
8301 }
8302
8303 static void alc262_hp_wildwest_unsol_event(struct hda_codec *codec,
8304                                            unsigned int res)
8305 {
8306         if ((res >> 26) != ALC880_HP_EVENT)
8307                 return;
8308         alc262_hp_wildwest_automute(codec);
8309 }
8310
8311 static int alc262_hp_master_sw_get(struct snd_kcontrol *kcontrol,
8312                                    struct snd_ctl_elem_value *ucontrol)
8313 {
8314         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8315         struct alc_spec *spec = codec->spec;
8316         *ucontrol->value.integer.value = spec->master_sw;
8317         return 0;
8318 }
8319
8320 static int alc262_hp_master_sw_put(struct snd_kcontrol *kcontrol,
8321                                    struct snd_ctl_elem_value *ucontrol)
8322 {
8323         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8324         struct alc_spec *spec = codec->spec;
8325         int val = !!*ucontrol->value.integer.value;
8326
8327         if (val == spec->master_sw)
8328                 return 0;
8329         spec->master_sw = val;
8330         alc262_hp_master_update(codec);
8331         return 1;
8332 }
8333
8334 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
8335         {
8336                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8337                 .name = "Master Playback Switch",
8338                 .info = snd_ctl_boolean_mono_info,
8339                 .get = alc262_hp_master_sw_get,
8340                 .put = alc262_hp_master_sw_put,
8341         },
8342         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8343         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8344         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8345         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
8346                               HDA_OUTPUT),
8347         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
8348                             HDA_OUTPUT),
8349         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8350         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8351         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8352         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8353         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8354         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8355         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8356         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8357         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8358         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8359         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8360         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
8361         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
8362         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
8363         { } /* end */
8364 };
8365
8366 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
8367         {
8368                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8369                 .name = "Master Playback Switch",
8370                 .info = snd_ctl_boolean_mono_info,
8371                 .get = alc262_hp_master_sw_get,
8372                 .put = alc262_hp_master_sw_put,
8373         },
8374         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8375         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8376         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8377         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8378         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
8379                               HDA_OUTPUT),
8380         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
8381                             HDA_OUTPUT),
8382         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
8383         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
8384         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
8385         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
8386         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
8387         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8388         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8389         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8390         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
8391         { } /* end */
8392 };
8393
8394 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
8395         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8396         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8397         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
8398         { } /* end */
8399 };
8400
8401 /* mute/unmute internal speaker according to the hp jack and mute state */
8402 static void alc262_hp_t5735_automute(struct hda_codec *codec, int force)
8403 {
8404         struct alc_spec *spec = codec->spec;
8405
8406         if (force || !spec->sense_updated) {
8407                 unsigned int present;
8408                 present = snd_hda_codec_read(codec, 0x15, 0,
8409                                              AC_VERB_GET_PIN_SENSE, 0);
8410                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
8411                 spec->sense_updated = 1;
8412         }
8413         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0, HDA_AMP_MUTE,
8414                                  spec->jack_present ? HDA_AMP_MUTE : 0);
8415 }
8416
8417 static void alc262_hp_t5735_unsol_event(struct hda_codec *codec,
8418                                         unsigned int res)
8419 {
8420         if ((res >> 26) != ALC880_HP_EVENT)
8421                 return;
8422         alc262_hp_t5735_automute(codec, 1);
8423 }
8424
8425 static void alc262_hp_t5735_init_hook(struct hda_codec *codec)
8426 {
8427         alc262_hp_t5735_automute(codec, 1);
8428 }
8429
8430 static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
8431         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8432         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8433         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8434         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8435         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8436         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8437         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8438         { } /* end */
8439 };
8440
8441 static struct hda_verb alc262_hp_t5735_verbs[] = {
8442         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8443         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8444
8445         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8446         { }
8447 };
8448
8449 static struct snd_kcontrol_new alc262_hp_rp5700_mixer[] = {
8450         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8451         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8452         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
8453         HDA_CODEC_MUTE("Speaker Playback Switch", 0x16, 0x0, HDA_OUTPUT),
8454         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
8455         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
8456         { } /* end */
8457 };
8458
8459 static struct hda_verb alc262_hp_rp5700_verbs[] = {
8460         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8461         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8462         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8463         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8464         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8465         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8466         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8467         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8468         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
8469         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
8470         {}
8471 };
8472
8473 static struct hda_input_mux alc262_hp_rp5700_capture_source = {
8474         .num_items = 1,
8475         .items = {
8476                 { "Line", 0x1 },
8477         },
8478 };
8479
8480 /* bind hp and internal speaker mute (with plug check) */
8481 static int alc262_sony_master_sw_put(struct snd_kcontrol *kcontrol,
8482                                      struct snd_ctl_elem_value *ucontrol)
8483 {
8484         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8485         long *valp = ucontrol->value.integer.value;
8486         int change;
8487
8488         /* change hp mute */
8489         change = snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
8490                                           HDA_AMP_MUTE,
8491                                           valp[0] ? 0 : HDA_AMP_MUTE);
8492         change |= snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
8493                                            HDA_AMP_MUTE,
8494                                            valp[1] ? 0 : HDA_AMP_MUTE);
8495         if (change) {
8496                 /* change speaker according to HP jack state */
8497                 struct alc_spec *spec = codec->spec;
8498                 unsigned int mute;
8499                 if (spec->jack_present)
8500                         mute = HDA_AMP_MUTE;
8501                 else
8502                         mute = snd_hda_codec_amp_read(codec, 0x15, 0,
8503                                                       HDA_OUTPUT, 0);
8504                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8505                                          HDA_AMP_MUTE, mute);
8506         }
8507         return change;
8508 }
8509
8510 static struct snd_kcontrol_new alc262_sony_mixer[] = {
8511         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8512         {
8513                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8514                 .name = "Master Playback Switch",
8515                 .info = snd_hda_mixer_amp_switch_info,
8516                 .get = snd_hda_mixer_amp_switch_get,
8517                 .put = alc262_sony_master_sw_put,
8518                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
8519         },
8520         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8521         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8522         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8523         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8524         { } /* end */
8525 };
8526
8527 static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
8528         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8529         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8530         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8531         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8532         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8533         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8534         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8535         { } /* end */
8536 };
8537
8538 #define alc262_capture_mixer            alc882_capture_mixer
8539 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
8540
8541 /*
8542  * generic initialization of ADC, input mixers and output mixers
8543  */
8544 static struct hda_verb alc262_init_verbs[] = {
8545         /*
8546          * Unmute ADC0-2 and set the default input to mic-in
8547          */
8548         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
8549         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8550         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8551         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8552         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8553         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8554
8555         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8556          * mixer widget
8557          * Note: PASD motherboards uses the Line In 2 as the input for
8558          * front panel mic (mic 2)
8559          */
8560         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8561         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8562         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8563         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8564         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8565         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8566
8567         /*
8568          * Set up output mixers (0x0c - 0x0e)
8569          */
8570         /* set vol=0 to output mixers */
8571         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8572         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8573         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8574         /* set up input amps for analog loopback */
8575         /* Amp Indices: DAC = 0, mixer = 1 */
8576         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8577         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8578         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8579         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8580         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8581         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8582
8583         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
8584         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8585         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
8586         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8587         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8588         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8589
8590         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8591         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8592         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8593         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8594         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8595         
8596         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8597         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
8598         
8599         /* FIXME: use matrix-type input source selection */
8600         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8601         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
8602         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8603         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8604         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8605         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8606         /* Input mixer2 */
8607         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8608         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8609         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8610         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8611         /* Input mixer3 */
8612         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8613         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8614         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8615         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8616
8617         { }
8618 };
8619
8620 static struct hda_verb alc262_hippo_unsol_verbs[] = {
8621         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8622         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8623         {}
8624 };
8625
8626 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
8627         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8628         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8629         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8630
8631         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8632         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8633         {}
8634 };
8635
8636 static struct hda_verb alc262_sony_unsol_verbs[] = {
8637         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8638         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8639         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
8640
8641         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8642         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8643 };
8644
8645 /* mute/unmute internal speaker according to the hp jack and mute state */
8646 static void alc262_hippo_automute(struct hda_codec *codec)
8647 {
8648         struct alc_spec *spec = codec->spec;
8649         unsigned int mute;
8650         unsigned int present;
8651
8652         /* need to execute and sync at first */
8653         snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
8654         present = snd_hda_codec_read(codec, 0x15, 0,
8655                                      AC_VERB_GET_PIN_SENSE, 0);
8656         spec->jack_present = (present & 0x80000000) != 0;
8657         if (spec->jack_present) {
8658                 /* mute internal speaker */
8659                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8660                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8661         } else {
8662                 /* unmute internal speaker if necessary */
8663                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
8664                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8665                                          HDA_AMP_MUTE, mute);
8666         }
8667 }
8668
8669 /* unsolicited event for HP jack sensing */
8670 static void alc262_hippo_unsol_event(struct hda_codec *codec,
8671                                        unsigned int res)
8672 {
8673         if ((res >> 26) != ALC880_HP_EVENT)
8674                 return;
8675         alc262_hippo_automute(codec);
8676 }
8677
8678 static void alc262_hippo1_automute(struct hda_codec *codec)
8679 {
8680         unsigned int mute;
8681         unsigned int present;
8682
8683         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
8684         present = snd_hda_codec_read(codec, 0x1b, 0,
8685                                      AC_VERB_GET_PIN_SENSE, 0);
8686         present = (present & 0x80000000) != 0;
8687         if (present) {
8688                 /* mute internal speaker */
8689                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8690                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8691         } else {
8692                 /* unmute internal speaker if necessary */
8693                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
8694                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8695                                          HDA_AMP_MUTE, mute);
8696         }
8697 }
8698
8699 /* unsolicited event for HP jack sensing */
8700 static void alc262_hippo1_unsol_event(struct hda_codec *codec,
8701                                        unsigned int res)
8702 {
8703         if ((res >> 26) != ALC880_HP_EVENT)
8704                 return;
8705         alc262_hippo1_automute(codec);
8706 }
8707
8708 /*
8709  * fujitsu model
8710  *  0x14 = headphone/spdif-out, 0x15 = internal speaker,
8711  *  0x1b = port replicator headphone out
8712  */
8713
8714 #define ALC_HP_EVENT    0x37
8715
8716 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
8717         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
8718         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8719         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
8720         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8721         {}
8722 };
8723
8724 static struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
8725         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
8726         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8727         {}
8728 };
8729
8730 static struct hda_input_mux alc262_fujitsu_capture_source = {
8731         .num_items = 3,
8732         .items = {
8733                 { "Mic", 0x0 },
8734                 { "Int Mic", 0x1 },
8735                 { "CD", 0x4 },
8736         },
8737 };
8738
8739 static struct hda_input_mux alc262_HP_capture_source = {
8740         .num_items = 5,
8741         .items = {
8742                 { "Mic", 0x0 },
8743                 { "Front Mic", 0x1 },
8744                 { "Line", 0x2 },
8745                 { "CD", 0x4 },
8746                 { "AUX IN", 0x6 },
8747         },
8748 };
8749
8750 static struct hda_input_mux alc262_HP_D7000_capture_source = {
8751         .num_items = 4,
8752         .items = {
8753                 { "Mic", 0x0 },
8754                 { "Front Mic", 0x2 },
8755                 { "Line", 0x1 },
8756                 { "CD", 0x4 },
8757         },
8758 };
8759
8760 /* mute/unmute internal speaker according to the hp jack and mute state */
8761 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
8762 {
8763         struct alc_spec *spec = codec->spec;
8764         unsigned int mute;
8765
8766         if (force || !spec->sense_updated) {
8767                 unsigned int present_int_hp, present_dock_hp;
8768                 /* need to execute and sync at first */
8769                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
8770                 present_int_hp = snd_hda_codec_read(codec, 0x14, 0,
8771                                         AC_VERB_GET_PIN_SENSE, 0);
8772                 snd_hda_codec_read(codec, 0x1B, 0, AC_VERB_SET_PIN_SENSE, 0);
8773                 present_dock_hp = snd_hda_codec_read(codec, 0x1b, 0,
8774                                         AC_VERB_GET_PIN_SENSE, 0);
8775                 spec->jack_present = (present_int_hp & 0x80000000) != 0;
8776                 spec->jack_present |= (present_dock_hp & 0x80000000) != 0;
8777                 spec->sense_updated = 1;
8778         }
8779         if (spec->jack_present) {
8780                 /* mute internal speaker */
8781                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8782                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8783         } else {
8784                 /* unmute internal speaker if necessary */
8785                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
8786                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8787                                          HDA_AMP_MUTE, mute);
8788         }
8789 }
8790
8791 /* unsolicited event for HP jack sensing */
8792 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
8793                                        unsigned int res)
8794 {
8795         if ((res >> 26) != ALC_HP_EVENT)
8796                 return;
8797         alc262_fujitsu_automute(codec, 1);
8798 }
8799
8800 /* bind volumes of both NID 0x0c and 0x0d */
8801 static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
8802         .ops = &snd_hda_bind_vol,
8803         .values = {
8804                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
8805                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
8806                 0
8807         },
8808 };
8809
8810 /* mute/unmute internal speaker according to the hp jack and mute state */
8811 static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
8812 {
8813         struct alc_spec *spec = codec->spec;
8814         unsigned int mute;
8815
8816         if (force || !spec->sense_updated) {
8817                 unsigned int present_int_hp;
8818                 /* need to execute and sync at first */
8819                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
8820                 present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
8821                                         AC_VERB_GET_PIN_SENSE, 0);
8822                 spec->jack_present = (present_int_hp & 0x80000000) != 0;
8823                 spec->sense_updated = 1;
8824         }
8825         if (spec->jack_present) {
8826                 /* mute internal speaker */
8827                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8828                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8829                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8830                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8831         } else {
8832                 /* unmute internal speaker if necessary */
8833                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
8834                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8835                                          HDA_AMP_MUTE, mute);
8836                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8837                                          HDA_AMP_MUTE, mute);
8838         }
8839 }
8840
8841 /* unsolicited event for HP jack sensing */
8842 static void alc262_lenovo_3000_unsol_event(struct hda_codec *codec,
8843                                        unsigned int res)
8844 {
8845         if ((res >> 26) != ALC_HP_EVENT)
8846                 return;
8847         alc262_lenovo_3000_automute(codec, 1);
8848 }
8849
8850 /* bind hp and internal speaker mute (with plug check) */
8851 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
8852                                          struct snd_ctl_elem_value *ucontrol)
8853 {
8854         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8855         long *valp = ucontrol->value.integer.value;
8856         int change;
8857
8858         change = snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8859                                                  HDA_AMP_MUTE,
8860                                                  valp ? 0 : HDA_AMP_MUTE);
8861         change |= snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
8862                                                  HDA_AMP_MUTE,
8863                                                  valp ? 0 : HDA_AMP_MUTE);
8864
8865         if (change)
8866                 alc262_fujitsu_automute(codec, 0);
8867         return change;
8868 }
8869
8870 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
8871         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
8872         {
8873                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8874                 .name = "Master Playback Switch",
8875                 .info = snd_hda_mixer_amp_switch_info,
8876                 .get = snd_hda_mixer_amp_switch_get,
8877                 .put = alc262_fujitsu_master_sw_put,
8878                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
8879         },
8880         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8881         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8882         HDA_CODEC_VOLUME("PC Speaker Volume", 0x0b, 0x05, HDA_INPUT),
8883         HDA_CODEC_MUTE("PC Speaker Switch", 0x0b, 0x05, HDA_INPUT),
8884         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8885         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8886         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8887         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
8888         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8889         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8890         { } /* end */
8891 };
8892
8893 /* bind hp and internal speaker mute (with plug check) */
8894 static int alc262_lenovo_3000_master_sw_put(struct snd_kcontrol *kcontrol,
8895                                          struct snd_ctl_elem_value *ucontrol)
8896 {
8897         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8898         long *valp = ucontrol->value.integer.value;
8899         int change;
8900
8901         change = snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
8902                                                  HDA_AMP_MUTE,
8903                                                  valp ? 0 : HDA_AMP_MUTE);
8904
8905         if (change)
8906                 alc262_lenovo_3000_automute(codec, 0);
8907         return change;
8908 }
8909
8910 static struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
8911         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
8912         {
8913                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8914                 .name = "Master Playback Switch",
8915                 .info = snd_hda_mixer_amp_switch_info,
8916                 .get = snd_hda_mixer_amp_switch_get,
8917                 .put = alc262_lenovo_3000_master_sw_put,
8918                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
8919         },
8920         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8921         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8922         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8923         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8924         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8925         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
8926         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8927         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8928         { } /* end */
8929 };
8930
8931 /* additional init verbs for Benq laptops */
8932 static struct hda_verb alc262_EAPD_verbs[] = {
8933         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
8934         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
8935         {}
8936 };
8937
8938 static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
8939         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8940         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8941
8942         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
8943         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
8944         {}
8945 };
8946
8947 /* Samsung Q1 Ultra Vista model setup */
8948 static struct snd_kcontrol_new alc262_ultra_mixer[] = {
8949         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8950         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
8951         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8952         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8953         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
8954         HDA_CODEC_VOLUME("Headphone Mic Boost", 0x15, 0, HDA_INPUT),
8955         { } /* end */
8956 };
8957
8958 static struct hda_verb alc262_ultra_verbs[] = {
8959         /* output mixer */
8960         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8961         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8962         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8963         /* speaker */
8964         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8965         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8966         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8967         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8968         /* HP */
8969         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8970         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8971         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8972         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8973         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8974         /* internal mic */
8975         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8976         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8977         /* ADC, choose mic */
8978         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8979         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8980         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8981         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8982         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8983         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8984         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
8985         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
8986         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
8987         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(8)},
8988         {}
8989 };
8990
8991 /* mute/unmute internal speaker according to the hp jack and mute state */
8992 static void alc262_ultra_automute(struct hda_codec *codec)
8993 {
8994         struct alc_spec *spec = codec->spec;
8995         unsigned int mute;
8996
8997         mute = 0;
8998         /* auto-mute only when HP is used as HP */
8999         if (!spec->cur_mux[0]) {
9000                 unsigned int present;
9001                 /* need to execute and sync at first */
9002                 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
9003                 present = snd_hda_codec_read(codec, 0x15, 0,
9004                                              AC_VERB_GET_PIN_SENSE, 0);
9005                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
9006                 if (spec->jack_present)
9007                         mute = HDA_AMP_MUTE;
9008         }
9009         /* mute/unmute internal speaker */
9010         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9011                                  HDA_AMP_MUTE, mute);
9012         /* mute/unmute HP */
9013         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9014                                  HDA_AMP_MUTE, mute ? 0 : HDA_AMP_MUTE);
9015 }
9016
9017 /* unsolicited event for HP jack sensing */
9018 static void alc262_ultra_unsol_event(struct hda_codec *codec,
9019                                        unsigned int res)
9020 {
9021         if ((res >> 26) != ALC880_HP_EVENT)
9022                 return;
9023         alc262_ultra_automute(codec);
9024 }
9025
9026 static struct hda_input_mux alc262_ultra_capture_source = {
9027         .num_items = 2,
9028         .items = {
9029                 { "Mic", 0x1 },
9030                 { "Headphone", 0x7 },
9031         },
9032 };
9033
9034 static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
9035                                      struct snd_ctl_elem_value *ucontrol)
9036 {
9037         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9038         struct alc_spec *spec = codec->spec;
9039         int ret;
9040
9041         ret = alc882_mux_enum_put(kcontrol, ucontrol);
9042         if (!ret)
9043                 return 0;
9044         /* reprogram the HP pin as mic or HP according to the input source */
9045         snd_hda_codec_write_cache(codec, 0x15, 0,
9046                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9047                                   spec->cur_mux[0] ? PIN_VREF80 : PIN_HP);
9048         alc262_ultra_automute(codec); /* mute/unmute HP */
9049         return ret;
9050 }
9051
9052 static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
9053         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
9054         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
9055         {
9056                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9057                 .name = "Capture Source",
9058                 .info = alc882_mux_enum_info,
9059                 .get = alc882_mux_enum_get,
9060                 .put = alc262_ultra_mux_enum_put,
9061         },
9062         { } /* end */
9063 };
9064
9065 /* add playback controls from the parsed DAC table */
9066 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
9067                                              const struct auto_pin_cfg *cfg)
9068 {
9069         hda_nid_t nid;
9070         int err;
9071
9072         spec->multiout.num_dacs = 1;    /* only use one dac */
9073         spec->multiout.dac_nids = spec->private_dac_nids;
9074         spec->multiout.dac_nids[0] = 2;
9075
9076         nid = cfg->line_out_pins[0];
9077         if (nid) {
9078                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
9079                                   "Front Playback Volume",
9080                                   HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT));
9081                 if (err < 0)
9082                         return err;
9083                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9084                                   "Front Playback Switch",
9085                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
9086                 if (err < 0)
9087                         return err;
9088         }
9089
9090         nid = cfg->speaker_pins[0];
9091         if (nid) {
9092                 if (nid == 0x16) {
9093                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
9094                                           "Speaker Playback Volume",
9095                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
9096                                                               HDA_OUTPUT));
9097                         if (err < 0)
9098                                 return err;
9099                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9100                                           "Speaker Playback Switch",
9101                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
9102                                                               HDA_OUTPUT));
9103                         if (err < 0)
9104                                 return err;
9105                 } else {
9106                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9107                                           "Speaker Playback Switch",
9108                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
9109                                                               HDA_OUTPUT));
9110                         if (err < 0)
9111                                 return err;
9112                 }
9113         }
9114         nid = cfg->hp_pins[0];
9115         if (nid) {
9116                 /* spec->multiout.hp_nid = 2; */
9117                 if (nid == 0x16) {
9118                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
9119                                           "Headphone Playback Volume",
9120                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
9121                                                               HDA_OUTPUT));
9122                         if (err < 0)
9123                                 return err;
9124                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9125                                           "Headphone Playback Switch",
9126                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
9127                                                               HDA_OUTPUT));
9128                         if (err < 0)
9129                                 return err;
9130                 } else {
9131                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9132                                           "Headphone Playback Switch",
9133                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
9134                                                               HDA_OUTPUT));
9135                         if (err < 0)
9136                                 return err;
9137                 }
9138         }
9139         return 0;
9140 }
9141
9142 /* identical with ALC880 */
9143 #define alc262_auto_create_analog_input_ctls \
9144         alc880_auto_create_analog_input_ctls
9145
9146 /*
9147  * generic initialization of ADC, input mixers and output mixers
9148  */
9149 static struct hda_verb alc262_volume_init_verbs[] = {
9150         /*
9151          * Unmute ADC0-2 and set the default input to mic-in
9152          */
9153         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9154         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9155         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9156         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9157         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9158         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9159
9160         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9161          * mixer widget
9162          * Note: PASD motherboards uses the Line In 2 as the input for
9163          * front panel mic (mic 2)
9164          */
9165         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9166         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9167         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9168         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9169         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9170         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9171
9172         /*
9173          * Set up output mixers (0x0c - 0x0f)
9174          */
9175         /* set vol=0 to output mixers */
9176         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9177         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9178         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9179         
9180         /* set up input amps for analog loopback */
9181         /* Amp Indices: DAC = 0, mixer = 1 */
9182         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9183         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9184         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9185         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9186         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9187         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9188
9189         /* FIXME: use matrix-type input source selection */
9190         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9191         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9192         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9193         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9194         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9195         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9196         /* Input mixer2 */
9197         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9198         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9199         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9200         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9201         /* Input mixer3 */
9202         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9203         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9204         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9205         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9206
9207         { }
9208 };
9209
9210 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
9211         /*
9212          * Unmute ADC0-2 and set the default input to mic-in
9213          */
9214         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9215         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9216         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9217         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9218         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9219         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9220
9221         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9222          * mixer widget
9223          * Note: PASD motherboards uses the Line In 2 as the input for
9224          * front panel mic (mic 2)
9225          */
9226         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9227         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9228         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9229         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9230         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9231         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9232         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
9233         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
9234         
9235         /*
9236          * Set up output mixers (0x0c - 0x0e)
9237          */
9238         /* set vol=0 to output mixers */
9239         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9240         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9241         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9242
9243         /* set up input amps for analog loopback */
9244         /* Amp Indices: DAC = 0, mixer = 1 */
9245         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9246         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9247         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9248         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9249         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9250         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9251
9252         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9253         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9254         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9255
9256         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9257         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9258
9259         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9260         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9261
9262         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9263         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9264         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9265         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9266         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9267
9268         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
9269         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9270         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9271         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
9272         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9273         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9274
9275
9276         /* FIXME: use matrix-type input source selection */
9277         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9278         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9279         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9280         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9281         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9282         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9283         /* Input mixer2 */
9284         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9285         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9286         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9287         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9288         /* Input mixer3 */
9289         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9290         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9291         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9292         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9293
9294         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9295
9296         { }
9297 };
9298
9299 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
9300         /*
9301          * Unmute ADC0-2 and set the default input to mic-in
9302          */
9303         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9304         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9305         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9306         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9307         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9308         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9309
9310         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9311          * mixer widget
9312          * Note: PASD motherboards uses the Line In 2 as the input for front
9313          * panel mic (mic 2)
9314          */
9315         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9316         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9317         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9318         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9319         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9320         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9321         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
9322         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
9323         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
9324         /*
9325          * Set up output mixers (0x0c - 0x0e)
9326          */
9327         /* set vol=0 to output mixers */
9328         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9329         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9330         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9331
9332         /* set up input amps for analog loopback */
9333         /* Amp Indices: DAC = 0, mixer = 1 */
9334         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9335         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9336         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9337         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9338         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9339         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9340
9341
9342         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
9343         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
9344         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
9345         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
9346         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
9347         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
9348         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
9349
9350         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9351         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9352
9353         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9354         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
9355
9356         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
9357         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9358         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9359         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
9360         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9361         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9362
9363         /* FIXME: use matrix-type input source selection */
9364         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9365         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9366         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
9367         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
9368         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
9369         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
9370         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
9371         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
9372         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
9373         /* Input mixer2 */
9374         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9375         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9376         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9377         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9378         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9379         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
9380         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
9381         /* Input mixer3 */
9382         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9383         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9384         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9385         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9386         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9387         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
9388         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
9389
9390         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9391
9392         { }
9393 };
9394
9395 #ifdef CONFIG_SND_HDA_POWER_SAVE
9396 #define alc262_loopbacks        alc880_loopbacks
9397 #endif
9398
9399 /* pcm configuration: identiacal with ALC880 */
9400 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
9401 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
9402 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
9403 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
9404
9405 /*
9406  * BIOS auto configuration
9407  */
9408 static int alc262_parse_auto_config(struct hda_codec *codec)
9409 {
9410         struct alc_spec *spec = codec->spec;
9411         int err;
9412         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
9413
9414         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
9415                                            alc262_ignore);
9416         if (err < 0)
9417                 return err;
9418         if (!spec->autocfg.line_outs)
9419                 return 0; /* can't find valid BIOS pin config */
9420         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
9421         if (err < 0)
9422                 return err;
9423         err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg);
9424         if (err < 0)
9425                 return err;
9426
9427         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
9428
9429         if (spec->autocfg.dig_out_pin)
9430                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
9431         if (spec->autocfg.dig_in_pin)
9432                 spec->dig_in_nid = ALC262_DIGIN_NID;
9433
9434         if (spec->kctl_alloc)
9435                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
9436
9437         spec->init_verbs[spec->num_init_verbs++] = alc262_volume_init_verbs;
9438         spec->num_mux_defs = 1;
9439         spec->input_mux = &spec->private_imux;
9440
9441         err = alc_auto_add_mic_boost(codec);
9442         if (err < 0)
9443                 return err;
9444
9445         return 1;
9446 }
9447
9448 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
9449 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
9450 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
9451
9452
9453 /* init callback for auto-configuration model -- overriding the default init */
9454 static void alc262_auto_init(struct hda_codec *codec)
9455 {
9456         struct alc_spec *spec = codec->spec;
9457         alc262_auto_init_multi_out(codec);
9458         alc262_auto_init_hp_out(codec);
9459         alc262_auto_init_analog_input(codec);
9460         if (spec->unsol_event)
9461                 alc_sku_automute(codec);
9462 }
9463
9464 /*
9465  * configuration and preset
9466  */
9467 static const char *alc262_models[ALC262_MODEL_LAST] = {
9468         [ALC262_BASIC]          = "basic",
9469         [ALC262_HIPPO]          = "hippo",
9470         [ALC262_HIPPO_1]        = "hippo_1",
9471         [ALC262_FUJITSU]        = "fujitsu",
9472         [ALC262_HP_BPC]         = "hp-bpc",
9473         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
9474         [ALC262_HP_TC_T5735]    = "hp-tc-t5735",
9475         [ALC262_HP_RP5700]      = "hp-rp5700",
9476         [ALC262_BENQ_ED8]       = "benq",
9477         [ALC262_BENQ_T31]       = "benq-t31",
9478         [ALC262_SONY_ASSAMD]    = "sony-assamd",
9479         [ALC262_ULTRA]          = "ultra",
9480         [ALC262_LENOVO_3000]    = "lenovo-3000",
9481         [ALC262_AUTO]           = "auto",
9482 };
9483
9484 static struct snd_pci_quirk alc262_cfg_tbl[] = {
9485         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
9486         SND_PCI_QUIRK(0x103c, 0x12fe, "HP xw9400", ALC262_HP_BPC),
9487         SND_PCI_QUIRK(0x103c, 0x12ff, "HP xw4550", ALC262_HP_BPC),
9488         SND_PCI_QUIRK(0x103c, 0x1306, "HP xw8600", ALC262_HP_BPC),
9489         SND_PCI_QUIRK(0x103c, 0x1307, "HP xw6600", ALC262_HP_BPC),
9490         SND_PCI_QUIRK(0x103c, 0x1308, "HP xw4600", ALC262_HP_BPC),
9491         SND_PCI_QUIRK(0x103c, 0x1309, "HP xw4*00", ALC262_HP_BPC),
9492         SND_PCI_QUIRK(0x103c, 0x130a, "HP xw6*00", ALC262_HP_BPC),
9493         SND_PCI_QUIRK(0x103c, 0x130b, "HP xw8*00", ALC262_HP_BPC),
9494         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
9495         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
9496         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
9497         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
9498         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
9499         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
9500         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
9501         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
9502         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
9503         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
9504         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
9505         SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
9506                       ALC262_HP_TC_T5735),
9507         SND_PCI_QUIRK(0x103c, 0x2817, "HP RP5700", ALC262_HP_RP5700),
9508         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
9509         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
9510         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
9511         SND_PCI_QUIRK(0x104d, 0x900e, "Sony ASSAMD", ALC262_SONY_ASSAMD),
9512         SND_PCI_QUIRK(0x104d, 0x9015, "Sony 0x9015", ALC262_SONY_ASSAMD),
9513         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
9514         SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
9515         SND_PCI_QUIRK(0x144d, 0xc032, "Samsung Q1 Ultra", ALC262_ULTRA),
9516         SND_PCI_QUIRK(0x144d, 0xc039, "Samsung Q1U EL", ALC262_ULTRA),
9517         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
9518         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
9519         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
9520         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
9521         {}
9522 };
9523
9524 static struct alc_config_preset alc262_presets[] = {
9525         [ALC262_BASIC] = {
9526                 .mixers = { alc262_base_mixer },
9527                 .init_verbs = { alc262_init_verbs },
9528                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9529                 .dac_nids = alc262_dac_nids,
9530                 .hp_nid = 0x03,
9531                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9532                 .channel_mode = alc262_modes,
9533                 .input_mux = &alc262_capture_source,
9534         },
9535         [ALC262_HIPPO] = {
9536                 .mixers = { alc262_base_mixer },
9537                 .init_verbs = { alc262_init_verbs, alc262_hippo_unsol_verbs},
9538                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9539                 .dac_nids = alc262_dac_nids,
9540                 .hp_nid = 0x03,
9541                 .dig_out_nid = ALC262_DIGOUT_NID,
9542                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9543                 .channel_mode = alc262_modes,
9544                 .input_mux = &alc262_capture_source,
9545                 .unsol_event = alc262_hippo_unsol_event,
9546                 .init_hook = alc262_hippo_automute,
9547         },
9548         [ALC262_HIPPO_1] = {
9549                 .mixers = { alc262_hippo1_mixer },
9550                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
9551                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9552                 .dac_nids = alc262_dac_nids,
9553                 .hp_nid = 0x02,
9554                 .dig_out_nid = ALC262_DIGOUT_NID,
9555                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9556                 .channel_mode = alc262_modes,
9557                 .input_mux = &alc262_capture_source,
9558                 .unsol_event = alc262_hippo1_unsol_event,
9559                 .init_hook = alc262_hippo1_automute,
9560         },
9561         [ALC262_FUJITSU] = {
9562                 .mixers = { alc262_fujitsu_mixer },
9563                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
9564                                 alc262_fujitsu_unsol_verbs },
9565                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9566                 .dac_nids = alc262_dac_nids,
9567                 .hp_nid = 0x03,
9568                 .dig_out_nid = ALC262_DIGOUT_NID,
9569                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9570                 .channel_mode = alc262_modes,
9571                 .input_mux = &alc262_fujitsu_capture_source,
9572                 .unsol_event = alc262_fujitsu_unsol_event,
9573         },
9574         [ALC262_HP_BPC] = {
9575                 .mixers = { alc262_HP_BPC_mixer },
9576                 .init_verbs = { alc262_HP_BPC_init_verbs },
9577                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9578                 .dac_nids = alc262_dac_nids,
9579                 .hp_nid = 0x03,
9580                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9581                 .channel_mode = alc262_modes,
9582                 .input_mux = &alc262_HP_capture_source,
9583                 .unsol_event = alc262_hp_bpc_unsol_event,
9584                 .init_hook = alc262_hp_bpc_automute,
9585         },
9586         [ALC262_HP_BPC_D7000_WF] = {
9587                 .mixers = { alc262_HP_BPC_WildWest_mixer },
9588                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
9589                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9590                 .dac_nids = alc262_dac_nids,
9591                 .hp_nid = 0x03,
9592                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9593                 .channel_mode = alc262_modes,
9594                 .input_mux = &alc262_HP_D7000_capture_source,
9595                 .unsol_event = alc262_hp_wildwest_unsol_event,
9596                 .init_hook = alc262_hp_wildwest_automute,
9597         },
9598         [ALC262_HP_BPC_D7000_WL] = {
9599                 .mixers = { alc262_HP_BPC_WildWest_mixer,
9600                             alc262_HP_BPC_WildWest_option_mixer },
9601                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
9602                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9603                 .dac_nids = alc262_dac_nids,
9604                 .hp_nid = 0x03,
9605                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9606                 .channel_mode = alc262_modes,
9607                 .input_mux = &alc262_HP_D7000_capture_source,
9608                 .unsol_event = alc262_hp_wildwest_unsol_event,
9609                 .init_hook = alc262_hp_wildwest_automute,
9610         },
9611         [ALC262_HP_TC_T5735] = {
9612                 .mixers = { alc262_hp_t5735_mixer },
9613                 .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
9614                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9615                 .dac_nids = alc262_dac_nids,
9616                 .hp_nid = 0x03,
9617                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9618                 .channel_mode = alc262_modes,
9619                 .input_mux = &alc262_capture_source,
9620                 .unsol_event = alc262_hp_t5735_unsol_event,
9621                 .init_hook = alc262_hp_t5735_init_hook,
9622         },
9623         [ALC262_HP_RP5700] = {
9624                 .mixers = { alc262_hp_rp5700_mixer },
9625                 .init_verbs = { alc262_init_verbs, alc262_hp_rp5700_verbs },
9626                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9627                 .dac_nids = alc262_dac_nids,
9628                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9629                 .channel_mode = alc262_modes,
9630                 .input_mux = &alc262_hp_rp5700_capture_source,
9631         },
9632         [ALC262_BENQ_ED8] = {
9633                 .mixers = { alc262_base_mixer },
9634                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
9635                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9636                 .dac_nids = alc262_dac_nids,
9637                 .hp_nid = 0x03,
9638                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9639                 .channel_mode = alc262_modes,
9640                 .input_mux = &alc262_capture_source,
9641         },
9642         [ALC262_SONY_ASSAMD] = {
9643                 .mixers = { alc262_sony_mixer },
9644                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
9645                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9646                 .dac_nids = alc262_dac_nids,
9647                 .hp_nid = 0x02,
9648                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9649                 .channel_mode = alc262_modes,
9650                 .input_mux = &alc262_capture_source,
9651                 .unsol_event = alc262_hippo_unsol_event,
9652                 .init_hook = alc262_hippo_automute,
9653         },
9654         [ALC262_BENQ_T31] = {
9655                 .mixers = { alc262_benq_t31_mixer },
9656                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs, alc262_hippo_unsol_verbs },
9657                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9658                 .dac_nids = alc262_dac_nids,
9659                 .hp_nid = 0x03,
9660                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9661                 .channel_mode = alc262_modes,
9662                 .input_mux = &alc262_capture_source,
9663                 .unsol_event = alc262_hippo_unsol_event,
9664                 .init_hook = alc262_hippo_automute,
9665         },      
9666         [ALC262_ULTRA] = {
9667                 .mixers = { alc262_ultra_mixer, alc262_ultra_capture_mixer },
9668                 .init_verbs = { alc262_ultra_verbs },
9669                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9670                 .dac_nids = alc262_dac_nids,
9671                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9672                 .channel_mode = alc262_modes,
9673                 .input_mux = &alc262_ultra_capture_source,
9674                 .adc_nids = alc262_adc_nids, /* ADC0 */
9675                 .capsrc_nids = alc262_capsrc_nids,
9676                 .num_adc_nids = 1, /* single ADC */
9677                 .unsol_event = alc262_ultra_unsol_event,
9678                 .init_hook = alc262_ultra_automute,
9679         },
9680         [ALC262_LENOVO_3000] = {
9681                 .mixers = { alc262_lenovo_3000_mixer },
9682                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
9683                                 alc262_lenovo_3000_unsol_verbs },
9684                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9685                 .dac_nids = alc262_dac_nids,
9686                 .hp_nid = 0x03,
9687                 .dig_out_nid = ALC262_DIGOUT_NID,
9688                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9689                 .channel_mode = alc262_modes,
9690                 .input_mux = &alc262_fujitsu_capture_source,
9691                 .unsol_event = alc262_lenovo_3000_unsol_event,
9692         },
9693 };
9694
9695 static int patch_alc262(struct hda_codec *codec)
9696 {
9697         struct alc_spec *spec;
9698         int board_config;
9699         int err;
9700
9701         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
9702         if (spec == NULL)
9703                 return -ENOMEM;
9704
9705         codec->spec = spec;
9706 #if 0
9707         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
9708          * under-run
9709          */
9710         {
9711         int tmp;
9712         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
9713         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
9714         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
9715         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
9716         }
9717 #endif
9718
9719         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
9720                                                   alc262_models,
9721                                                   alc262_cfg_tbl);
9722
9723         if (board_config < 0) {
9724                 printk(KERN_INFO "hda_codec: Unknown model for ALC262, "
9725                        "trying auto-probe from BIOS...\n");
9726                 board_config = ALC262_AUTO;
9727         }
9728
9729         if (board_config == ALC262_AUTO) {
9730                 /* automatic parse from the BIOS config */
9731                 err = alc262_parse_auto_config(codec);
9732                 if (err < 0) {
9733                         alc_free(codec);
9734                         return err;
9735                 } else if (!err) {
9736                         printk(KERN_INFO
9737                                "hda_codec: Cannot set up configuration "
9738                                "from BIOS.  Using base mode...\n");
9739                         board_config = ALC262_BASIC;
9740                 }
9741         }
9742
9743         if (board_config != ALC262_AUTO)
9744                 setup_preset(spec, &alc262_presets[board_config]);
9745
9746         spec->stream_name_analog = "ALC262 Analog";
9747         spec->stream_analog_playback = &alc262_pcm_analog_playback;
9748         spec->stream_analog_capture = &alc262_pcm_analog_capture;
9749                 
9750         spec->stream_name_digital = "ALC262 Digital";
9751         spec->stream_digital_playback = &alc262_pcm_digital_playback;
9752         spec->stream_digital_capture = &alc262_pcm_digital_capture;
9753
9754         if (!spec->adc_nids && spec->input_mux) {
9755                 /* check whether NID 0x07 is valid */
9756                 unsigned int wcap = get_wcaps(codec, 0x07);
9757
9758                 /* get type */
9759                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
9760                 if (wcap != AC_WID_AUD_IN) {
9761                         spec->adc_nids = alc262_adc_nids_alt;
9762                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
9763                         spec->capsrc_nids = alc262_capsrc_nids_alt;
9764                         spec->mixers[spec->num_mixers] =
9765                                 alc262_capture_alt_mixer;
9766                         spec->num_mixers++;
9767                 } else {
9768                         spec->adc_nids = alc262_adc_nids;
9769                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
9770                         spec->capsrc_nids = alc262_capsrc_nids;
9771                         spec->mixers[spec->num_mixers] = alc262_capture_mixer;
9772                         spec->num_mixers++;
9773                 }
9774         }
9775
9776         spec->vmaster_nid = 0x0c;
9777
9778         codec->patch_ops = alc_patch_ops;
9779         if (board_config == ALC262_AUTO)
9780                 spec->init_hook = alc262_auto_init;
9781 #ifdef CONFIG_SND_HDA_POWER_SAVE
9782         if (!spec->loopback.amplist)
9783                 spec->loopback.amplist = alc262_loopbacks;
9784 #endif
9785                 
9786         return 0;
9787 }
9788
9789 /*
9790  *  ALC268 channel source setting (2 channel)
9791  */
9792 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
9793 #define alc268_modes            alc260_modes
9794         
9795 static hda_nid_t alc268_dac_nids[2] = {
9796         /* front, hp */
9797         0x02, 0x03
9798 };
9799
9800 static hda_nid_t alc268_adc_nids[2] = {
9801         /* ADC0-1 */
9802         0x08, 0x07
9803 };
9804
9805 static hda_nid_t alc268_adc_nids_alt[1] = {
9806         /* ADC0 */
9807         0x08
9808 };
9809
9810 static hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
9811
9812 static struct snd_kcontrol_new alc268_base_mixer[] = {
9813         /* output mixer control */
9814         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
9815         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9816         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
9817         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9818         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9819         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9820         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
9821         { }
9822 };
9823
9824 /* bind Beep switches of both NID 0x0f and 0x10 */
9825 static struct hda_bind_ctls alc268_bind_beep_sw = {
9826         .ops = &snd_hda_bind_sw,
9827         .values = {
9828                 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
9829                 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
9830                 0
9831         },
9832 };
9833
9834 static struct snd_kcontrol_new alc268_beep_mixer[] = {
9835         HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
9836         HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
9837         { }
9838 };
9839
9840 static struct hda_verb alc268_eapd_verbs[] = {
9841         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
9842         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
9843         { }
9844 };
9845
9846 /* Toshiba specific */
9847 #define alc268_toshiba_automute alc262_hippo_automute
9848
9849 static struct hda_verb alc268_toshiba_verbs[] = {
9850         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9851         { } /* end */
9852 };
9853
9854 /* Acer specific */
9855 /* bind volumes of both NID 0x02 and 0x03 */
9856 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
9857         .ops = &snd_hda_bind_vol,
9858         .values = {
9859                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
9860                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
9861                 0
9862         },
9863 };
9864
9865 /* mute/unmute internal speaker according to the hp jack and mute state */
9866 static void alc268_acer_automute(struct hda_codec *codec, int force)
9867 {
9868         struct alc_spec *spec = codec->spec;
9869         unsigned int mute;
9870
9871         if (force || !spec->sense_updated) {
9872                 unsigned int present;
9873                 present = snd_hda_codec_read(codec, 0x14, 0,
9874                                          AC_VERB_GET_PIN_SENSE, 0);
9875                 spec->jack_present = (present & 0x80000000) != 0;
9876                 spec->sense_updated = 1;
9877         }
9878         if (spec->jack_present)
9879                 mute = HDA_AMP_MUTE; /* mute internal speaker */
9880         else /* unmute internal speaker if necessary */
9881                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
9882         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9883                                  HDA_AMP_MUTE, mute);
9884 }
9885
9886
9887 /* bind hp and internal speaker mute (with plug check) */
9888 static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
9889                                      struct snd_ctl_elem_value *ucontrol)
9890 {
9891         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9892         long *valp = ucontrol->value.integer.value;
9893         int change;
9894
9895         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
9896                                           HDA_AMP_MUTE,
9897                                           valp[0] ? 0 : HDA_AMP_MUTE);
9898         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
9899                                            HDA_AMP_MUTE,
9900                                            valp[1] ? 0 : HDA_AMP_MUTE);
9901         if (change)
9902                 alc268_acer_automute(codec, 0);
9903         return change;
9904 }
9905
9906 static struct snd_kcontrol_new alc268_acer_mixer[] = {
9907         /* output mixer control */
9908         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
9909         {
9910                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9911                 .name = "Master Playback Switch",
9912                 .info = snd_hda_mixer_amp_switch_info,
9913                 .get = snd_hda_mixer_amp_switch_get,
9914                 .put = alc268_acer_master_sw_put,
9915                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
9916         },
9917         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9918         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
9919         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
9920         { }
9921 };
9922
9923 static struct hda_verb alc268_acer_verbs[] = {
9924         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
9925         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9926         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9927         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9928         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
9929         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
9930
9931         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9932         { }
9933 };
9934
9935 /* unsolicited event for HP jack sensing */
9936 static void alc268_toshiba_unsol_event(struct hda_codec *codec,
9937                                        unsigned int res)
9938 {
9939         if ((res >> 26) != ALC880_HP_EVENT)
9940                 return;
9941         alc268_toshiba_automute(codec);
9942 }
9943
9944 static void alc268_acer_unsol_event(struct hda_codec *codec,
9945                                        unsigned int res)
9946 {
9947         if ((res >> 26) != ALC880_HP_EVENT)
9948                 return;
9949         alc268_acer_automute(codec, 1);
9950 }
9951
9952 static void alc268_acer_init_hook(struct hda_codec *codec)
9953 {
9954         alc268_acer_automute(codec, 1);
9955 }
9956
9957 static struct snd_kcontrol_new alc268_dell_mixer[] = {
9958         /* output mixer control */
9959         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
9960         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9961         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
9962         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9963         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9964         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
9965         { }
9966 };
9967
9968 static struct hda_verb alc268_dell_verbs[] = {
9969         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9970         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9971         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9972         { }
9973 };
9974
9975 /* mute/unmute internal speaker according to the hp jack and mute state */
9976 static void alc268_dell_automute(struct hda_codec *codec)
9977 {
9978         unsigned int present;
9979         unsigned int mute;
9980
9981         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0);
9982         if (present & 0x80000000)
9983                 mute = HDA_AMP_MUTE;
9984         else
9985                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
9986         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9987                                  HDA_AMP_MUTE, mute);
9988 }
9989
9990 static void alc268_dell_unsol_event(struct hda_codec *codec,
9991                                     unsigned int res)
9992 {
9993         if ((res >> 26) != ALC880_HP_EVENT)
9994                 return;
9995         alc268_dell_automute(codec);
9996 }
9997
9998 #define alc268_dell_init_hook   alc268_dell_automute
9999
10000 static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
10001         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
10002         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10003         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
10004         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10005         HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
10006         HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
10007         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
10008         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
10009         { }
10010 };
10011
10012 static struct hda_verb alc267_quanta_il1_verbs[] = {
10013         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10014         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
10015         { }
10016 };
10017
10018 static void alc267_quanta_il1_hp_automute(struct hda_codec *codec)
10019 {
10020         unsigned int present;
10021
10022         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
10023                 & AC_PINSENSE_PRESENCE;
10024         snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
10025                             present ? 0 : PIN_OUT);
10026 }
10027
10028 static void alc267_quanta_il1_mic_automute(struct hda_codec *codec)
10029 {
10030         unsigned int present;
10031
10032         present = snd_hda_codec_read(codec, 0x18, 0,
10033                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10034         snd_hda_codec_write(codec, 0x23, 0,
10035                             AC_VERB_SET_CONNECT_SEL,
10036                             present ? 0x00 : 0x01);
10037 }
10038
10039 static void alc267_quanta_il1_automute(struct hda_codec *codec)
10040 {
10041         alc267_quanta_il1_hp_automute(codec);
10042         alc267_quanta_il1_mic_automute(codec);
10043 }
10044
10045 static void alc267_quanta_il1_unsol_event(struct hda_codec *codec,
10046                                            unsigned int res)
10047 {
10048         switch (res >> 26) {
10049         case ALC880_HP_EVENT:
10050                 alc267_quanta_il1_hp_automute(codec);
10051                 break;
10052         case ALC880_MIC_EVENT:
10053                 alc267_quanta_il1_mic_automute(codec);
10054                 break;
10055         }
10056 }
10057
10058 /*
10059  * generic initialization of ADC, input mixers and output mixers
10060  */
10061 static struct hda_verb alc268_base_init_verbs[] = {
10062         /* Unmute DAC0-1 and set vol = 0 */
10063         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10064         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10065         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10066         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10067         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10068         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10069
10070         /*
10071          * Set up output mixers (0x0c - 0x0e)
10072          */
10073         /* set vol=0 to output mixers */
10074         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10075         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10076         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10077         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
10078
10079         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10080         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10081
10082         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
10083         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
10084         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
10085         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10086         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10087         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10088         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10089         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10090
10091         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10092         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10093         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10094         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10095         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10096         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10097         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10098
10099         /* set PCBEEP vol = 0, mute connections */
10100         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10101         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10102         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10103
10104         /* Unmute Selector 23h,24h and set the default input to mic-in */
10105         
10106         {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
10107         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10108         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
10109         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10110
10111         { }
10112 };
10113
10114 /*
10115  * generic initialization of ADC, input mixers and output mixers
10116  */
10117 static struct hda_verb alc268_volume_init_verbs[] = {
10118         /* set output DAC */
10119         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10120         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10121         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10122         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10123
10124         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10125         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10126         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10127         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10128         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10129
10130         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10131         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10132         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10133         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10134         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10135
10136         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10137         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10138         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10139         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10140
10141         /* set PCBEEP vol = 0, mute connections */
10142         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10143         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10144         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10145
10146         { }
10147 };
10148
10149 #define alc268_mux_enum_info alc_mux_enum_info
10150 #define alc268_mux_enum_get alc_mux_enum_get
10151 #define alc268_mux_enum_put alc_mux_enum_put
10152
10153 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
10154         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
10155         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
10156         {
10157                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10158                 /* The multiple "Capture Source" controls confuse alsamixer
10159                  * So call somewhat different..
10160                  */
10161                 /* .name = "Capture Source", */
10162                 .name = "Input Source",
10163                 .count = 1,
10164                 .info = alc268_mux_enum_info,
10165                 .get = alc268_mux_enum_get,
10166                 .put = alc268_mux_enum_put,
10167         },
10168         { } /* end */
10169 };
10170
10171 static struct snd_kcontrol_new alc268_capture_mixer[] = {
10172         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
10173         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
10174         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
10175         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
10176         {
10177                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10178                 /* The multiple "Capture Source" controls confuse alsamixer
10179                  * So call somewhat different..
10180                  */
10181                 /* .name = "Capture Source", */
10182                 .name = "Input Source",
10183                 .count = 2,
10184                 .info = alc268_mux_enum_info,
10185                 .get = alc268_mux_enum_get,
10186                 .put = alc268_mux_enum_put,
10187         },
10188         { } /* end */
10189 };
10190
10191 static struct hda_input_mux alc268_capture_source = {
10192         .num_items = 4,
10193         .items = {
10194                 { "Mic", 0x0 },
10195                 { "Front Mic", 0x1 },
10196                 { "Line", 0x2 },
10197                 { "CD", 0x3 },
10198         },
10199 };
10200
10201 static struct hda_input_mux alc268_acer_capture_source = {
10202         .num_items = 3,
10203         .items = {
10204                 { "Mic", 0x0 },
10205                 { "Internal Mic", 0x6 },
10206                 { "Line", 0x2 },
10207         },
10208 };
10209
10210 #ifdef CONFIG_SND_DEBUG
10211 static struct snd_kcontrol_new alc268_test_mixer[] = {
10212         /* Volume widgets */
10213         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10214         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
10215         HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
10216         HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
10217         HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
10218         HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
10219         HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
10220         HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
10221         HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
10222         HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
10223         HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
10224         HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
10225         HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
10226         /* The below appears problematic on some hardwares */
10227         /*HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),*/
10228         HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
10229         HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
10230         HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
10231         HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),
10232
10233         /* Modes for retasking pin widgets */
10234         ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
10235         ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
10236         ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
10237         ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),
10238
10239         /* Controls for GPIO pins, assuming they are configured as outputs */
10240         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
10241         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
10242         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
10243         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
10244
10245         /* Switches to allow the digital SPDIF output pin to be enabled.
10246          * The ALC268 does not have an SPDIF input.
10247          */
10248         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),
10249
10250         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
10251          * this output to turn on an external amplifier.
10252          */
10253         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
10254         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
10255
10256         { } /* end */
10257 };
10258 #endif
10259
10260 /* create input playback/capture controls for the given pin */
10261 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
10262                                     const char *ctlname, int idx)
10263 {
10264         char name[32];
10265         int err;
10266
10267         sprintf(name, "%s Playback Volume", ctlname);
10268         if (nid == 0x14) {
10269                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
10270                                   HDA_COMPOSE_AMP_VAL(0x02, 3, idx,
10271                                                       HDA_OUTPUT));
10272                 if (err < 0)
10273                         return err;
10274         } else if (nid == 0x15) {
10275                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
10276                                   HDA_COMPOSE_AMP_VAL(0x03, 3, idx,
10277                                                       HDA_OUTPUT));
10278                 if (err < 0)
10279                         return err;
10280         } else
10281                 return -1;
10282         sprintf(name, "%s Playback Switch", ctlname);
10283         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
10284                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
10285         if (err < 0)
10286                 return err;
10287         return 0;
10288 }
10289
10290 /* add playback controls from the parsed DAC table */
10291 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
10292                                              const struct auto_pin_cfg *cfg)
10293 {
10294         hda_nid_t nid;
10295         int err;
10296
10297         spec->multiout.num_dacs = 2;    /* only use one dac */
10298         spec->multiout.dac_nids = spec->private_dac_nids;
10299         spec->multiout.dac_nids[0] = 2;
10300         spec->multiout.dac_nids[1] = 3;
10301
10302         nid = cfg->line_out_pins[0];
10303         if (nid)
10304                 alc268_new_analog_output(spec, nid, "Front", 0);        
10305
10306         nid = cfg->speaker_pins[0];
10307         if (nid == 0x1d) {
10308                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
10309                                   "Speaker Playback Volume",
10310                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
10311                 if (err < 0)
10312                         return err;
10313         }
10314         nid = cfg->hp_pins[0];
10315         if (nid)
10316                 alc268_new_analog_output(spec, nid, "Headphone", 0);
10317
10318         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
10319         if (nid == 0x16) {
10320                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10321                                   "Mono Playback Switch",
10322                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_INPUT));
10323                 if (err < 0)
10324                         return err;
10325         }
10326         return 0;       
10327 }
10328
10329 /* create playback/capture controls for input pins */
10330 static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
10331                                                 const struct auto_pin_cfg *cfg)
10332 {
10333         struct hda_input_mux *imux = &spec->private_imux;
10334         int i, idx1;
10335
10336         for (i = 0; i < AUTO_PIN_LAST; i++) {
10337                 switch(cfg->input_pins[i]) {
10338                 case 0x18:
10339                         idx1 = 0;       /* Mic 1 */
10340                         break;
10341                 case 0x19:
10342                         idx1 = 1;       /* Mic 2 */
10343                         break;
10344                 case 0x1a:
10345                         idx1 = 2;       /* Line In */
10346                         break;
10347                 case 0x1c:      
10348                         idx1 = 3;       /* CD */
10349                         break;
10350                 case 0x12:
10351                 case 0x13:
10352                         idx1 = 6;       /* digital mics */
10353                         break;
10354                 default:
10355                         continue;
10356                 }
10357                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
10358                 imux->items[imux->num_items].index = idx1;
10359                 imux->num_items++;      
10360         }
10361         return 0;
10362 }
10363
10364 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
10365 {
10366         struct alc_spec *spec = codec->spec;
10367         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
10368         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
10369         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
10370         unsigned int    dac_vol1, dac_vol2;
10371
10372         if (speaker_nid) {
10373                 snd_hda_codec_write(codec, speaker_nid, 0,
10374                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
10375                 snd_hda_codec_write(codec, 0x0f, 0,
10376                                     AC_VERB_SET_AMP_GAIN_MUTE,
10377                                     AMP_IN_UNMUTE(1));
10378                 snd_hda_codec_write(codec, 0x10, 0,
10379                                     AC_VERB_SET_AMP_GAIN_MUTE,
10380                                     AMP_IN_UNMUTE(1));
10381         } else {
10382                 snd_hda_codec_write(codec, 0x0f, 0,
10383                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
10384                 snd_hda_codec_write(codec, 0x10, 0,
10385                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
10386         }
10387
10388         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
10389         if (line_nid == 0x14)   
10390                 dac_vol2 = AMP_OUT_ZERO;
10391         else if (line_nid == 0x15)
10392                 dac_vol1 = AMP_OUT_ZERO;
10393         if (hp_nid == 0x14)     
10394                 dac_vol2 = AMP_OUT_ZERO;
10395         else if (hp_nid == 0x15)
10396                 dac_vol1 = AMP_OUT_ZERO;
10397         if (line_nid != 0x16 || hp_nid != 0x16 ||
10398             spec->autocfg.line_out_pins[1] != 0x16 ||
10399             spec->autocfg.line_out_pins[2] != 0x16)
10400                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
10401
10402         snd_hda_codec_write(codec, 0x02, 0,
10403                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
10404         snd_hda_codec_write(codec, 0x03, 0,
10405                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
10406 }
10407
10408 /* pcm configuration: identiacal with ALC880 */
10409 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
10410 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
10411 #define alc268_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
10412 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
10413
10414 /*
10415  * BIOS auto configuration
10416  */
10417 static int alc268_parse_auto_config(struct hda_codec *codec)
10418 {
10419         struct alc_spec *spec = codec->spec;
10420         int err;
10421         static hda_nid_t alc268_ignore[] = { 0 };
10422
10423         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
10424                                            alc268_ignore);
10425         if (err < 0)
10426                 return err;
10427         if (!spec->autocfg.line_outs)
10428                 return 0; /* can't find valid BIOS pin config */
10429
10430         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
10431         if (err < 0)
10432                 return err;
10433         err = alc268_auto_create_analog_input_ctls(spec, &spec->autocfg);
10434         if (err < 0)
10435                 return err;
10436
10437         spec->multiout.max_channels = 2;
10438
10439         /* digital only support output */
10440         if (spec->autocfg.dig_out_pin)
10441                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
10442
10443         if (spec->kctl_alloc)
10444                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
10445
10446         if (spec->autocfg.speaker_pins[0] != 0x1d)
10447                 spec->mixers[spec->num_mixers++] = alc268_beep_mixer;
10448
10449         spec->init_verbs[spec->num_init_verbs++] = alc268_volume_init_verbs;
10450         spec->num_mux_defs = 1;
10451         spec->input_mux = &spec->private_imux;
10452
10453         err = alc_auto_add_mic_boost(codec);
10454         if (err < 0)
10455                 return err;
10456
10457         return 1;
10458 }
10459
10460 #define alc268_auto_init_multi_out      alc882_auto_init_multi_out
10461 #define alc268_auto_init_hp_out         alc882_auto_init_hp_out
10462 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
10463
10464 /* init callback for auto-configuration model -- overriding the default init */
10465 static void alc268_auto_init(struct hda_codec *codec)
10466 {
10467         struct alc_spec *spec = codec->spec;
10468         alc268_auto_init_multi_out(codec);
10469         alc268_auto_init_hp_out(codec);
10470         alc268_auto_init_mono_speaker_out(codec);
10471         alc268_auto_init_analog_input(codec);
10472         if (spec->unsol_event)
10473                 alc_sku_automute(codec);
10474 }
10475
10476 /*
10477  * configuration and preset
10478  */
10479 static const char *alc268_models[ALC268_MODEL_LAST] = {
10480         [ALC267_QUANTA_IL1]     = "quanta-il1",
10481         [ALC268_3ST]            = "3stack",
10482         [ALC268_TOSHIBA]        = "toshiba",
10483         [ALC268_ACER]           = "acer",
10484         [ALC268_DELL]           = "dell",
10485         [ALC268_ZEPTO]          = "zepto",
10486 #ifdef CONFIG_SND_DEBUG
10487         [ALC268_TEST]           = "test",
10488 #endif
10489         [ALC268_AUTO]           = "auto",
10490 };
10491
10492 static struct snd_pci_quirk alc268_cfg_tbl[] = {
10493         SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
10494         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
10495         SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
10496         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
10497         SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER),
10498         SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
10499         SND_PCI_QUIRK(0x103c, 0x30cc, "TOSHIBA", ALC268_TOSHIBA),
10500         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
10501         SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA),
10502         SND_PCI_QUIRK(0x1179, 0xff50, "TOSHIBA A305", ALC268_TOSHIBA),
10503         SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
10504         SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
10505         SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
10506         {}
10507 };
10508
10509 static struct alc_config_preset alc268_presets[] = {
10510         [ALC267_QUANTA_IL1] = {
10511                 .mixers = { alc267_quanta_il1_mixer },
10512                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10513                                 alc267_quanta_il1_verbs },
10514                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10515                 .dac_nids = alc268_dac_nids,
10516                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10517                 .adc_nids = alc268_adc_nids_alt,
10518                 .hp_nid = 0x03,
10519                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10520                 .channel_mode = alc268_modes,
10521                 .input_mux = &alc268_capture_source,
10522                 .unsol_event = alc267_quanta_il1_unsol_event,
10523                 .init_hook = alc267_quanta_il1_automute,
10524         },
10525         [ALC268_3ST] = {
10526                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
10527                             alc268_beep_mixer },
10528                 .init_verbs = { alc268_base_init_verbs },
10529                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10530                 .dac_nids = alc268_dac_nids,
10531                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10532                 .adc_nids = alc268_adc_nids_alt,
10533                 .capsrc_nids = alc268_capsrc_nids,
10534                 .hp_nid = 0x03,
10535                 .dig_out_nid = ALC268_DIGOUT_NID,
10536                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10537                 .channel_mode = alc268_modes,
10538                 .input_mux = &alc268_capture_source,
10539         },
10540         [ALC268_TOSHIBA] = {
10541                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
10542                             alc268_beep_mixer },
10543                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10544                                 alc268_toshiba_verbs },
10545                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10546                 .dac_nids = alc268_dac_nids,
10547                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10548                 .adc_nids = alc268_adc_nids_alt,
10549                 .capsrc_nids = alc268_capsrc_nids,
10550                 .hp_nid = 0x03,
10551                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10552                 .channel_mode = alc268_modes,
10553                 .input_mux = &alc268_capture_source,
10554                 .unsol_event = alc268_toshiba_unsol_event,
10555                 .init_hook = alc268_toshiba_automute,
10556         },
10557         [ALC268_ACER] = {
10558                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
10559                             alc268_beep_mixer },
10560                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10561                                 alc268_acer_verbs },
10562                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10563                 .dac_nids = alc268_dac_nids,
10564                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10565                 .adc_nids = alc268_adc_nids_alt,
10566                 .capsrc_nids = alc268_capsrc_nids,
10567                 .hp_nid = 0x02,
10568                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10569                 .channel_mode = alc268_modes,
10570                 .input_mux = &alc268_acer_capture_source,
10571                 .unsol_event = alc268_acer_unsol_event,
10572                 .init_hook = alc268_acer_init_hook,
10573         },
10574         [ALC268_DELL] = {
10575                 .mixers = { alc268_dell_mixer, alc268_beep_mixer },
10576                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10577                                 alc268_dell_verbs },
10578                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10579                 .dac_nids = alc268_dac_nids,
10580                 .hp_nid = 0x02,
10581                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10582                 .channel_mode = alc268_modes,
10583                 .unsol_event = alc268_dell_unsol_event,
10584                 .init_hook = alc268_dell_init_hook,
10585                 .input_mux = &alc268_capture_source,
10586         },
10587         [ALC268_ZEPTO] = {
10588                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
10589                             alc268_beep_mixer },
10590                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10591                                 alc268_toshiba_verbs },
10592                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10593                 .dac_nids = alc268_dac_nids,
10594                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10595                 .adc_nids = alc268_adc_nids_alt,
10596                 .capsrc_nids = alc268_capsrc_nids,
10597                 .hp_nid = 0x03,
10598                 .dig_out_nid = ALC268_DIGOUT_NID,
10599                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10600                 .channel_mode = alc268_modes,
10601                 .input_mux = &alc268_capture_source,
10602                 .unsol_event = alc268_toshiba_unsol_event,
10603                 .init_hook = alc268_toshiba_automute
10604         },
10605 #ifdef CONFIG_SND_DEBUG
10606         [ALC268_TEST] = {
10607                 .mixers = { alc268_test_mixer, alc268_capture_mixer },
10608                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10609                                 alc268_volume_init_verbs },
10610                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10611                 .dac_nids = alc268_dac_nids,
10612                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10613                 .adc_nids = alc268_adc_nids_alt,
10614                 .capsrc_nids = alc268_capsrc_nids,
10615                 .hp_nid = 0x03,
10616                 .dig_out_nid = ALC268_DIGOUT_NID,
10617                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10618                 .channel_mode = alc268_modes,
10619                 .input_mux = &alc268_capture_source,
10620         },
10621 #endif
10622 };
10623
10624 static int patch_alc268(struct hda_codec *codec)
10625 {
10626         struct alc_spec *spec;
10627         int board_config;
10628         int err;
10629
10630         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
10631         if (spec == NULL)
10632                 return -ENOMEM;
10633
10634         codec->spec = spec;
10635
10636         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
10637                                                   alc268_models,
10638                                                   alc268_cfg_tbl);
10639
10640         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
10641                 printk(KERN_INFO "hda_codec: Unknown model for ALC268, "
10642                        "trying auto-probe from BIOS...\n");
10643                 board_config = ALC268_AUTO;
10644         }
10645
10646         if (board_config == ALC268_AUTO) {
10647                 /* automatic parse from the BIOS config */
10648                 err = alc268_parse_auto_config(codec);
10649                 if (err < 0) {
10650                         alc_free(codec);
10651                         return err;
10652                 } else if (!err) {
10653                         printk(KERN_INFO
10654                                "hda_codec: Cannot set up configuration "
10655                                "from BIOS.  Using base mode...\n");
10656                         board_config = ALC268_3ST;
10657                 }
10658         }
10659
10660         if (board_config != ALC268_AUTO)
10661                 setup_preset(spec, &alc268_presets[board_config]);
10662
10663         spec->stream_name_analog = "ALC268 Analog";
10664         spec->stream_analog_playback = &alc268_pcm_analog_playback;
10665         spec->stream_analog_capture = &alc268_pcm_analog_capture;
10666         spec->stream_analog_alt_capture = &alc268_pcm_analog_alt_capture;
10667
10668         spec->stream_name_digital = "ALC268 Digital";
10669         spec->stream_digital_playback = &alc268_pcm_digital_playback;
10670
10671         if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
10672                 /* override the amp caps for beep generator */
10673                 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
10674                                           (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
10675                                           (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
10676                                           (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
10677                                           (0 << AC_AMPCAP_MUTE_SHIFT));
10678
10679         if (!spec->adc_nids && spec->input_mux) {
10680                 /* check whether NID 0x07 is valid */
10681                 unsigned int wcap = get_wcaps(codec, 0x07);
10682                 int i;
10683
10684                 /* get type */
10685                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
10686                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
10687                         spec->adc_nids = alc268_adc_nids_alt;
10688                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
10689                         spec->mixers[spec->num_mixers] =
10690                                         alc268_capture_alt_mixer;
10691                         spec->num_mixers++;
10692                 } else {
10693                         spec->adc_nids = alc268_adc_nids;
10694                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
10695                         spec->mixers[spec->num_mixers] =
10696                                 alc268_capture_mixer;
10697                         spec->num_mixers++;
10698                 }
10699                 spec->capsrc_nids = alc268_capsrc_nids;
10700                 /* set default input source */
10701                 for (i = 0; i < spec->num_adc_nids; i++)
10702                         snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
10703                                 0, AC_VERB_SET_CONNECT_SEL,
10704                                 spec->input_mux->items[0].index);
10705         }
10706
10707         spec->vmaster_nid = 0x02;
10708
10709         codec->patch_ops = alc_patch_ops;
10710         if (board_config == ALC268_AUTO)
10711                 spec->init_hook = alc268_auto_init;
10712                 
10713         return 0;
10714 }
10715
10716 /*
10717  *  ALC269 channel source setting (2 channel)
10718  */
10719 #define ALC269_DIGOUT_NID       ALC880_DIGOUT_NID
10720
10721 #define alc269_dac_nids         alc260_dac_nids
10722
10723 static hda_nid_t alc269_adc_nids[1] = {
10724         /* ADC1 */
10725         0x07,
10726 };
10727
10728 #define alc269_modes            alc260_modes
10729 #define alc269_capture_source   alc880_lg_lw_capture_source
10730
10731 static struct snd_kcontrol_new alc269_base_mixer[] = {
10732         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10733         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10734         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10735         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10736         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10737         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10738         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10739         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10740         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10741         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10742         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10743         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
10744         { } /* end */
10745 };
10746
10747 /* capture mixer elements */
10748 static struct snd_kcontrol_new alc269_capture_mixer[] = {
10749         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
10750         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
10751         {
10752                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10753                 /* The multiple "Capture Source" controls confuse alsamixer
10754                  * So call somewhat different..
10755                  */
10756                 /* .name = "Capture Source", */
10757                 .name = "Input Source",
10758                 .count = 1,
10759                 .info = alc_mux_enum_info,
10760                 .get = alc_mux_enum_get,
10761                 .put = alc_mux_enum_put,
10762         },
10763         { } /* end */
10764 };
10765
10766 /*
10767  * generic initialization of ADC, input mixers and output mixers
10768  */
10769 static struct hda_verb alc269_init_verbs[] = {
10770         /*
10771          * Unmute ADC0 and set the default input to mic-in
10772          */
10773         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10774
10775         /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the
10776          * analog-loopback mixer widget
10777          * Note: PASD motherboards uses the Line In 2 as the input for
10778          * front panel mic (mic 2)
10779          */
10780         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10781         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10782         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10783         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10784         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10785         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10786
10787         /*
10788          * Set up output mixers (0x0c - 0x0e)
10789          */
10790         /* set vol=0 to output mixers */
10791         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10792         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10793
10794         /* set up input amps for analog loopback */
10795         /* Amp Indices: DAC = 0, mixer = 1 */
10796         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10797         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10798         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10799         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10800         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10801         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10802
10803         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10804         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10805         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10806         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10807         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10808         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10809         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10810
10811         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10812         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10813         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10814         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10815         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10816         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10817         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10818
10819         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
10820         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10821
10822         /* FIXME: use matrix-type input source selection */
10823         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
10824         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10825         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10826         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10827         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10828         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10829
10830         /* set EAPD */
10831         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
10832         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
10833         { }
10834 };
10835
10836 /* add playback controls from the parsed DAC table */
10837 static int alc269_auto_create_multi_out_ctls(struct alc_spec *spec,
10838                                              const struct auto_pin_cfg *cfg)
10839 {
10840         hda_nid_t nid;
10841         int err;
10842
10843         spec->multiout.num_dacs = 1;    /* only use one dac */
10844         spec->multiout.dac_nids = spec->private_dac_nids;
10845         spec->multiout.dac_nids[0] = 2;
10846
10847         nid = cfg->line_out_pins[0];
10848         if (nid) {
10849                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
10850                                   "Front Playback Volume",
10851                                   HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT));
10852                 if (err < 0)
10853                         return err;
10854                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10855                                   "Front Playback Switch",
10856                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
10857                 if (err < 0)
10858                         return err;
10859         }
10860
10861         nid = cfg->speaker_pins[0];
10862         if (nid) {
10863                 if (!cfg->line_out_pins[0]) {
10864                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10865                                           "Speaker Playback Volume",
10866                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
10867                                                               HDA_OUTPUT));
10868                         if (err < 0)
10869                                 return err;
10870                 }
10871                 if (nid == 0x16) {
10872                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10873                                           "Speaker Playback Switch",
10874                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10875                                                               HDA_OUTPUT));
10876                         if (err < 0)
10877                                 return err;
10878                 } else {
10879                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10880                                           "Speaker Playback Switch",
10881                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10882                                                               HDA_OUTPUT));
10883                         if (err < 0)
10884                                 return err;
10885                 }
10886         }
10887         nid = cfg->hp_pins[0];
10888         if (nid) {
10889                 /* spec->multiout.hp_nid = 2; */
10890                 if (!cfg->line_out_pins[0] && !cfg->speaker_pins[0]) {
10891                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10892                                           "Headphone Playback Volume",
10893                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
10894                                                               HDA_OUTPUT));
10895                         if (err < 0)
10896                                 return err;
10897                 }
10898                 if (nid == 0x16) {
10899                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10900                                           "Headphone Playback Switch",
10901                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10902                                                               HDA_OUTPUT));
10903                         if (err < 0)
10904                                 return err;
10905                 } else {
10906                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10907                                           "Headphone Playback Switch",
10908                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10909                                                               HDA_OUTPUT));
10910                         if (err < 0)
10911                                 return err;
10912                 }
10913         }
10914         return 0;
10915 }
10916
10917 #define alc269_auto_create_analog_input_ctls \
10918         alc880_auto_create_analog_input_ctls
10919
10920 #ifdef CONFIG_SND_HDA_POWER_SAVE
10921 #define alc269_loopbacks        alc880_loopbacks
10922 #endif
10923
10924 /* pcm configuration: identiacal with ALC880 */
10925 #define alc269_pcm_analog_playback      alc880_pcm_analog_playback
10926 #define alc269_pcm_analog_capture       alc880_pcm_analog_capture
10927 #define alc269_pcm_digital_playback     alc880_pcm_digital_playback
10928 #define alc269_pcm_digital_capture      alc880_pcm_digital_capture
10929
10930 /*
10931  * BIOS auto configuration
10932  */
10933 static int alc269_parse_auto_config(struct hda_codec *codec)
10934 {
10935         struct alc_spec *spec = codec->spec;
10936         int err;
10937         static hda_nid_t alc269_ignore[] = { 0x1d, 0 };
10938
10939         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
10940                                            alc269_ignore);
10941         if (err < 0)
10942                 return err;
10943
10944         err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
10945         if (err < 0)
10946                 return err;
10947         err = alc269_auto_create_analog_input_ctls(spec, &spec->autocfg);
10948         if (err < 0)
10949                 return err;
10950
10951         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
10952
10953         if (spec->autocfg.dig_out_pin)
10954                 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;
10955
10956         if (spec->kctl_alloc)
10957                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
10958
10959         spec->init_verbs[spec->num_init_verbs++] = alc269_init_verbs;
10960         spec->num_mux_defs = 1;
10961         spec->input_mux = &spec->private_imux;
10962
10963         err = alc_auto_add_mic_boost(codec);
10964         if (err < 0)
10965                 return err;
10966
10967         return 1;
10968 }
10969
10970 #define alc269_auto_init_multi_out      alc882_auto_init_multi_out
10971 #define alc269_auto_init_hp_out         alc882_auto_init_hp_out
10972 #define alc269_auto_init_analog_input   alc882_auto_init_analog_input
10973
10974
10975 /* init callback for auto-configuration model -- overriding the default init */
10976 static void alc269_auto_init(struct hda_codec *codec)
10977 {
10978         struct alc_spec *spec = codec->spec;
10979         alc269_auto_init_multi_out(codec);
10980         alc269_auto_init_hp_out(codec);
10981         alc269_auto_init_analog_input(codec);
10982         if (spec->unsol_event)
10983                 alc_sku_automute(codec);
10984 }
10985
10986 /*
10987  * configuration and preset
10988  */
10989 static const char *alc269_models[ALC269_MODEL_LAST] = {
10990         [ALC269_BASIC]          = "basic",
10991 };
10992
10993 static struct snd_pci_quirk alc269_cfg_tbl[] = {
10994         {}
10995 };
10996
10997 static struct alc_config_preset alc269_presets[] = {
10998         [ALC269_BASIC] = {
10999                 .mixers = { alc269_base_mixer },
11000                 .init_verbs = { alc269_init_verbs },
11001                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
11002                 .dac_nids = alc269_dac_nids,
11003                 .hp_nid = 0x03,
11004                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
11005                 .channel_mode = alc269_modes,
11006                 .input_mux = &alc269_capture_source,
11007         },
11008 };
11009
11010 static int patch_alc269(struct hda_codec *codec)
11011 {
11012         struct alc_spec *spec;
11013         int board_config;
11014         int err;
11015
11016         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
11017         if (spec == NULL)
11018                 return -ENOMEM;
11019
11020         codec->spec = spec;
11021
11022         board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
11023                                                   alc269_models,
11024                                                   alc269_cfg_tbl);
11025
11026         if (board_config < 0) {
11027                 printk(KERN_INFO "hda_codec: Unknown model for ALC269, "
11028                        "trying auto-probe from BIOS...\n");
11029                 board_config = ALC269_AUTO;
11030         }
11031
11032         if (board_config == ALC269_AUTO) {
11033                 /* automatic parse from the BIOS config */
11034                 err = alc269_parse_auto_config(codec);
11035                 if (err < 0) {
11036                         alc_free(codec);
11037                         return err;
11038                 } else if (!err) {
11039                         printk(KERN_INFO
11040                                "hda_codec: Cannot set up configuration "
11041                                "from BIOS.  Using base mode...\n");
11042                         board_config = ALC269_BASIC;
11043                 }
11044         }
11045
11046         if (board_config != ALC269_AUTO)
11047                 setup_preset(spec, &alc269_presets[board_config]);
11048
11049         spec->stream_name_analog = "ALC269 Analog";
11050         spec->stream_analog_playback = &alc269_pcm_analog_playback;
11051         spec->stream_analog_capture = &alc269_pcm_analog_capture;
11052
11053         spec->stream_name_digital = "ALC269 Digital";
11054         spec->stream_digital_playback = &alc269_pcm_digital_playback;
11055         spec->stream_digital_capture = &alc269_pcm_digital_capture;
11056
11057         spec->adc_nids = alc269_adc_nids;
11058         spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
11059         spec->mixers[spec->num_mixers] = alc269_capture_mixer;
11060         spec->num_mixers++;
11061
11062         codec->patch_ops = alc_patch_ops;
11063         if (board_config == ALC269_AUTO)
11064                 spec->init_hook = alc269_auto_init;
11065 #ifdef CONFIG_SND_HDA_POWER_SAVE
11066         if (!spec->loopback.amplist)
11067                 spec->loopback.amplist = alc269_loopbacks;
11068 #endif
11069
11070         return 0;
11071 }
11072
11073 /*
11074  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
11075  */
11076
11077 /*
11078  * set the path ways for 2 channel output
11079  * need to set the codec line out and mic 1 pin widgets to inputs
11080  */
11081 static struct hda_verb alc861_threestack_ch2_init[] = {
11082         /* set pin widget 1Ah (line in) for input */
11083         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11084         /* set pin widget 18h (mic1/2) for input, for mic also enable
11085          * the vref
11086          */
11087         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11088
11089         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
11090 #if 0
11091         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
11092         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
11093 #endif
11094         { } /* end */
11095 };
11096 /*
11097  * 6ch mode
11098  * need to set the codec line out and mic 1 pin widgets to outputs
11099  */
11100 static struct hda_verb alc861_threestack_ch6_init[] = {
11101         /* set pin widget 1Ah (line in) for output (Back Surround)*/
11102         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11103         /* set pin widget 18h (mic1) for output (CLFE)*/
11104         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11105
11106         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
11107         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
11108
11109         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
11110 #if 0
11111         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
11112         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
11113 #endif
11114         { } /* end */
11115 };
11116
11117 static struct hda_channel_mode alc861_threestack_modes[2] = {
11118         { 2, alc861_threestack_ch2_init },
11119         { 6, alc861_threestack_ch6_init },
11120 };
11121 /* Set mic1 as input and unmute the mixer */
11122 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
11123         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11124         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
11125         { } /* end */
11126 };
11127 /* Set mic1 as output and mute mixer */
11128 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
11129         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11130         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
11131         { } /* end */
11132 };
11133
11134 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
11135         { 2, alc861_uniwill_m31_ch2_init },
11136         { 4, alc861_uniwill_m31_ch4_init },
11137 };
11138
11139 /* Set mic1 and line-in as input and unmute the mixer */
11140 static struct hda_verb alc861_asus_ch2_init[] = {
11141         /* set pin widget 1Ah (line in) for input */
11142         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11143         /* set pin widget 18h (mic1/2) for input, for mic also enable
11144          * the vref
11145          */
11146         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11147
11148         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
11149 #if 0
11150         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
11151         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
11152 #endif
11153         { } /* end */
11154 };
11155 /* Set mic1 nad line-in as output and mute mixer */
11156 static struct hda_verb alc861_asus_ch6_init[] = {
11157         /* set pin widget 1Ah (line in) for output (Back Surround)*/
11158         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11159         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
11160         /* set pin widget 18h (mic1) for output (CLFE)*/
11161         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11162         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
11163         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
11164         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
11165
11166         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
11167 #if 0
11168         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
11169         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
11170 #endif
11171         { } /* end */
11172 };
11173
11174 static struct hda_channel_mode alc861_asus_modes[2] = {
11175         { 2, alc861_asus_ch2_init },
11176         { 6, alc861_asus_ch6_init },
11177 };
11178
11179 /* patch-ALC861 */
11180
11181 static struct snd_kcontrol_new alc861_base_mixer[] = {
11182         /* output mixer control */
11183         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11184         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
11185         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
11186         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
11187         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
11188
11189         /*Input mixer control */
11190         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
11191            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
11192         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11193         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11194         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
11195         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
11196         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11197         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11198         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
11199         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
11200
11201         /* Capture mixer control */
11202         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11203         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11204         {
11205                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11206                 .name = "Capture Source",
11207                 .count = 1,
11208                 .info = alc_mux_enum_info,
11209                 .get = alc_mux_enum_get,
11210                 .put = alc_mux_enum_put,
11211         },
11212         { } /* end */
11213 };
11214
11215 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
11216         /* output mixer control */
11217         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11218         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
11219         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
11220         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
11221         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
11222
11223         /* Input mixer control */
11224         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
11225            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
11226         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11227         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11228         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
11229         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
11230         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11231         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11232         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
11233         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
11234
11235         /* Capture mixer control */
11236         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11237         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11238         {
11239                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11240                 .name = "Capture Source",
11241                 .count = 1,
11242                 .info = alc_mux_enum_info,
11243                 .get = alc_mux_enum_get,
11244                 .put = alc_mux_enum_put,
11245         },
11246         {
11247                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11248                 .name = "Channel Mode",
11249                 .info = alc_ch_mode_info,
11250                 .get = alc_ch_mode_get,
11251                 .put = alc_ch_mode_put,
11252                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
11253         },
11254         { } /* end */
11255 };
11256
11257 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
11258         /* output mixer control */
11259         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11260         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11261         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11262         
11263         /*Capture mixer control */
11264         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11265         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11266         {
11267                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11268                 .name = "Capture Source",
11269                 .count = 1,
11270                 .info = alc_mux_enum_info,
11271                 .get = alc_mux_enum_get,
11272                 .put = alc_mux_enum_put,
11273         },
11274
11275         { } /* end */
11276 };
11277
11278 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
11279         /* output mixer control */
11280         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11281         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
11282         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
11283         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
11284         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
11285
11286         /* Input mixer control */
11287         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
11288            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
11289         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11290         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11291         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
11292         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
11293         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11294         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11295         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
11296         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
11297
11298         /* Capture mixer control */
11299         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11300         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11301         {
11302                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11303                 .name = "Capture Source",
11304                 .count = 1,
11305                 .info = alc_mux_enum_info,
11306                 .get = alc_mux_enum_get,
11307                 .put = alc_mux_enum_put,
11308         },
11309         {
11310                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11311                 .name = "Channel Mode",
11312                 .info = alc_ch_mode_info,
11313                 .get = alc_ch_mode_get,
11314                 .put = alc_ch_mode_put,
11315                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
11316         },
11317         { } /* end */
11318 };
11319
11320 static struct snd_kcontrol_new alc861_asus_mixer[] = {
11321         /* output mixer control */
11322         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11323         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
11324         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
11325         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
11326         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
11327
11328         /* Input mixer control */
11329         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
11330         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11331         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11332         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11333         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
11334         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
11335         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11336         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11337         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
11338         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
11339
11340         /* Capture mixer control */
11341         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11342         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11343         {
11344                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11345                 .name = "Capture Source",
11346                 .count = 1,
11347                 .info = alc_mux_enum_info,
11348                 .get = alc_mux_enum_get,
11349                 .put = alc_mux_enum_put,
11350         },
11351         {
11352                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11353                 .name = "Channel Mode",
11354                 .info = alc_ch_mode_info,
11355                 .get = alc_ch_mode_get,
11356                 .put = alc_ch_mode_put,
11357                 .private_value = ARRAY_SIZE(alc861_asus_modes),
11358         },
11359         { }
11360 };
11361
11362 /* additional mixer */
11363 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
11364         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11365         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11366         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x23, 0x0, HDA_OUTPUT),
11367         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x23, 0x0, HDA_OUTPUT),
11368         { }
11369 };
11370
11371 /*
11372  * generic initialization of ADC, input mixers and output mixers
11373  */
11374 static struct hda_verb alc861_base_init_verbs[] = {
11375         /*
11376          * Unmute ADC0 and set the default input to mic-in
11377          */
11378         /* port-A for surround (rear panel) */
11379         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11380         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
11381         /* port-B for mic-in (rear panel) with vref */
11382         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11383         /* port-C for line-in (rear panel) */
11384         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11385         /* port-D for Front */
11386         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11387         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
11388         /* port-E for HP out (front panel) */
11389         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
11390         /* route front PCM to HP */
11391         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
11392         /* port-F for mic-in (front panel) with vref */
11393         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11394         /* port-G for CLFE (rear panel) */
11395         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11396         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
11397         /* port-H for side (rear panel) */
11398         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11399         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
11400         /* CD-in */
11401         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11402         /* route front mic to ADC1*/
11403         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11404         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11405         
11406         /* Unmute DAC0~3 & spdif out*/
11407         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11408         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11409         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11410         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11411         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11412         
11413         /* Unmute Mixer 14 (mic) 1c (Line in)*/
11414         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11415         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11416         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11417         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11418         
11419         /* Unmute Stereo Mixer 15 */
11420         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11421         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11422         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11423         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
11424
11425         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11426         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11427         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11428         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11429         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11430         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11431         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11432         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11433         /* hp used DAC 3 (Front) */
11434         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
11435         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11436
11437         { }
11438 };
11439
11440 static struct hda_verb alc861_threestack_init_verbs[] = {
11441         /*
11442          * Unmute ADC0 and set the default input to mic-in
11443          */
11444         /* port-A for surround (rear panel) */
11445         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11446         /* port-B for mic-in (rear panel) with vref */
11447         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11448         /* port-C for line-in (rear panel) */
11449         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11450         /* port-D for Front */
11451         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11452         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
11453         /* port-E for HP out (front panel) */
11454         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
11455         /* route front PCM to HP */
11456         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
11457         /* port-F for mic-in (front panel) with vref */
11458         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11459         /* port-G for CLFE (rear panel) */
11460         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11461         /* port-H for side (rear panel) */
11462         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11463         /* CD-in */
11464         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11465         /* route front mic to ADC1*/
11466         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11467         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11468         /* Unmute DAC0~3 & spdif out*/
11469         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11470         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11471         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11472         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11473         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11474         
11475         /* Unmute Mixer 14 (mic) 1c (Line in)*/
11476         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11477         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11478         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11479         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11480         
11481         /* Unmute Stereo Mixer 15 */
11482         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11483         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11484         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11485         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
11486
11487         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11488         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11489         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11490         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11491         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11492         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11493         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11494         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11495         /* hp used DAC 3 (Front) */
11496         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
11497         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11498         { }
11499 };
11500
11501 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
11502         /*
11503          * Unmute ADC0 and set the default input to mic-in
11504          */
11505         /* port-A for surround (rear panel) */
11506         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11507         /* port-B for mic-in (rear panel) with vref */
11508         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11509         /* port-C for line-in (rear panel) */
11510         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11511         /* port-D for Front */
11512         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11513         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
11514         /* port-E for HP out (front panel) */
11515         /* this has to be set to VREF80 */
11516         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11517         /* route front PCM to HP */
11518         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
11519         /* port-F for mic-in (front panel) with vref */
11520         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11521         /* port-G for CLFE (rear panel) */
11522         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11523         /* port-H for side (rear panel) */
11524         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11525         /* CD-in */
11526         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11527         /* route front mic to ADC1*/
11528         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11529         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11530         /* Unmute DAC0~3 & spdif out*/
11531         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11532         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11533         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11534         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11535         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11536         
11537         /* Unmute Mixer 14 (mic) 1c (Line in)*/
11538         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11539         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11540         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11541         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11542         
11543         /* Unmute Stereo Mixer 15 */
11544         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11545         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11546         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11547         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
11548
11549         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11550         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11551         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11552         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11553         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11554         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11555         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11556         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11557         /* hp used DAC 3 (Front) */
11558         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
11559         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11560         { }
11561 };
11562
11563 static struct hda_verb alc861_asus_init_verbs[] = {
11564         /*
11565          * Unmute ADC0 and set the default input to mic-in
11566          */
11567         /* port-A for surround (rear panel)
11568          * according to codec#0 this is the HP jack
11569          */
11570         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
11571         /* route front PCM to HP */
11572         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
11573         /* port-B for mic-in (rear panel) with vref */
11574         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11575         /* port-C for line-in (rear panel) */
11576         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11577         /* port-D for Front */
11578         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11579         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
11580         /* port-E for HP out (front panel) */
11581         /* this has to be set to VREF80 */
11582         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11583         /* route front PCM to HP */
11584         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
11585         /* port-F for mic-in (front panel) with vref */
11586         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11587         /* port-G for CLFE (rear panel) */
11588         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11589         /* port-H for side (rear panel) */
11590         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11591         /* CD-in */
11592         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11593         /* route front mic to ADC1*/
11594         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11595         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11596         /* Unmute DAC0~3 & spdif out*/
11597         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11598         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11599         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11600         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11601         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11602         /* Unmute Mixer 14 (mic) 1c (Line in)*/
11603         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11604         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11605         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11606         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11607         
11608         /* Unmute Stereo Mixer 15 */
11609         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11610         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11611         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11612         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
11613
11614         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11615         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11616         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11617         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11618         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11619         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11620         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11621         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11622         /* hp used DAC 3 (Front) */
11623         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
11624         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11625         { }
11626 };
11627
11628 /* additional init verbs for ASUS laptops */
11629 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
11630         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
11631         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
11632         { }
11633 };
11634
11635 /*
11636  * generic initialization of ADC, input mixers and output mixers
11637  */
11638 static struct hda_verb alc861_auto_init_verbs[] = {
11639         /*
11640          * Unmute ADC0 and set the default input to mic-in
11641          */
11642         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
11643         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11644         
11645         /* Unmute DAC0~3 & spdif out*/
11646         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11647         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11648         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11649         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11650         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11651         
11652         /* Unmute Mixer 14 (mic) 1c (Line in)*/
11653         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11654         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11655         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11656         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11657         
11658         /* Unmute Stereo Mixer 15 */
11659         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11660         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11661         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11662         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
11663
11664         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11665         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11666         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11667         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11668         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11669         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11670         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11671         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11672
11673         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11674         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11675         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11676         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
11677         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11678         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11679         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11680         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
11681
11682         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
11683
11684         { }
11685 };
11686
11687 static struct hda_verb alc861_toshiba_init_verbs[] = {
11688         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11689
11690         { }
11691 };
11692
11693 /* toggle speaker-output according to the hp-jack state */
11694 static void alc861_toshiba_automute(struct hda_codec *codec)
11695 {
11696         unsigned int present;
11697
11698         present = snd_hda_codec_read(codec, 0x0f, 0,
11699                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11700         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
11701                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
11702         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
11703                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
11704 }
11705
11706 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
11707                                        unsigned int res)
11708 {
11709         if ((res >> 26) == ALC880_HP_EVENT)
11710                 alc861_toshiba_automute(codec);
11711 }
11712
11713 /* pcm configuration: identiacal with ALC880 */
11714 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
11715 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
11716 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
11717 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
11718
11719
11720 #define ALC861_DIGOUT_NID       0x07
11721
11722 static struct hda_channel_mode alc861_8ch_modes[1] = {
11723         { 8, NULL }
11724 };
11725
11726 static hda_nid_t alc861_dac_nids[4] = {
11727         /* front, surround, clfe, side */
11728         0x03, 0x06, 0x05, 0x04
11729 };
11730
11731 static hda_nid_t alc660_dac_nids[3] = {
11732         /* front, clfe, surround */
11733         0x03, 0x05, 0x06
11734 };
11735
11736 static hda_nid_t alc861_adc_nids[1] = {
11737         /* ADC0-2 */
11738         0x08,
11739 };
11740
11741 static struct hda_input_mux alc861_capture_source = {
11742         .num_items = 5,
11743         .items = {
11744                 { "Mic", 0x0 },
11745                 { "Front Mic", 0x3 },
11746                 { "Line", 0x1 },
11747                 { "CD", 0x4 },
11748                 { "Mixer", 0x5 },
11749         },
11750 };
11751
11752 /* fill in the dac_nids table from the parsed pin configuration */
11753 static int alc861_auto_fill_dac_nids(struct alc_spec *spec,
11754                                      const struct auto_pin_cfg *cfg)
11755 {
11756         int i;
11757         hda_nid_t nid;
11758
11759         spec->multiout.dac_nids = spec->private_dac_nids;
11760         for (i = 0; i < cfg->line_outs; i++) {
11761                 nid = cfg->line_out_pins[i];
11762                 if (nid) {
11763                         if (i >= ARRAY_SIZE(alc861_dac_nids))
11764                                 continue;
11765                         spec->multiout.dac_nids[i] = alc861_dac_nids[i];
11766                 }
11767         }
11768         spec->multiout.num_dacs = cfg->line_outs;
11769         return 0;
11770 }
11771
11772 /* add playback controls from the parsed DAC table */
11773 static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
11774                                              const struct auto_pin_cfg *cfg)
11775 {
11776         char name[32];
11777         static const char *chname[4] = {
11778                 "Front", "Surround", NULL /*CLFE*/, "Side"
11779         };
11780         hda_nid_t nid;
11781         int i, idx, err;
11782
11783         for (i = 0; i < cfg->line_outs; i++) {
11784                 nid = spec->multiout.dac_nids[i];
11785                 if (!nid)
11786                         continue;
11787                 if (nid == 0x05) {
11788                         /* Center/LFE */
11789                         err = add_control(spec, ALC_CTL_BIND_MUTE,
11790                                           "Center Playback Switch",
11791                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
11792                                                               HDA_OUTPUT));
11793                         if (err < 0)
11794                                 return err;
11795                         err = add_control(spec, ALC_CTL_BIND_MUTE,
11796                                           "LFE Playback Switch",
11797                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
11798                                                               HDA_OUTPUT));
11799                         if (err < 0)
11800                                 return err;
11801                 } else {
11802                         for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1;
11803                              idx++)
11804                                 if (nid == alc861_dac_nids[idx])
11805                                         break;
11806                         sprintf(name, "%s Playback Switch", chname[idx]);
11807                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
11808                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
11809                                                               HDA_OUTPUT));
11810                         if (err < 0)
11811                                 return err;
11812                 }
11813         }
11814         return 0;
11815 }
11816
11817 static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
11818 {
11819         int err;
11820         hda_nid_t nid;
11821
11822         if (!pin)
11823                 return 0;
11824
11825         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
11826                 nid = 0x03;
11827                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11828                                   "Headphone Playback Switch",
11829                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
11830                 if (err < 0)
11831                         return err;
11832                 spec->multiout.hp_nid = nid;
11833         }
11834         return 0;
11835 }
11836
11837 /* create playback/capture controls for input pins */
11838 static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec,
11839                                                 const struct auto_pin_cfg *cfg)
11840 {
11841         struct hda_input_mux *imux = &spec->private_imux;
11842         int i, err, idx, idx1;
11843
11844         for (i = 0; i < AUTO_PIN_LAST; i++) {
11845                 switch (cfg->input_pins[i]) {
11846                 case 0x0c:
11847                         idx1 = 1;
11848                         idx = 2;        /* Line In */
11849                         break;
11850                 case 0x0f:
11851                         idx1 = 2;
11852                         idx = 2;        /* Line In */
11853                         break;
11854                 case 0x0d:
11855                         idx1 = 0;
11856                         idx = 1;        /* Mic In */
11857                         break;
11858                 case 0x10:
11859                         idx1 = 3;
11860                         idx = 1;        /* Mic In */
11861                         break;
11862                 case 0x11:
11863                         idx1 = 4;
11864                         idx = 0;        /* CD */
11865                         break;
11866                 default:
11867                         continue;
11868                 }
11869
11870                 err = new_analog_input(spec, cfg->input_pins[i],
11871                                        auto_pin_cfg_labels[i], idx, 0x15);
11872                 if (err < 0)
11873                         return err;
11874
11875                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
11876                 imux->items[imux->num_items].index = idx1;
11877                 imux->num_items++;
11878         }
11879         return 0;
11880 }
11881
11882 static struct snd_kcontrol_new alc861_capture_mixer[] = {
11883         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11884         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11885
11886         {
11887                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11888                 /* The multiple "Capture Source" controls confuse alsamixer
11889                  * So call somewhat different..
11890                  */
11891                 /* .name = "Capture Source", */
11892                 .name = "Input Source",
11893                 .count = 1,
11894                 .info = alc_mux_enum_info,
11895                 .get = alc_mux_enum_get,
11896                 .put = alc_mux_enum_put,
11897         },
11898         { } /* end */
11899 };
11900
11901 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
11902                                               hda_nid_t nid,
11903                                               int pin_type, int dac_idx)
11904 {
11905         alc_set_pin_output(codec, nid, pin_type);
11906 }
11907
11908 static void alc861_auto_init_multi_out(struct hda_codec *codec)
11909 {
11910         struct alc_spec *spec = codec->spec;
11911         int i;
11912
11913         alc_subsystem_id(codec, 0x0e, 0x0f, 0x0b);
11914         for (i = 0; i < spec->autocfg.line_outs; i++) {
11915                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
11916                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
11917                 if (nid)
11918                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
11919                                                           spec->multiout.dac_nids[i]);
11920         }
11921 }
11922
11923 static void alc861_auto_init_hp_out(struct hda_codec *codec)
11924 {
11925         struct alc_spec *spec = codec->spec;
11926         hda_nid_t pin;
11927
11928         pin = spec->autocfg.hp_pins[0];
11929         if (pin) /* connect to front */
11930                 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
11931                                                   spec->multiout.dac_nids[0]);
11932         pin = spec->autocfg.speaker_pins[0];
11933         if (pin)
11934                 alc861_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
11935 }
11936
11937 static void alc861_auto_init_analog_input(struct hda_codec *codec)
11938 {
11939         struct alc_spec *spec = codec->spec;
11940         int i;
11941
11942         for (i = 0; i < AUTO_PIN_LAST; i++) {
11943                 hda_nid_t nid = spec->autocfg.input_pins[i];
11944                 if (nid >= 0x0c && nid <= 0x11) {
11945                         snd_hda_codec_write(codec, nid, 0,
11946                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
11947                                             i <= AUTO_PIN_FRONT_MIC ?
11948                                             PIN_VREF80 : PIN_IN);
11949                 }
11950         }
11951 }
11952
11953 /* parse the BIOS configuration and set up the alc_spec */
11954 /* return 1 if successful, 0 if the proper config is not found,
11955  * or a negative error code
11956  */
11957 static int alc861_parse_auto_config(struct hda_codec *codec)
11958 {
11959         struct alc_spec *spec = codec->spec;
11960         int err;
11961         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
11962
11963         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11964                                            alc861_ignore);
11965         if (err < 0)
11966                 return err;
11967         if (!spec->autocfg.line_outs)
11968                 return 0; /* can't find valid BIOS pin config */
11969
11970         err = alc861_auto_fill_dac_nids(spec, &spec->autocfg);
11971         if (err < 0)
11972                 return err;
11973         err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg);
11974         if (err < 0)
11975                 return err;
11976         err = alc861_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
11977         if (err < 0)
11978                 return err;
11979         err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg);
11980         if (err < 0)
11981                 return err;
11982
11983         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
11984
11985         if (spec->autocfg.dig_out_pin)
11986                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
11987
11988         if (spec->kctl_alloc)
11989                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
11990
11991         spec->init_verbs[spec->num_init_verbs++] = alc861_auto_init_verbs;
11992
11993         spec->num_mux_defs = 1;
11994         spec->input_mux = &spec->private_imux;
11995
11996         spec->adc_nids = alc861_adc_nids;
11997         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
11998         spec->mixers[spec->num_mixers] = alc861_capture_mixer;
11999         spec->num_mixers++;
12000
12001         return 1;
12002 }
12003
12004 /* additional initialization for auto-configuration model */
12005 static void alc861_auto_init(struct hda_codec *codec)
12006 {
12007         struct alc_spec *spec = codec->spec;
12008         alc861_auto_init_multi_out(codec);
12009         alc861_auto_init_hp_out(codec);
12010         alc861_auto_init_analog_input(codec);
12011         if (spec->unsol_event)
12012                 alc_sku_automute(codec);
12013 }
12014
12015 #ifdef CONFIG_SND_HDA_POWER_SAVE
12016 static struct hda_amp_list alc861_loopbacks[] = {
12017         { 0x15, HDA_INPUT, 0 },
12018         { 0x15, HDA_INPUT, 1 },
12019         { 0x15, HDA_INPUT, 2 },
12020         { 0x15, HDA_INPUT, 3 },
12021         { } /* end */
12022 };
12023 #endif
12024
12025
12026 /*
12027  * configuration and preset
12028  */
12029 static const char *alc861_models[ALC861_MODEL_LAST] = {
12030         [ALC861_3ST]            = "3stack",
12031         [ALC660_3ST]            = "3stack-660",
12032         [ALC861_3ST_DIG]        = "3stack-dig",
12033         [ALC861_6ST_DIG]        = "6stack-dig",
12034         [ALC861_UNIWILL_M31]    = "uniwill-m31",
12035         [ALC861_TOSHIBA]        = "toshiba",
12036         [ALC861_ASUS]           = "asus",
12037         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
12038         [ALC861_AUTO]           = "auto",
12039 };
12040
12041 static struct snd_pci_quirk alc861_cfg_tbl[] = {
12042         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
12043         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
12044         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
12045         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
12046         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
12047         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
12048         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
12049         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
12050          *        Any other models that need this preset?
12051          */
12052         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
12053         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
12054         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
12055         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
12056         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
12057         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
12058         /* FIXME: the below seems conflict */
12059         /* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
12060         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
12061         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
12062         {}
12063 };
12064
12065 static struct alc_config_preset alc861_presets[] = {
12066         [ALC861_3ST] = {
12067                 .mixers = { alc861_3ST_mixer },
12068                 .init_verbs = { alc861_threestack_init_verbs },
12069                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12070                 .dac_nids = alc861_dac_nids,
12071                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
12072                 .channel_mode = alc861_threestack_modes,
12073                 .need_dac_fix = 1,
12074                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12075                 .adc_nids = alc861_adc_nids,
12076                 .input_mux = &alc861_capture_source,
12077         },
12078         [ALC861_3ST_DIG] = {
12079                 .mixers = { alc861_base_mixer },
12080                 .init_verbs = { alc861_threestack_init_verbs },
12081                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12082                 .dac_nids = alc861_dac_nids,
12083                 .dig_out_nid = ALC861_DIGOUT_NID,
12084                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
12085                 .channel_mode = alc861_threestack_modes,
12086                 .need_dac_fix = 1,
12087                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12088                 .adc_nids = alc861_adc_nids,
12089                 .input_mux = &alc861_capture_source,
12090         },
12091         [ALC861_6ST_DIG] = {
12092                 .mixers = { alc861_base_mixer },
12093                 .init_verbs = { alc861_base_init_verbs },
12094                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12095                 .dac_nids = alc861_dac_nids,
12096                 .dig_out_nid = ALC861_DIGOUT_NID,
12097                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
12098                 .channel_mode = alc861_8ch_modes,
12099                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12100                 .adc_nids = alc861_adc_nids,
12101                 .input_mux = &alc861_capture_source,
12102         },
12103         [ALC660_3ST] = {
12104                 .mixers = { alc861_3ST_mixer },
12105                 .init_verbs = { alc861_threestack_init_verbs },
12106                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
12107                 .dac_nids = alc660_dac_nids,
12108                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
12109                 .channel_mode = alc861_threestack_modes,
12110                 .need_dac_fix = 1,
12111                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12112                 .adc_nids = alc861_adc_nids,
12113                 .input_mux = &alc861_capture_source,
12114         },
12115         [ALC861_UNIWILL_M31] = {
12116                 .mixers = { alc861_uniwill_m31_mixer },
12117                 .init_verbs = { alc861_uniwill_m31_init_verbs },
12118                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12119                 .dac_nids = alc861_dac_nids,
12120                 .dig_out_nid = ALC861_DIGOUT_NID,
12121                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
12122                 .channel_mode = alc861_uniwill_m31_modes,
12123                 .need_dac_fix = 1,
12124                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12125                 .adc_nids = alc861_adc_nids,
12126                 .input_mux = &alc861_capture_source,
12127         },
12128         [ALC861_TOSHIBA] = {
12129                 .mixers = { alc861_toshiba_mixer },
12130                 .init_verbs = { alc861_base_init_verbs,
12131                                 alc861_toshiba_init_verbs },
12132                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12133                 .dac_nids = alc861_dac_nids,
12134                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
12135                 .channel_mode = alc883_3ST_2ch_modes,
12136                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12137                 .adc_nids = alc861_adc_nids,
12138                 .input_mux = &alc861_capture_source,
12139                 .unsol_event = alc861_toshiba_unsol_event,
12140                 .init_hook = alc861_toshiba_automute,
12141         },
12142         [ALC861_ASUS] = {
12143                 .mixers = { alc861_asus_mixer },
12144                 .init_verbs = { alc861_asus_init_verbs },
12145                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12146                 .dac_nids = alc861_dac_nids,
12147                 .dig_out_nid = ALC861_DIGOUT_NID,
12148                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
12149                 .channel_mode = alc861_asus_modes,
12150                 .need_dac_fix = 1,
12151                 .hp_nid = 0x06,
12152                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12153                 .adc_nids = alc861_adc_nids,
12154                 .input_mux = &alc861_capture_source,
12155         },
12156         [ALC861_ASUS_LAPTOP] = {
12157                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
12158                 .init_verbs = { alc861_asus_init_verbs,
12159                                 alc861_asus_laptop_init_verbs },
12160                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12161                 .dac_nids = alc861_dac_nids,
12162                 .dig_out_nid = ALC861_DIGOUT_NID,
12163                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
12164                 .channel_mode = alc883_3ST_2ch_modes,
12165                 .need_dac_fix = 1,
12166                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12167                 .adc_nids = alc861_adc_nids,
12168                 .input_mux = &alc861_capture_source,
12169         },
12170 };
12171
12172
12173 static int patch_alc861(struct hda_codec *codec)
12174 {
12175         struct alc_spec *spec;
12176         int board_config;
12177         int err;
12178
12179         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
12180         if (spec == NULL)
12181                 return -ENOMEM;
12182
12183         codec->spec = spec;
12184
12185         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
12186                                                   alc861_models,
12187                                                   alc861_cfg_tbl);
12188
12189         if (board_config < 0) {
12190                 printk(KERN_INFO "hda_codec: Unknown model for ALC861, "
12191                        "trying auto-probe from BIOS...\n");
12192                 board_config = ALC861_AUTO;
12193         }
12194
12195         if (board_config == ALC861_AUTO) {
12196                 /* automatic parse from the BIOS config */
12197                 err = alc861_parse_auto_config(codec);
12198                 if (err < 0) {
12199                         alc_free(codec);
12200                         return err;
12201                 } else if (!err) {
12202                         printk(KERN_INFO
12203                                "hda_codec: Cannot set up configuration "
12204                                "from BIOS.  Using base mode...\n");
12205                    board_config = ALC861_3ST_DIG;
12206                 }
12207         }
12208
12209         if (board_config != ALC861_AUTO)
12210                 setup_preset(spec, &alc861_presets[board_config]);
12211
12212         spec->stream_name_analog = "ALC861 Analog";
12213         spec->stream_analog_playback = &alc861_pcm_analog_playback;
12214         spec->stream_analog_capture = &alc861_pcm_analog_capture;
12215
12216         spec->stream_name_digital = "ALC861 Digital";
12217         spec->stream_digital_playback = &alc861_pcm_digital_playback;
12218         spec->stream_digital_capture = &alc861_pcm_digital_capture;
12219
12220         spec->vmaster_nid = 0x03;
12221
12222         codec->patch_ops = alc_patch_ops;
12223         if (board_config == ALC861_AUTO)
12224                 spec->init_hook = alc861_auto_init;
12225 #ifdef CONFIG_SND_HDA_POWER_SAVE
12226         if (!spec->loopback.amplist)
12227                 spec->loopback.amplist = alc861_loopbacks;
12228 #endif
12229                 
12230         return 0;
12231 }
12232
12233 /*
12234  * ALC861-VD support
12235  *
12236  * Based on ALC882
12237  *
12238  * In addition, an independent DAC
12239  */
12240 #define ALC861VD_DIGOUT_NID     0x06
12241
12242 static hda_nid_t alc861vd_dac_nids[4] = {
12243         /* front, surr, clfe, side surr */
12244         0x02, 0x03, 0x04, 0x05
12245 };
12246
12247 /* dac_nids for ALC660vd are in a different order - according to
12248  * Realtek's driver.
12249  * This should probably tesult in a different mixer for 6stack models
12250  * of ALC660vd codecs, but for now there is only 3stack mixer
12251  * - and it is the same as in 861vd.
12252  * adc_nids in ALC660vd are (is) the same as in 861vd
12253  */
12254 static hda_nid_t alc660vd_dac_nids[3] = {
12255         /* front, rear, clfe, rear_surr */
12256         0x02, 0x04, 0x03
12257 };
12258
12259 static hda_nid_t alc861vd_adc_nids[1] = {
12260         /* ADC0 */
12261         0x09,
12262 };
12263
12264 static hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
12265
12266 /* input MUX */
12267 /* FIXME: should be a matrix-type input source selection */
12268 static struct hda_input_mux alc861vd_capture_source = {
12269         .num_items = 4,
12270         .items = {
12271                 { "Mic", 0x0 },
12272                 { "Front Mic", 0x1 },
12273                 { "Line", 0x2 },
12274                 { "CD", 0x4 },
12275         },
12276 };
12277
12278 static struct hda_input_mux alc861vd_dallas_capture_source = {
12279         .num_items = 2,
12280         .items = {
12281                 { "Ext Mic", 0x0 },
12282                 { "Int Mic", 0x1 },
12283         },
12284 };
12285
12286 static struct hda_input_mux alc861vd_hp_capture_source = {
12287         .num_items = 2,
12288         .items = {
12289                 { "Front Mic", 0x0 },
12290                 { "ATAPI Mic", 0x1 },
12291         },
12292 };
12293
12294 #define alc861vd_mux_enum_info alc_mux_enum_info
12295 #define alc861vd_mux_enum_get alc_mux_enum_get
12296 /* ALC861VD has the ALC882-type input selection (but has only one ADC) */
12297 #define alc861vd_mux_enum_put alc882_mux_enum_put
12298
12299 /*
12300  * 2ch mode
12301  */
12302 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
12303         { 2, NULL }
12304 };
12305
12306 /*
12307  * 6ch mode
12308  */
12309 static struct hda_verb alc861vd_6stack_ch6_init[] = {
12310         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12311         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12312         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12313         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12314         { } /* end */
12315 };
12316
12317 /*
12318  * 8ch mode
12319  */
12320 static struct hda_verb alc861vd_6stack_ch8_init[] = {
12321         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12322         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12323         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12324         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12325         { } /* end */
12326 };
12327
12328 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
12329         { 6, alc861vd_6stack_ch6_init },
12330         { 8, alc861vd_6stack_ch8_init },
12331 };
12332
12333 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
12334         {
12335                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12336                 .name = "Channel Mode",
12337                 .info = alc_ch_mode_info,
12338                 .get = alc_ch_mode_get,
12339                 .put = alc_ch_mode_put,
12340         },
12341         { } /* end */
12342 };
12343
12344 static struct snd_kcontrol_new alc861vd_capture_mixer[] = {
12345         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
12346         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
12347
12348         {
12349                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12350                 /* The multiple "Capture Source" controls confuse alsamixer
12351                  * So call somewhat different..
12352                  */
12353                 /* .name = "Capture Source", */
12354                 .name = "Input Source",
12355                 .count = 1,
12356                 .info = alc861vd_mux_enum_info,
12357                 .get = alc861vd_mux_enum_get,
12358                 .put = alc861vd_mux_enum_put,
12359         },
12360         { } /* end */
12361 };
12362
12363 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
12364  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
12365  */
12366 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
12367         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12368         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
12369
12370         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12371         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
12372
12373         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
12374                                 HDA_OUTPUT),
12375         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
12376                                 HDA_OUTPUT),
12377         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
12378         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
12379
12380         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
12381         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
12382
12383         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12384
12385         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12386         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12387         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12388
12389         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
12390         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12391         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12392
12393         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12394         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12395
12396         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
12397         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
12398
12399         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
12400         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
12401
12402         { } /* end */
12403 };
12404
12405 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
12406         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12407         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
12408
12409         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12410
12411         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12412         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12413         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12414
12415         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
12416         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12417         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12418
12419         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12420         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12421
12422         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
12423         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
12424
12425         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
12426         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
12427
12428         { } /* end */
12429 };
12430
12431 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
12432         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12433         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
12434         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12435
12436         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12437
12438         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12439         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12440         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12441
12442         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
12443         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12444         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12445
12446         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
12447         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
12448
12449         { } /* end */
12450 };
12451
12452 /* Pin assignment: Speaker=0x14, HP = 0x15,
12453  *                 Ext Mic=0x18, Int Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
12454  */
12455 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
12456         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12457         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
12458         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12459         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
12460         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
12461         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12462         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12463         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
12464         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12465         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12466         HDA_CODEC_VOLUME("PC Beep Volume", 0x0b, 0x05, HDA_INPUT),
12467         HDA_CODEC_MUTE("PC Beep Switch", 0x0b, 0x05, HDA_INPUT),
12468         { } /* end */
12469 };
12470
12471 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
12472  *                 Front Mic=0x18, ATAPI Mic = 0x19,
12473  */
12474 static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
12475         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12476         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
12477         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12478         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
12479         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12480         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12481         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12482         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12483         
12484         { } /* end */
12485 };
12486
12487 /*
12488  * generic initialization of ADC, input mixers and output mixers
12489  */
12490 static struct hda_verb alc861vd_volume_init_verbs[] = {
12491         /*
12492          * Unmute ADC0 and set the default input to mic-in
12493          */
12494         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
12495         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12496
12497         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
12498          * the analog-loopback mixer widget
12499          */
12500         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
12501         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12502         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12503         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12504         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12505         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
12506
12507         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
12508         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12509         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12510         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12511         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
12512
12513         /*
12514          * Set up output mixers (0x02 - 0x05)
12515          */
12516         /* set vol=0 to output mixers */
12517         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12518         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12519         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12520         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12521
12522         /* set up input amps for analog loopback */
12523         /* Amp Indices: DAC = 0, mixer = 1 */
12524         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12525         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12526         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12527         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12528         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12529         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12530         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12531         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12532
12533         { }
12534 };
12535
12536 /*
12537  * 3-stack pin configuration:
12538  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
12539  */
12540 static struct hda_verb alc861vd_3stack_init_verbs[] = {
12541         /*
12542          * Set pin mode and muting
12543          */
12544         /* set front pin widgets 0x14 for output */
12545         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12546         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12547         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
12548
12549         /* Mic (rear) pin: input vref at 80% */
12550         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12551         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12552         /* Front Mic pin: input vref at 80% */
12553         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12554         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12555         /* Line In pin: input */
12556         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12557         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12558         /* Line-2 In: Headphone output (output 0 - 0x0c) */
12559         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12560         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12561         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
12562         /* CD pin widget for input */
12563         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12564
12565         { }
12566 };
12567
12568 /*
12569  * 6-stack pin configuration:
12570  */
12571 static struct hda_verb alc861vd_6stack_init_verbs[] = {
12572         /*
12573          * Set pin mode and muting
12574          */
12575         /* set front pin widgets 0x14 for output */
12576         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12577         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12578         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
12579
12580         /* Rear Pin: output 1 (0x0d) */
12581         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12582         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12583         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12584         /* CLFE Pin: output 2 (0x0e) */
12585         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12586         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12587         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
12588         /* Side Pin: output 3 (0x0f) */
12589         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12590         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12591         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
12592
12593         /* Mic (rear) pin: input vref at 80% */
12594         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12595         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12596         /* Front Mic pin: input vref at 80% */
12597         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12598         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12599         /* Line In pin: input */
12600         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12601         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12602         /* Line-2 In: Headphone output (output 0 - 0x0c) */
12603         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12604         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12605         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
12606         /* CD pin widget for input */
12607         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12608
12609         { }
12610 };
12611
12612 static struct hda_verb alc861vd_eapd_verbs[] = {
12613         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
12614         { }
12615 };
12616
12617 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
12618         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12619         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12620         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
12621         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12622         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT}, 
12623         {}
12624 };
12625
12626 /* toggle speaker-output according to the hp-jack state */
12627 static void alc861vd_lenovo_hp_automute(struct hda_codec *codec)
12628 {
12629         unsigned int present;
12630         unsigned char bits;
12631
12632         present = snd_hda_codec_read(codec, 0x1b, 0,
12633                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12634         bits = present ? HDA_AMP_MUTE : 0;
12635         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
12636                                  HDA_AMP_MUTE, bits);
12637 }
12638
12639 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
12640 {
12641         unsigned int present;
12642         unsigned char bits;
12643
12644         present = snd_hda_codec_read(codec, 0x18, 0,
12645                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12646         bits = present ? HDA_AMP_MUTE : 0;
12647         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
12648                                  HDA_AMP_MUTE, bits);
12649 }
12650
12651 static void alc861vd_lenovo_automute(struct hda_codec *codec)
12652 {
12653         alc861vd_lenovo_hp_automute(codec);
12654         alc861vd_lenovo_mic_automute(codec);
12655 }
12656
12657 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
12658                                         unsigned int res)
12659 {
12660         switch (res >> 26) {
12661         case ALC880_HP_EVENT:
12662                 alc861vd_lenovo_hp_automute(codec);
12663                 break;
12664         case ALC880_MIC_EVENT:
12665                 alc861vd_lenovo_mic_automute(codec);
12666                 break;
12667         }
12668 }
12669
12670 static struct hda_verb alc861vd_dallas_verbs[] = {
12671         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12672         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12673         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12674         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12675
12676         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12677         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12678         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12679         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12680         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12681         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12682         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12683         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12684         
12685         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12686         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12687         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12688         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12689         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12690         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12691         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12692         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12693
12694         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
12695         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12696         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
12697         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12698         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12699         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12700         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12701         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12702
12703         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12704         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12705         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12706         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
12707
12708         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12709         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},  
12710         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12711
12712         { } /* end */
12713 };
12714
12715 /* toggle speaker-output according to the hp-jack state */
12716 static void alc861vd_dallas_automute(struct hda_codec *codec)
12717 {
12718         unsigned int present;
12719
12720         present = snd_hda_codec_read(codec, 0x15, 0,
12721                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12722         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
12723                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
12724 }
12725
12726 static void alc861vd_dallas_unsol_event(struct hda_codec *codec, unsigned int res)
12727 {
12728         if ((res >> 26) == ALC880_HP_EVENT)
12729                 alc861vd_dallas_automute(codec);
12730 }
12731
12732 #ifdef CONFIG_SND_HDA_POWER_SAVE
12733 #define alc861vd_loopbacks      alc880_loopbacks
12734 #endif
12735
12736 /* pcm configuration: identiacal with ALC880 */
12737 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
12738 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
12739 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
12740 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
12741
12742 /*
12743  * configuration and preset
12744  */
12745 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
12746         [ALC660VD_3ST]          = "3stack-660",
12747         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
12748         [ALC861VD_3ST]          = "3stack",
12749         [ALC861VD_3ST_DIG]      = "3stack-digout",
12750         [ALC861VD_6ST_DIG]      = "6stack-digout",
12751         [ALC861VD_LENOVO]       = "lenovo",
12752         [ALC861VD_DALLAS]       = "dallas",
12753         [ALC861VD_HP]           = "hp",
12754         [ALC861VD_AUTO]         = "auto",
12755 };
12756
12757 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
12758         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
12759         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
12760         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
12761         SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),
12762         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
12763         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
12764         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
12765         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
12766         SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS),
12767         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
12768         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
12769         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
12770         SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo", ALC861VD_LENOVO),
12771         SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo 3000 C200", ALC861VD_LENOVO),
12772         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
12773         {}
12774 };
12775
12776 static struct alc_config_preset alc861vd_presets[] = {
12777         [ALC660VD_3ST] = {
12778                 .mixers = { alc861vd_3st_mixer },
12779                 .init_verbs = { alc861vd_volume_init_verbs,
12780                                  alc861vd_3stack_init_verbs },
12781                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
12782                 .dac_nids = alc660vd_dac_nids,
12783                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12784                 .channel_mode = alc861vd_3stack_2ch_modes,
12785                 .input_mux = &alc861vd_capture_source,
12786         },
12787         [ALC660VD_3ST_DIG] = {
12788                 .mixers = { alc861vd_3st_mixer },
12789                 .init_verbs = { alc861vd_volume_init_verbs,
12790                                  alc861vd_3stack_init_verbs },
12791                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
12792                 .dac_nids = alc660vd_dac_nids,
12793                 .dig_out_nid = ALC861VD_DIGOUT_NID,
12794                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12795                 .channel_mode = alc861vd_3stack_2ch_modes,
12796                 .input_mux = &alc861vd_capture_source,
12797         },
12798         [ALC861VD_3ST] = {
12799                 .mixers = { alc861vd_3st_mixer },
12800                 .init_verbs = { alc861vd_volume_init_verbs,
12801                                  alc861vd_3stack_init_verbs },
12802                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
12803                 .dac_nids = alc861vd_dac_nids,
12804                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12805                 .channel_mode = alc861vd_3stack_2ch_modes,
12806                 .input_mux = &alc861vd_capture_source,
12807         },
12808         [ALC861VD_3ST_DIG] = {
12809                 .mixers = { alc861vd_3st_mixer },
12810                 .init_verbs = { alc861vd_volume_init_verbs,
12811                                  alc861vd_3stack_init_verbs },
12812                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
12813                 .dac_nids = alc861vd_dac_nids,
12814                 .dig_out_nid = ALC861VD_DIGOUT_NID,
12815                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12816                 .channel_mode = alc861vd_3stack_2ch_modes,
12817                 .input_mux = &alc861vd_capture_source,
12818         },
12819         [ALC861VD_6ST_DIG] = {
12820                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
12821                 .init_verbs = { alc861vd_volume_init_verbs,
12822                                 alc861vd_6stack_init_verbs },
12823                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
12824                 .dac_nids = alc861vd_dac_nids,
12825                 .dig_out_nid = ALC861VD_DIGOUT_NID,
12826                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
12827                 .channel_mode = alc861vd_6stack_modes,
12828                 .input_mux = &alc861vd_capture_source,
12829         },
12830         [ALC861VD_LENOVO] = {
12831                 .mixers = { alc861vd_lenovo_mixer },
12832                 .init_verbs = { alc861vd_volume_init_verbs,
12833                                 alc861vd_3stack_init_verbs,
12834                                 alc861vd_eapd_verbs,
12835                                 alc861vd_lenovo_unsol_verbs },
12836                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
12837                 .dac_nids = alc660vd_dac_nids,
12838                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12839                 .channel_mode = alc861vd_3stack_2ch_modes,
12840                 .input_mux = &alc861vd_capture_source,
12841                 .unsol_event = alc861vd_lenovo_unsol_event,
12842                 .init_hook = alc861vd_lenovo_automute,
12843         },
12844         [ALC861VD_DALLAS] = {
12845                 .mixers = { alc861vd_dallas_mixer },
12846                 .init_verbs = { alc861vd_dallas_verbs },
12847                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
12848                 .dac_nids = alc861vd_dac_nids,
12849                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12850                 .channel_mode = alc861vd_3stack_2ch_modes,
12851                 .input_mux = &alc861vd_dallas_capture_source,
12852                 .unsol_event = alc861vd_dallas_unsol_event,
12853                 .init_hook = alc861vd_dallas_automute,
12854         },
12855         [ALC861VD_HP] = {
12856                 .mixers = { alc861vd_hp_mixer },
12857                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
12858                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
12859                 .dac_nids = alc861vd_dac_nids,
12860                 .dig_out_nid = ALC861VD_DIGOUT_NID,
12861                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12862                 .channel_mode = alc861vd_3stack_2ch_modes,
12863                 .input_mux = &alc861vd_hp_capture_source,
12864                 .unsol_event = alc861vd_dallas_unsol_event,
12865                 .init_hook = alc861vd_dallas_automute,
12866         },              
12867 };
12868
12869 /*
12870  * BIOS auto configuration
12871  */
12872 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
12873                                 hda_nid_t nid, int pin_type, int dac_idx)
12874 {
12875         alc_set_pin_output(codec, nid, pin_type);
12876 }
12877
12878 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
12879 {
12880         struct alc_spec *spec = codec->spec;
12881         int i;
12882
12883         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
12884         for (i = 0; i <= HDA_SIDE; i++) {
12885                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
12886                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
12887                 if (nid)
12888                         alc861vd_auto_set_output_and_unmute(codec, nid,
12889                                                             pin_type, i);
12890         }
12891 }
12892
12893
12894 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
12895 {
12896         struct alc_spec *spec = codec->spec;
12897         hda_nid_t pin;
12898
12899         pin = spec->autocfg.hp_pins[0];
12900         if (pin) /* connect to front and  use dac 0 */
12901                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
12902         pin = spec->autocfg.speaker_pins[0];
12903         if (pin)
12904                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
12905 }
12906
12907 #define alc861vd_is_input_pin(nid)      alc880_is_input_pin(nid)
12908 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
12909
12910 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
12911 {
12912         struct alc_spec *spec = codec->spec;
12913         int i;
12914
12915         for (i = 0; i < AUTO_PIN_LAST; i++) {
12916                 hda_nid_t nid = spec->autocfg.input_pins[i];
12917                 if (alc861vd_is_input_pin(nid)) {
12918                         snd_hda_codec_write(codec, nid, 0,
12919                                         AC_VERB_SET_PIN_WIDGET_CONTROL,
12920                                         i <= AUTO_PIN_FRONT_MIC ?
12921                                                         PIN_VREF80 : PIN_IN);
12922                         if (nid != ALC861VD_PIN_CD_NID)
12923                                 snd_hda_codec_write(codec, nid, 0,
12924                                                 AC_VERB_SET_AMP_GAIN_MUTE,
12925                                                 AMP_OUT_MUTE);
12926                 }
12927         }
12928 }
12929
12930 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
12931 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
12932
12933 /* add playback controls from the parsed DAC table */
12934 /* Based on ALC880 version. But ALC861VD has separate,
12935  * different NIDs for mute/unmute switch and volume control */
12936 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
12937                                              const struct auto_pin_cfg *cfg)
12938 {
12939         char name[32];
12940         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
12941         hda_nid_t nid_v, nid_s;
12942         int i, err;
12943
12944         for (i = 0; i < cfg->line_outs; i++) {
12945                 if (!spec->multiout.dac_nids[i])
12946                         continue;
12947                 nid_v = alc861vd_idx_to_mixer_vol(
12948                                 alc880_dac_to_idx(
12949                                         spec->multiout.dac_nids[i]));
12950                 nid_s = alc861vd_idx_to_mixer_switch(
12951                                 alc880_dac_to_idx(
12952                                         spec->multiout.dac_nids[i]));
12953
12954                 if (i == 2) {
12955                         /* Center/LFE */
12956                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12957                                           "Center Playback Volume",
12958                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
12959                                                               HDA_OUTPUT));
12960                         if (err < 0)
12961                                 return err;
12962                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12963                                           "LFE Playback Volume",
12964                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
12965                                                               HDA_OUTPUT));
12966                         if (err < 0)
12967                                 return err;
12968                         err = add_control(spec, ALC_CTL_BIND_MUTE,
12969                                           "Center Playback Switch",
12970                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
12971                                                               HDA_INPUT));
12972                         if (err < 0)
12973                                 return err;
12974                         err = add_control(spec, ALC_CTL_BIND_MUTE,
12975                                           "LFE Playback Switch",
12976                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
12977                                                               HDA_INPUT));
12978                         if (err < 0)
12979                                 return err;
12980                 } else {
12981                         sprintf(name, "%s Playback Volume", chname[i]);
12982                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
12983                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
12984                                                               HDA_OUTPUT));
12985                         if (err < 0)
12986                                 return err;
12987                         sprintf(name, "%s Playback Switch", chname[i]);
12988                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
12989                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
12990                                                               HDA_INPUT));
12991                         if (err < 0)
12992                                 return err;
12993                 }
12994         }
12995         return 0;
12996 }
12997
12998 /* add playback controls for speaker and HP outputs */
12999 /* Based on ALC880 version. But ALC861VD has separate,
13000  * different NIDs for mute/unmute switch and volume control */
13001 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
13002                                         hda_nid_t pin, const char *pfx)
13003 {
13004         hda_nid_t nid_v, nid_s;
13005         int err;
13006         char name[32];
13007
13008         if (!pin)
13009                 return 0;
13010
13011         if (alc880_is_fixed_pin(pin)) {
13012                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
13013                 /* specify the DAC as the extra output */
13014                 if (!spec->multiout.hp_nid)
13015                         spec->multiout.hp_nid = nid_v;
13016                 else
13017                         spec->multiout.extra_out_nid[0] = nid_v;
13018                 /* control HP volume/switch on the output mixer amp */
13019                 nid_v = alc861vd_idx_to_mixer_vol(
13020                                 alc880_fixed_pin_idx(pin));
13021                 nid_s = alc861vd_idx_to_mixer_switch(
13022                                 alc880_fixed_pin_idx(pin));
13023
13024                 sprintf(name, "%s Playback Volume", pfx);
13025                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
13026                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
13027                 if (err < 0)
13028                         return err;
13029                 sprintf(name, "%s Playback Switch", pfx);
13030                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
13031                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
13032                 if (err < 0)
13033                         return err;
13034         } else if (alc880_is_multi_pin(pin)) {
13035                 /* set manual connection */
13036                 /* we have only a switch on HP-out PIN */
13037                 sprintf(name, "%s Playback Switch", pfx);
13038                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
13039                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
13040                 if (err < 0)
13041                         return err;
13042         }
13043         return 0;
13044 }
13045
13046 /* parse the BIOS configuration and set up the alc_spec
13047  * return 1 if successful, 0 if the proper config is not found,
13048  * or a negative error code
13049  * Based on ALC880 version - had to change it to override
13050  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
13051 static int alc861vd_parse_auto_config(struct hda_codec *codec)
13052 {
13053         struct alc_spec *spec = codec->spec;
13054         int err;
13055         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
13056
13057         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
13058                                            alc861vd_ignore);
13059         if (err < 0)
13060                 return err;
13061         if (!spec->autocfg.line_outs)
13062                 return 0; /* can't find valid BIOS pin config */
13063
13064         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
13065         if (err < 0)
13066                 return err;
13067         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
13068         if (err < 0)
13069                 return err;
13070         err = alc861vd_auto_create_extra_out(spec,
13071                                              spec->autocfg.speaker_pins[0],
13072                                              "Speaker");
13073         if (err < 0)
13074                 return err;
13075         err = alc861vd_auto_create_extra_out(spec,
13076                                              spec->autocfg.hp_pins[0],
13077                                              "Headphone");
13078         if (err < 0)
13079                 return err;
13080         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
13081         if (err < 0)
13082                 return err;
13083
13084         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
13085
13086         if (spec->autocfg.dig_out_pin)
13087                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
13088
13089         if (spec->kctl_alloc)
13090                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
13091
13092         spec->init_verbs[spec->num_init_verbs++]
13093                 = alc861vd_volume_init_verbs;
13094
13095         spec->num_mux_defs = 1;
13096         spec->input_mux = &spec->private_imux;
13097
13098         err = alc_auto_add_mic_boost(codec);
13099         if (err < 0)
13100                 return err;
13101
13102         return 1;
13103 }
13104
13105 /* additional initialization for auto-configuration model */
13106 static void alc861vd_auto_init(struct hda_codec *codec)
13107 {
13108         struct alc_spec *spec = codec->spec;
13109         alc861vd_auto_init_multi_out(codec);
13110         alc861vd_auto_init_hp_out(codec);
13111         alc861vd_auto_init_analog_input(codec);
13112         if (spec->unsol_event)
13113                 alc_sku_automute(codec);
13114 }
13115
13116 static int patch_alc861vd(struct hda_codec *codec)
13117 {
13118         struct alc_spec *spec;
13119         int err, board_config;
13120
13121         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13122         if (spec == NULL)
13123                 return -ENOMEM;
13124
13125         codec->spec = spec;
13126
13127         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
13128                                                   alc861vd_models,
13129                                                   alc861vd_cfg_tbl);
13130
13131         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
13132                 printk(KERN_INFO "hda_codec: Unknown model for ALC660VD/"
13133                         "ALC861VD, trying auto-probe from BIOS...\n");
13134                 board_config = ALC861VD_AUTO;
13135         }
13136
13137         if (board_config == ALC861VD_AUTO) {
13138                 /* automatic parse from the BIOS config */
13139                 err = alc861vd_parse_auto_config(codec);
13140                 if (err < 0) {
13141                         alc_free(codec);
13142                         return err;
13143                 } else if (!err) {
13144                         printk(KERN_INFO
13145                                "hda_codec: Cannot set up configuration "
13146                                "from BIOS.  Using base mode...\n");
13147                         board_config = ALC861VD_3ST;
13148                 }
13149         }
13150
13151         if (board_config != ALC861VD_AUTO)
13152                 setup_preset(spec, &alc861vd_presets[board_config]);
13153
13154         spec->stream_name_analog = "ALC861VD Analog";
13155         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
13156         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
13157
13158         spec->stream_name_digital = "ALC861VD Digital";
13159         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
13160         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
13161
13162         spec->adc_nids = alc861vd_adc_nids;
13163         spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
13164         spec->capsrc_nids = alc861vd_capsrc_nids;
13165
13166         spec->mixers[spec->num_mixers] = alc861vd_capture_mixer;
13167         spec->num_mixers++;
13168
13169         spec->vmaster_nid = 0x02;
13170
13171         codec->patch_ops = alc_patch_ops;
13172
13173         if (board_config == ALC861VD_AUTO)
13174                 spec->init_hook = alc861vd_auto_init;
13175 #ifdef CONFIG_SND_HDA_POWER_SAVE
13176         if (!spec->loopback.amplist)
13177                 spec->loopback.amplist = alc861vd_loopbacks;
13178 #endif
13179
13180         return 0;
13181 }
13182
13183 /*
13184  * ALC662 support
13185  *
13186  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
13187  * configuration.  Each pin widget can choose any input DACs and a mixer.
13188  * Each ADC is connected from a mixer of all inputs.  This makes possible
13189  * 6-channel independent captures.
13190  *
13191  * In addition, an independent DAC for the multi-playback (not used in this
13192  * driver yet).
13193  */
13194 #define ALC662_DIGOUT_NID       0x06
13195 #define ALC662_DIGIN_NID        0x0a
13196
13197 static hda_nid_t alc662_dac_nids[4] = {
13198         /* front, rear, clfe, rear_surr */
13199         0x02, 0x03, 0x04
13200 };
13201
13202 static hda_nid_t alc662_adc_nids[1] = {
13203         /* ADC1-2 */
13204         0x09,
13205 };
13206
13207 static hda_nid_t alc662_capsrc_nids[1] = { 0x22 };
13208
13209 /* input MUX */
13210 /* FIXME: should be a matrix-type input source selection */
13211 static struct hda_input_mux alc662_capture_source = {
13212         .num_items = 4,
13213         .items = {
13214                 { "Mic", 0x0 },
13215                 { "Front Mic", 0x1 },
13216                 { "Line", 0x2 },
13217                 { "CD", 0x4 },
13218         },
13219 };
13220
13221 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
13222         .num_items = 2,
13223         .items = {
13224                 { "Mic", 0x1 },
13225                 { "Line", 0x2 },
13226         },
13227 };
13228
13229 static struct hda_input_mux alc662_eeepc_capture_source = {
13230         .num_items = 2,
13231         .items = {
13232                 { "i-Mic", 0x1 },
13233                 { "e-Mic", 0x0 },
13234         },
13235 };
13236
13237 #define alc662_mux_enum_info alc_mux_enum_info
13238 #define alc662_mux_enum_get alc_mux_enum_get
13239 #define alc662_mux_enum_put alc882_mux_enum_put
13240
13241 /*
13242  * 2ch mode
13243  */
13244 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
13245         { 2, NULL }
13246 };
13247
13248 /*
13249  * 2ch mode
13250  */
13251 static struct hda_verb alc662_3ST_ch2_init[] = {
13252         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
13253         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
13254         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
13255         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
13256         { } /* end */
13257 };
13258
13259 /*
13260  * 6ch mode
13261  */
13262 static struct hda_verb alc662_3ST_ch6_init[] = {
13263         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13264         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
13265         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
13266         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13267         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
13268         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
13269         { } /* end */
13270 };
13271
13272 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
13273         { 2, alc662_3ST_ch2_init },
13274         { 6, alc662_3ST_ch6_init },
13275 };
13276
13277 /*
13278  * 2ch mode
13279  */
13280 static struct hda_verb alc662_sixstack_ch6_init[] = {
13281         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13282         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13283         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13284         { } /* end */
13285 };
13286
13287 /*
13288  * 6ch mode
13289  */
13290 static struct hda_verb alc662_sixstack_ch8_init[] = {
13291         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13292         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13293         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13294         { } /* end */
13295 };
13296
13297 static struct hda_channel_mode alc662_5stack_modes[2] = {
13298         { 2, alc662_sixstack_ch6_init },
13299         { 6, alc662_sixstack_ch8_init },
13300 };
13301
13302 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
13303  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
13304  */
13305
13306 static struct snd_kcontrol_new alc662_base_mixer[] = {
13307         /* output mixer control */
13308         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
13309         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
13310         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
13311         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
13312         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
13313         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
13314         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
13315         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
13316         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13317
13318         /*Input mixer control */
13319         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
13320         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
13321         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
13322         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
13323         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
13324         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
13325         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
13326         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
13327         { } /* end */
13328 };
13329
13330 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
13331         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13332         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
13333         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13334         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13335         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13336         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13337         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13338         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13339         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13340         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13341         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13342         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
13343         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
13344         { } /* end */
13345 };
13346
13347 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
13348         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13349         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
13350         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13351         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
13352         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
13353         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
13354         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
13355         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
13356         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13357         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13358         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13359         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13360         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13361         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13362         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13363         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13364         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13365         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
13366         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
13367         { } /* end */
13368 };
13369
13370 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
13371         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13372         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
13373         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13374         HDA_BIND_MUTE("Speaker Playback Switch", 0x03, 2, HDA_INPUT),
13375         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13376         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13377         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13378         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13379         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13380         { } /* end */
13381 };
13382
13383 static struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
13384         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13385
13386         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13387         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13388
13389         HDA_CODEC_VOLUME("e-Mic Boost", 0x18, 0, HDA_INPUT),
13390         HDA_CODEC_VOLUME("e-Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13391         HDA_CODEC_MUTE("e-Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13392
13393         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
13394         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13395         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13396         { } /* end */
13397 };
13398
13399 static struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
13400         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13401         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13402         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13403         HDA_BIND_MUTE("Surround Playback Switch", 0x03, 2, HDA_INPUT),
13404         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
13405         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
13406         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
13407         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
13408         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13409         HDA_BIND_MUTE("MuteCtrl Playback Switch", 0x0c, 2, HDA_INPUT),
13410         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13411         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13412         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13413         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13414         { } /* end */
13415 };
13416
13417 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
13418         {
13419                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13420                 .name = "Channel Mode",
13421                 .info = alc_ch_mode_info,
13422                 .get = alc_ch_mode_get,
13423                 .put = alc_ch_mode_put,
13424         },
13425         { } /* end */
13426 };
13427
13428 static struct hda_verb alc662_init_verbs[] = {
13429         /* ADC: mute amp left and right */
13430         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13431         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
13432         /* Front mixer: unmute input/output amp left and right (volume = 0) */
13433
13434         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13435         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13436         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13437         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13438         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
13439
13440         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13441         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13442         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13443         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13444         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13445         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13446
13447         /* Front Pin: output 0 (0x0c) */
13448         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13449         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13450
13451         /* Rear Pin: output 1 (0x0d) */
13452         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13453         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13454
13455         /* CLFE Pin: output 2 (0x0e) */
13456         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13457         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13458
13459         /* Mic (rear) pin: input vref at 80% */
13460         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13461         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13462         /* Front Mic pin: input vref at 80% */
13463         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13464         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13465         /* Line In pin: input */
13466         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13467         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13468         /* Line-2 In: Headphone output (output 0 - 0x0c) */
13469         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13470         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13471         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
13472         /* CD pin widget for input */
13473         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13474
13475         /* FIXME: use matrix-type input source selection */
13476         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
13477         /* Input mixer */
13478         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13479         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13480         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13481         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
13482
13483         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13484         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13485         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13486         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
13487         { }
13488 };
13489
13490 static struct hda_verb alc662_sue_init_verbs[] = {
13491         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
13492         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
13493         {}
13494 };
13495
13496 static struct hda_verb alc662_eeepc_sue_init_verbs[] = {
13497         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
13498         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13499         {}
13500 };
13501
13502 /* Set Unsolicited Event*/
13503 static struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
13504         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13505         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13506         {}
13507 };
13508
13509 /*
13510  * generic initialization of ADC, input mixers and output mixers
13511  */
13512 static struct hda_verb alc662_auto_init_verbs[] = {
13513         /*
13514          * Unmute ADC and set the default input to mic-in
13515          */
13516         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
13517         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13518
13519         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
13520          * mixer widget
13521          * Note: PASD motherboards uses the Line In 2 as the input for front
13522          * panel mic (mic 2)
13523          */
13524         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
13525         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13526         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13527         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13528         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13529         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
13530
13531         /*
13532          * Set up output mixers (0x0c - 0x0f)
13533          */
13534         /* set vol=0 to output mixers */
13535         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13536         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13537         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13538
13539         /* set up input amps for analog loopback */
13540         /* Amp Indices: DAC = 0, mixer = 1 */
13541         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13542         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13543         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13544         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13545         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13546         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13547
13548
13549         /* FIXME: use matrix-type input source selection */
13550         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
13551         /* Input mixer */
13552         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13553         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13554         { }
13555 };
13556
13557 /* capture mixer elements */
13558 static struct snd_kcontrol_new alc662_capture_mixer[] = {
13559         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
13560         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
13561         {
13562                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13563                 /* The multiple "Capture Source" controls confuse alsamixer
13564                  * So call somewhat different..
13565                  */
13566                 /* .name = "Capture Source", */
13567                 .name = "Input Source",
13568                 .count = 1,
13569                 .info = alc662_mux_enum_info,
13570                 .get = alc662_mux_enum_get,
13571                 .put = alc662_mux_enum_put,
13572         },
13573         { } /* end */
13574 };
13575
13576 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
13577 {
13578         unsigned int present;
13579         unsigned char bits;
13580
13581         present = snd_hda_codec_read(codec, 0x14, 0,
13582                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13583         bits = present ? HDA_AMP_MUTE : 0;
13584         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
13585                                  HDA_AMP_MUTE, bits);
13586 }
13587
13588 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
13589 {
13590         unsigned int present;
13591         unsigned char bits;
13592
13593         present = snd_hda_codec_read(codec, 0x1b, 0,
13594                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13595         bits = present ? HDA_AMP_MUTE : 0;
13596         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
13597                                  HDA_AMP_MUTE, bits);
13598         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
13599                                  HDA_AMP_MUTE, bits);
13600 }
13601
13602 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
13603                                            unsigned int res)
13604 {
13605         if ((res >> 26) == ALC880_HP_EVENT)
13606                 alc662_lenovo_101e_all_automute(codec);
13607         if ((res >> 26) == ALC880_FRONT_EVENT)
13608                 alc662_lenovo_101e_ispeaker_automute(codec);
13609 }
13610
13611 static void alc662_eeepc_mic_automute(struct hda_codec *codec)
13612 {
13613         unsigned int present;
13614
13615         present = snd_hda_codec_read(codec, 0x18, 0,
13616                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13617         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13618                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
13619         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13620                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
13621         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13622                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
13623         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13624                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
13625 }
13626
13627 /* unsolicited event for HP jack sensing */
13628 static void alc662_eeepc_unsol_event(struct hda_codec *codec,
13629                                      unsigned int res)
13630 {
13631         if ((res >> 26) == ALC880_HP_EVENT)
13632                 alc262_hippo1_automute( codec );
13633
13634         if ((res >> 26) == ALC880_MIC_EVENT)
13635                 alc662_eeepc_mic_automute(codec);
13636 }
13637
13638 static void alc662_eeepc_inithook(struct hda_codec *codec)
13639 {
13640         alc262_hippo1_automute( codec );
13641         alc662_eeepc_mic_automute(codec);
13642 }
13643
13644 static void alc662_eeepc_ep20_automute(struct hda_codec *codec)
13645 {
13646         unsigned int mute;
13647         unsigned int present;
13648
13649         snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
13650         present = snd_hda_codec_read(codec, 0x14, 0,
13651                                      AC_VERB_GET_PIN_SENSE, 0);
13652         present = (present & 0x80000000) != 0;
13653         if (present) {
13654                 /* mute internal speaker */
13655                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
13656                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
13657         } else {
13658                 /* unmute internal speaker if necessary */
13659                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
13660                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
13661                                          HDA_AMP_MUTE, mute);
13662         }
13663 }
13664
13665 /* unsolicited event for HP jack sensing */
13666 static void alc662_eeepc_ep20_unsol_event(struct hda_codec *codec,
13667                                           unsigned int res)
13668 {
13669         if ((res >> 26) == ALC880_HP_EVENT)
13670                 alc662_eeepc_ep20_automute(codec);
13671 }
13672
13673 static void alc662_eeepc_ep20_inithook(struct hda_codec *codec)
13674 {
13675         alc662_eeepc_ep20_automute(codec);
13676 }
13677
13678 #ifdef CONFIG_SND_HDA_POWER_SAVE
13679 #define alc662_loopbacks        alc880_loopbacks
13680 #endif
13681
13682
13683 /* pcm configuration: identiacal with ALC880 */
13684 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
13685 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
13686 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
13687 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
13688
13689 /*
13690  * configuration and preset
13691  */
13692 static const char *alc662_models[ALC662_MODEL_LAST] = {
13693         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
13694         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
13695         [ALC662_3ST_6ch]        = "3stack-6ch",
13696         [ALC662_5ST_DIG]        = "6stack-dig",
13697         [ALC662_LENOVO_101E]    = "lenovo-101e",
13698         [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
13699         [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
13700         [ALC662_AUTO]           = "auto",
13701 };
13702
13703 static struct snd_pci_quirk alc662_cfg_tbl[] = {
13704         SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
13705         SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
13706         SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
13707         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
13708         {}
13709 };
13710
13711 static struct alc_config_preset alc662_presets[] = {
13712         [ALC662_3ST_2ch_DIG] = {
13713                 .mixers = { alc662_3ST_2ch_mixer, alc662_capture_mixer },
13714                 .init_verbs = { alc662_init_verbs },
13715                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13716                 .dac_nids = alc662_dac_nids,
13717                 .dig_out_nid = ALC662_DIGOUT_NID,
13718                 .dig_in_nid = ALC662_DIGIN_NID,
13719                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
13720                 .channel_mode = alc662_3ST_2ch_modes,
13721                 .input_mux = &alc662_capture_source,
13722         },
13723         [ALC662_3ST_6ch_DIG] = {
13724                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer,
13725                             alc662_capture_mixer },
13726                 .init_verbs = { alc662_init_verbs },
13727                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13728                 .dac_nids = alc662_dac_nids,
13729                 .dig_out_nid = ALC662_DIGOUT_NID,
13730                 .dig_in_nid = ALC662_DIGIN_NID,
13731                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
13732                 .channel_mode = alc662_3ST_6ch_modes,
13733                 .need_dac_fix = 1,
13734                 .input_mux = &alc662_capture_source,
13735         },
13736         [ALC662_3ST_6ch] = {
13737                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer,
13738                             alc662_capture_mixer },
13739                 .init_verbs = { alc662_init_verbs },
13740                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13741                 .dac_nids = alc662_dac_nids,
13742                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
13743                 .channel_mode = alc662_3ST_6ch_modes,
13744                 .need_dac_fix = 1,
13745                 .input_mux = &alc662_capture_source,
13746         },
13747         [ALC662_5ST_DIG] = {
13748                 .mixers = { alc662_base_mixer, alc662_chmode_mixer,
13749                             alc662_capture_mixer },
13750                 .init_verbs = { alc662_init_verbs },
13751                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13752                 .dac_nids = alc662_dac_nids,
13753                 .dig_out_nid = ALC662_DIGOUT_NID,
13754                 .dig_in_nid = ALC662_DIGIN_NID,
13755                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
13756                 .channel_mode = alc662_5stack_modes,
13757                 .input_mux = &alc662_capture_source,
13758         },
13759         [ALC662_LENOVO_101E] = {
13760                 .mixers = { alc662_lenovo_101e_mixer, alc662_capture_mixer },
13761                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
13762                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13763                 .dac_nids = alc662_dac_nids,
13764                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
13765                 .channel_mode = alc662_3ST_2ch_modes,
13766                 .input_mux = &alc662_lenovo_101e_capture_source,
13767                 .unsol_event = alc662_lenovo_101e_unsol_event,
13768                 .init_hook = alc662_lenovo_101e_all_automute,
13769         },
13770         [ALC662_ASUS_EEEPC_P701] = {
13771                 .mixers = { alc662_eeepc_p701_mixer, alc662_capture_mixer },
13772                 .init_verbs = { alc662_init_verbs,
13773                                 alc662_eeepc_sue_init_verbs },
13774                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13775                 .dac_nids = alc662_dac_nids,
13776                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
13777                 .channel_mode = alc662_3ST_2ch_modes,
13778                 .input_mux = &alc662_eeepc_capture_source,
13779                 .unsol_event = alc662_eeepc_unsol_event,
13780                 .init_hook = alc662_eeepc_inithook,
13781         },
13782         [ALC662_ASUS_EEEPC_EP20] = {
13783                 .mixers = { alc662_eeepc_ep20_mixer, alc662_capture_mixer,
13784                             alc662_chmode_mixer },
13785                 .init_verbs = { alc662_init_verbs,
13786                                 alc662_eeepc_ep20_sue_init_verbs },
13787                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13788                 .dac_nids = alc662_dac_nids,
13789                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
13790                 .channel_mode = alc662_3ST_6ch_modes,
13791                 .input_mux = &alc662_lenovo_101e_capture_source,
13792                 .unsol_event = alc662_eeepc_ep20_unsol_event,
13793                 .init_hook = alc662_eeepc_ep20_inithook,
13794         },
13795
13796 };
13797
13798
13799 /*
13800  * BIOS auto configuration
13801  */
13802
13803 /* add playback controls from the parsed DAC table */
13804 static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec,
13805                                              const struct auto_pin_cfg *cfg)
13806 {
13807         char name[32];
13808         static const char *chname[4] = {
13809                 "Front", "Surround", NULL /*CLFE*/, "Side"
13810         };
13811         hda_nid_t nid;
13812         int i, err;
13813
13814         for (i = 0; i < cfg->line_outs; i++) {
13815                 if (!spec->multiout.dac_nids[i])
13816                         continue;
13817                 nid = alc880_idx_to_dac(i);
13818                 if (i == 2) {
13819                         /* Center/LFE */
13820                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
13821                                           "Center Playback Volume",
13822                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
13823                                                               HDA_OUTPUT));
13824                         if (err < 0)
13825                                 return err;
13826                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
13827                                           "LFE Playback Volume",
13828                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
13829                                                               HDA_OUTPUT));
13830                         if (err < 0)
13831                                 return err;
13832                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13833                                           "Center Playback Switch",
13834                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
13835                                                               HDA_INPUT));
13836                         if (err < 0)
13837                                 return err;
13838                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13839                                           "LFE Playback Switch",
13840                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
13841                                                               HDA_INPUT));
13842                         if (err < 0)
13843                                 return err;
13844                 } else {
13845                         sprintf(name, "%s Playback Volume", chname[i]);
13846                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
13847                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
13848                                                               HDA_OUTPUT));
13849                         if (err < 0)
13850                                 return err;
13851                         sprintf(name, "%s Playback Switch", chname[i]);
13852                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
13853                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
13854                                                               HDA_INPUT));
13855                         if (err < 0)
13856                                 return err;
13857                 }
13858         }
13859         return 0;
13860 }
13861
13862 /* add playback controls for speaker and HP outputs */
13863 static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
13864                                         const char *pfx)
13865 {
13866         hda_nid_t nid;
13867         int err;
13868         char name[32];
13869
13870         if (!pin)
13871                 return 0;
13872
13873         if (alc880_is_fixed_pin(pin)) {
13874                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
13875                 /* printk("DAC nid=%x\n",nid); */
13876                 /* specify the DAC as the extra output */
13877                 if (!spec->multiout.hp_nid)
13878                         spec->multiout.hp_nid = nid;
13879                 else
13880                         spec->multiout.extra_out_nid[0] = nid;
13881                 /* control HP volume/switch on the output mixer amp */
13882                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
13883                 sprintf(name, "%s Playback Volume", pfx);
13884                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
13885                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
13886                 if (err < 0)
13887                         return err;
13888                 sprintf(name, "%s Playback Switch", pfx);
13889                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
13890                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
13891                 if (err < 0)
13892                         return err;
13893         } else if (alc880_is_multi_pin(pin)) {
13894                 /* set manual connection */
13895                 /* we have only a switch on HP-out PIN */
13896                 sprintf(name, "%s Playback Switch", pfx);
13897                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
13898                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
13899                 if (err < 0)
13900                         return err;
13901         }
13902         return 0;
13903 }
13904
13905 /* create playback/capture controls for input pins */
13906 static int alc662_auto_create_analog_input_ctls(struct alc_spec *spec,
13907                                                 const struct auto_pin_cfg *cfg)
13908 {
13909         struct hda_input_mux *imux = &spec->private_imux;
13910         int i, err, idx;
13911
13912         for (i = 0; i < AUTO_PIN_LAST; i++) {
13913                 if (alc880_is_input_pin(cfg->input_pins[i])) {
13914                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
13915                         err = new_analog_input(spec, cfg->input_pins[i],
13916                                                auto_pin_cfg_labels[i],
13917                                                idx, 0x0b);
13918                         if (err < 0)
13919                                 return err;
13920                         imux->items[imux->num_items].label =
13921                                 auto_pin_cfg_labels[i];
13922                         imux->items[imux->num_items].index =
13923                                 alc880_input_pin_idx(cfg->input_pins[i]);
13924                         imux->num_items++;
13925                 }
13926         }
13927         return 0;
13928 }
13929
13930 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
13931                                               hda_nid_t nid, int pin_type,
13932                                               int dac_idx)
13933 {
13934         alc_set_pin_output(codec, nid, pin_type);
13935         /* need the manual connection? */
13936         if (alc880_is_multi_pin(nid)) {
13937                 struct alc_spec *spec = codec->spec;
13938                 int idx = alc880_multi_pin_idx(nid);
13939                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
13940                                     AC_VERB_SET_CONNECT_SEL,
13941                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
13942         }
13943 }
13944
13945 static void alc662_auto_init_multi_out(struct hda_codec *codec)
13946 {
13947         struct alc_spec *spec = codec->spec;
13948         int i;
13949
13950         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
13951         for (i = 0; i <= HDA_SIDE; i++) {
13952                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
13953                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
13954                 if (nid)
13955                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
13956                                                           i);
13957         }
13958 }
13959
13960 static void alc662_auto_init_hp_out(struct hda_codec *codec)
13961 {
13962         struct alc_spec *spec = codec->spec;
13963         hda_nid_t pin;
13964
13965         pin = spec->autocfg.hp_pins[0];
13966         if (pin) /* connect to front */
13967                 /* use dac 0 */
13968                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
13969         pin = spec->autocfg.speaker_pins[0];
13970         if (pin)
13971                 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
13972 }
13973
13974 #define alc662_is_input_pin(nid)        alc880_is_input_pin(nid)
13975 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
13976
13977 static void alc662_auto_init_analog_input(struct hda_codec *codec)
13978 {
13979         struct alc_spec *spec = codec->spec;
13980         int i;
13981
13982         for (i = 0; i < AUTO_PIN_LAST; i++) {
13983                 hda_nid_t nid = spec->autocfg.input_pins[i];
13984                 if (alc662_is_input_pin(nid)) {
13985                         snd_hda_codec_write(codec, nid, 0,
13986                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
13987                                             (i <= AUTO_PIN_FRONT_MIC ?
13988                                              PIN_VREF80 : PIN_IN));
13989                         if (nid != ALC662_PIN_CD_NID)
13990                                 snd_hda_codec_write(codec, nid, 0,
13991                                                     AC_VERB_SET_AMP_GAIN_MUTE,
13992                                                     AMP_OUT_MUTE);
13993                 }
13994         }
13995 }
13996
13997 static int alc662_parse_auto_config(struct hda_codec *codec)
13998 {
13999         struct alc_spec *spec = codec->spec;
14000         int err;
14001         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
14002
14003         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
14004                                            alc662_ignore);
14005         if (err < 0)
14006                 return err;
14007         if (!spec->autocfg.line_outs)
14008                 return 0; /* can't find valid BIOS pin config */
14009
14010         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
14011         if (err < 0)
14012                 return err;
14013         err = alc662_auto_create_multi_out_ctls(spec, &spec->autocfg);
14014         if (err < 0)
14015                 return err;
14016         err = alc662_auto_create_extra_out(spec,
14017                                            spec->autocfg.speaker_pins[0],
14018                                            "Speaker");
14019         if (err < 0)
14020                 return err;
14021         err = alc662_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
14022                                            "Headphone");
14023         if (err < 0)
14024                 return err;
14025         err = alc662_auto_create_analog_input_ctls(spec, &spec->autocfg);
14026         if (err < 0)
14027                 return err;
14028
14029         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
14030
14031         if (spec->autocfg.dig_out_pin)
14032                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
14033
14034         if (spec->kctl_alloc)
14035                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
14036
14037         spec->num_mux_defs = 1;
14038         spec->input_mux = &spec->private_imux;
14039         
14040         spec->init_verbs[spec->num_init_verbs++] = alc662_auto_init_verbs;
14041         spec->mixers[spec->num_mixers] = alc662_capture_mixer;
14042         spec->num_mixers++;
14043         return 1;
14044 }
14045
14046 /* additional initialization for auto-configuration model */
14047 static void alc662_auto_init(struct hda_codec *codec)
14048 {
14049         struct alc_spec *spec = codec->spec;
14050         alc662_auto_init_multi_out(codec);
14051         alc662_auto_init_hp_out(codec);
14052         alc662_auto_init_analog_input(codec);
14053         if (spec->unsol_event)
14054                 alc_sku_automute(codec);
14055 }
14056
14057 static int patch_alc662(struct hda_codec *codec)
14058 {
14059         struct alc_spec *spec;
14060         int err, board_config;
14061
14062         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
14063         if (!spec)
14064                 return -ENOMEM;
14065
14066         codec->spec = spec;
14067
14068         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
14069                                                   alc662_models,
14070                                                   alc662_cfg_tbl);
14071         if (board_config < 0) {
14072                 printk(KERN_INFO "hda_codec: Unknown model for ALC662, "
14073                        "trying auto-probe from BIOS...\n");
14074                 board_config = ALC662_AUTO;
14075         }
14076
14077         if (board_config == ALC662_AUTO) {
14078                 /* automatic parse from the BIOS config */
14079                 err = alc662_parse_auto_config(codec);
14080                 if (err < 0) {
14081                         alc_free(codec);
14082                         return err;
14083                 } else if (!err) {
14084                         printk(KERN_INFO
14085                                "hda_codec: Cannot set up configuration "
14086                                "from BIOS.  Using base mode...\n");
14087                         board_config = ALC662_3ST_2ch_DIG;
14088                 }
14089         }
14090
14091         if (board_config != ALC662_AUTO)
14092                 setup_preset(spec, &alc662_presets[board_config]);
14093
14094         spec->stream_name_analog = "ALC662 Analog";
14095         spec->stream_analog_playback = &alc662_pcm_analog_playback;
14096         spec->stream_analog_capture = &alc662_pcm_analog_capture;
14097
14098         spec->stream_name_digital = "ALC662 Digital";
14099         spec->stream_digital_playback = &alc662_pcm_digital_playback;
14100         spec->stream_digital_capture = &alc662_pcm_digital_capture;
14101
14102         spec->adc_nids = alc662_adc_nids;
14103         spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
14104         spec->capsrc_nids = alc662_capsrc_nids;
14105
14106         spec->vmaster_nid = 0x02;
14107
14108         codec->patch_ops = alc_patch_ops;
14109         if (board_config == ALC662_AUTO)
14110                 spec->init_hook = alc662_auto_init;
14111 #ifdef CONFIG_SND_HDA_POWER_SAVE
14112         if (!spec->loopback.amplist)
14113                 spec->loopback.amplist = alc662_loopbacks;
14114 #endif
14115
14116         return 0;
14117 }
14118
14119 /*
14120  * patch entries
14121  */
14122 struct hda_codec_preset snd_hda_preset_realtek[] = {
14123         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
14124         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
14125         { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
14126         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
14127         { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
14128         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
14129           .patch = patch_alc861 },
14130         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
14131         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
14132         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
14133         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
14134           .patch = patch_alc883 },
14135         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
14136           .patch = patch_alc662 },
14137         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
14138         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
14139         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
14140         { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
14141           .patch = patch_alc882 }, /* should be patch_alc883() in future */
14142         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
14143         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
14144         { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 },
14145         {} /* terminator */
14146 };