ALSA: hda - Consider additional capture source/selector in ALC889
[safe/jmp/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
34 #define ALC880_FRONT_EVENT              0x01
35 #define ALC880_DCVOL_EVENT              0x02
36 #define ALC880_HP_EVENT                 0x04
37 #define ALC880_MIC_EVENT                0x08
38
39 /* ALC880 board config type */
40 enum {
41         ALC880_3ST,
42         ALC880_3ST_DIG,
43         ALC880_5ST,
44         ALC880_5ST_DIG,
45         ALC880_W810,
46         ALC880_Z71V,
47         ALC880_6ST,
48         ALC880_6ST_DIG,
49         ALC880_F1734,
50         ALC880_ASUS,
51         ALC880_ASUS_DIG,
52         ALC880_ASUS_W1V,
53         ALC880_ASUS_DIG2,
54         ALC880_FUJITSU,
55         ALC880_UNIWILL_DIG,
56         ALC880_UNIWILL,
57         ALC880_UNIWILL_P53,
58         ALC880_CLEVO,
59         ALC880_TCL_S700,
60         ALC880_LG,
61         ALC880_LG_LW,
62         ALC880_MEDION_RIM,
63 #ifdef CONFIG_SND_DEBUG
64         ALC880_TEST,
65 #endif
66         ALC880_AUTO,
67         ALC880_MODEL_LAST /* last tag */
68 };
69
70 /* ALC260 models */
71 enum {
72         ALC260_BASIC,
73         ALC260_HP,
74         ALC260_HP_DC7600,
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_NEC,
104         ALC262_TOSHIBA_S06,
105         ALC262_TOSHIBA_RX1,
106         ALC262_AUTO,
107         ALC262_MODEL_LAST /* last tag */
108 };
109
110 /* ALC268 models */
111 enum {
112         ALC267_QUANTA_IL1,
113         ALC268_3ST,
114         ALC268_TOSHIBA,
115         ALC268_ACER,
116         ALC268_ACER_DMIC,
117         ALC268_ACER_ASPIRE_ONE,
118         ALC268_DELL,
119         ALC268_ZEPTO,
120 #ifdef CONFIG_SND_DEBUG
121         ALC268_TEST,
122 #endif
123         ALC268_AUTO,
124         ALC268_MODEL_LAST /* last tag */
125 };
126
127 /* ALC269 models */
128 enum {
129         ALC269_BASIC,
130         ALC269_QUANTA_FL1,
131         ALC269_ASUS_EEEPC_P703,
132         ALC269_ASUS_EEEPC_P901,
133         ALC269_FUJITSU,
134         ALC269_LIFEBOOK,
135         ALC269_AUTO,
136         ALC269_MODEL_LAST /* last tag */
137 };
138
139 /* ALC861 models */
140 enum {
141         ALC861_3ST,
142         ALC660_3ST,
143         ALC861_3ST_DIG,
144         ALC861_6ST_DIG,
145         ALC861_UNIWILL_M31,
146         ALC861_TOSHIBA,
147         ALC861_ASUS,
148         ALC861_ASUS_LAPTOP,
149         ALC861_AUTO,
150         ALC861_MODEL_LAST,
151 };
152
153 /* ALC861-VD models */
154 enum {
155         ALC660VD_3ST,
156         ALC660VD_3ST_DIG,
157         ALC660VD_ASUS_V1S,
158         ALC861VD_3ST,
159         ALC861VD_3ST_DIG,
160         ALC861VD_6ST_DIG,
161         ALC861VD_LENOVO,
162         ALC861VD_DALLAS,
163         ALC861VD_HP,
164         ALC861VD_AUTO,
165         ALC861VD_MODEL_LAST,
166 };
167
168 /* ALC662 models */
169 enum {
170         ALC662_3ST_2ch_DIG,
171         ALC662_3ST_6ch_DIG,
172         ALC662_3ST_6ch,
173         ALC662_5ST_DIG,
174         ALC662_LENOVO_101E,
175         ALC662_ASUS_EEEPC_P701,
176         ALC662_ASUS_EEEPC_EP20,
177         ALC663_ASUS_M51VA,
178         ALC663_ASUS_G71V,
179         ALC663_ASUS_H13,
180         ALC663_ASUS_G50V,
181         ALC662_ECS,
182         ALC663_ASUS_MODE1,
183         ALC662_ASUS_MODE2,
184         ALC663_ASUS_MODE3,
185         ALC663_ASUS_MODE4,
186         ALC663_ASUS_MODE5,
187         ALC663_ASUS_MODE6,
188         ALC662_AUTO,
189         ALC662_MODEL_LAST,
190 };
191
192 /* ALC882 models */
193 enum {
194         ALC882_3ST_DIG,
195         ALC882_6ST_DIG,
196         ALC882_ARIMA,
197         ALC882_W2JC,
198         ALC882_TARGA,
199         ALC882_ASUS_A7J,
200         ALC882_ASUS_A7M,
201         ALC885_MACPRO,
202         ALC885_MBP3,
203         ALC885_IMAC24,
204         ALC882_AUTO,
205         ALC882_MODEL_LAST,
206 };
207
208 /* ALC883 models */
209 enum {
210         ALC883_3ST_2ch_DIG,
211         ALC883_3ST_6ch_DIG,
212         ALC883_3ST_6ch,
213         ALC883_6ST_DIG,
214         ALC883_TARGA_DIG,
215         ALC883_TARGA_2ch_DIG,
216         ALC883_ACER,
217         ALC883_ACER_ASPIRE,
218         ALC888_ACER_ASPIRE_4930G,
219         ALC883_MEDION,
220         ALC883_MEDION_MD2,
221         ALC883_LAPTOP_EAPD,
222         ALC883_LENOVO_101E_2ch,
223         ALC883_LENOVO_NB0763,
224         ALC888_LENOVO_MS7195_DIG,
225         ALC888_LENOVO_SKY,
226         ALC883_HAIER_W66,
227         ALC888_3ST_HP,
228         ALC888_6ST_DELL,
229         ALC883_MITAC,
230         ALC883_CLEVO_M720,
231         ALC883_FUJITSU_PI2515,
232         ALC888_FUJITSU_XA3530,
233         ALC883_3ST_6ch_INTEL,
234         ALC888_ASUS_M90V,
235         ALC888_ASUS_EEE1601,
236         ALC1200_ASUS_P5Q,
237         ALC883_AUTO,
238         ALC883_MODEL_LAST,
239 };
240
241 /* styles of capture selection */
242 enum {
243         CAPT_MUX = 0,   /* only mux based */
244         CAPT_MIX,       /* only mixer based */
245         CAPT_1MUX_MIX,  /* first mux and other mixers */
246 };
247
248 /* for GPIO Poll */
249 #define GPIO_MASK       0x03
250
251 struct alc_spec {
252         /* codec parameterization */
253         struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
254         unsigned int num_mixers;
255         struct snd_kcontrol_new *cap_mixer;     /* capture mixer */
256
257         const struct hda_verb *init_verbs[5];   /* initialization verbs
258                                                  * don't forget NULL
259                                                  * termination!
260                                                  */
261         unsigned int num_init_verbs;
262
263         char *stream_name_analog;       /* analog PCM stream */
264         struct hda_pcm_stream *stream_analog_playback;
265         struct hda_pcm_stream *stream_analog_capture;
266         struct hda_pcm_stream *stream_analog_alt_playback;
267         struct hda_pcm_stream *stream_analog_alt_capture;
268
269         char *stream_name_digital;      /* digital PCM stream */
270         struct hda_pcm_stream *stream_digital_playback;
271         struct hda_pcm_stream *stream_digital_capture;
272
273         /* playback */
274         struct hda_multi_out multiout;  /* playback set-up
275                                          * max_channels, dacs must be set
276                                          * dig_out_nid and hp_nid are optional
277                                          */
278         hda_nid_t alt_dac_nid;
279         int dig_out_type;
280
281         /* capture */
282         unsigned int num_adc_nids;
283         hda_nid_t *adc_nids;
284         hda_nid_t *capsrc_nids;
285         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
286         int capture_style;              /* capture style (CAPT_*) */
287
288         /* capture source */
289         unsigned int num_mux_defs;
290         const struct hda_input_mux *input_mux;
291         unsigned int cur_mux[3];
292
293         /* channel model */
294         const struct hda_channel_mode *channel_mode;
295         int num_channel_mode;
296         int need_dac_fix;
297
298         /* PCM information */
299         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
300
301         /* dynamic controls, init_verbs and input_mux */
302         struct auto_pin_cfg autocfg;
303         struct snd_array kctls;
304         struct hda_input_mux private_imux[3];
305         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
306
307         /* hooks */
308         void (*init_hook)(struct hda_codec *codec);
309         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
310
311         /* for pin sensing */
312         unsigned int sense_updated: 1;
313         unsigned int jack_present: 1;
314         unsigned int master_sw: 1;
315
316         /* other flags */
317         unsigned int no_analog :1; /* digital I/O only */
318
319         /* for virtual master */
320         hda_nid_t vmaster_nid;
321 #ifdef CONFIG_SND_HDA_POWER_SAVE
322         struct hda_loopback_check loopback;
323 #endif
324
325         /* for PLL fix */
326         hda_nid_t pll_nid;
327         unsigned int pll_coef_idx, pll_coef_bit;
328
329 #ifdef SND_HDA_NEEDS_RESUME
330 #define ALC_MAX_PINS    16
331         unsigned int num_pins;
332         hda_nid_t pin_nids[ALC_MAX_PINS];
333         unsigned int pin_cfgs[ALC_MAX_PINS];
334 #endif
335 };
336
337 /*
338  * configuration template - to be copied to the spec instance
339  */
340 struct alc_config_preset {
341         struct snd_kcontrol_new *mixers[5]; /* should be identical size
342                                              * with spec
343                                              */
344         struct snd_kcontrol_new *cap_mixer; /* capture mixer */
345         const struct hda_verb *init_verbs[5];
346         unsigned int num_dacs;
347         hda_nid_t *dac_nids;
348         hda_nid_t dig_out_nid;          /* optional */
349         hda_nid_t hp_nid;               /* optional */
350         unsigned int num_adc_nids;
351         hda_nid_t *adc_nids;
352         hda_nid_t *capsrc_nids;
353         hda_nid_t dig_in_nid;
354         unsigned int num_channel_mode;
355         const struct hda_channel_mode *channel_mode;
356         int need_dac_fix;
357         unsigned int num_mux_defs;
358         const struct hda_input_mux *input_mux;
359         void (*unsol_event)(struct hda_codec *, unsigned int);
360         void (*init_hook)(struct hda_codec *);
361 #ifdef CONFIG_SND_HDA_POWER_SAVE
362         struct hda_amp_list *loopbacks;
363 #endif
364 };
365
366
367 /*
368  * input MUX handling
369  */
370 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
371                              struct snd_ctl_elem_info *uinfo)
372 {
373         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
374         struct alc_spec *spec = codec->spec;
375         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
376         if (mux_idx >= spec->num_mux_defs)
377                 mux_idx = 0;
378         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
379 }
380
381 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
382                             struct snd_ctl_elem_value *ucontrol)
383 {
384         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
385         struct alc_spec *spec = codec->spec;
386         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
387
388         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
389         return 0;
390 }
391
392 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
393                             struct snd_ctl_elem_value *ucontrol)
394 {
395         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
396         struct alc_spec *spec = codec->spec;
397         const struct hda_input_mux *imux;
398         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
399         unsigned int mux_idx;
400         hda_nid_t nid = spec->capsrc_nids ?
401                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
402
403         mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
404         imux = &spec->input_mux[mux_idx];
405
406         if (spec->capture_style &&
407             !(spec->capture_style == CAPT_1MUX_MIX && !adc_idx)) {
408                 /* Matrix-mixer style (e.g. ALC882) */
409                 unsigned int *cur_val = &spec->cur_mux[adc_idx];
410                 unsigned int i, idx;
411
412                 idx = ucontrol->value.enumerated.item[0];
413                 if (idx >= imux->num_items)
414                         idx = imux->num_items - 1;
415                 if (*cur_val == idx)
416                         return 0;
417                 for (i = 0; i < imux->num_items; i++) {
418                         unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
419                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
420                                                  imux->items[i].index,
421                                                  HDA_AMP_MUTE, v);
422                 }
423                 *cur_val = idx;
424                 return 1;
425         } else {
426                 /* MUX style (e.g. ALC880) */
427                 return snd_hda_input_mux_put(codec, imux, ucontrol, nid,
428                                              &spec->cur_mux[adc_idx]);
429         }
430 }
431
432 /*
433  * channel mode setting
434  */
435 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
436                             struct snd_ctl_elem_info *uinfo)
437 {
438         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
439         struct alc_spec *spec = codec->spec;
440         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
441                                     spec->num_channel_mode);
442 }
443
444 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
445                            struct snd_ctl_elem_value *ucontrol)
446 {
447         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
448         struct alc_spec *spec = codec->spec;
449         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
450                                    spec->num_channel_mode,
451                                    spec->multiout.max_channels);
452 }
453
454 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
455                            struct snd_ctl_elem_value *ucontrol)
456 {
457         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
458         struct alc_spec *spec = codec->spec;
459         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
460                                       spec->num_channel_mode,
461                                       &spec->multiout.max_channels);
462         if (err >= 0 && spec->need_dac_fix)
463                 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
464         return err;
465 }
466
467 /*
468  * Control the mode of pin widget settings via the mixer.  "pc" is used
469  * instead of "%" to avoid consequences of accidently treating the % as
470  * being part of a format specifier.  Maximum allowed length of a value is
471  * 63 characters plus NULL terminator.
472  *
473  * Note: some retasking pin complexes seem to ignore requests for input
474  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
475  * are requested.  Therefore order this list so that this behaviour will not
476  * cause problems when mixer clients move through the enum sequentially.
477  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
478  * March 2006.
479  */
480 static char *alc_pin_mode_names[] = {
481         "Mic 50pc bias", "Mic 80pc bias",
482         "Line in", "Line out", "Headphone out",
483 };
484 static unsigned char alc_pin_mode_values[] = {
485         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
486 };
487 /* The control can present all 5 options, or it can limit the options based
488  * in the pin being assumed to be exclusively an input or an output pin.  In
489  * addition, "input" pins may or may not process the mic bias option
490  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
491  * accept requests for bias as of chip versions up to March 2006) and/or
492  * wiring in the computer.
493  */
494 #define ALC_PIN_DIR_IN              0x00
495 #define ALC_PIN_DIR_OUT             0x01
496 #define ALC_PIN_DIR_INOUT           0x02
497 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
498 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
499
500 /* Info about the pin modes supported by the different pin direction modes.
501  * For each direction the minimum and maximum values are given.
502  */
503 static signed char alc_pin_mode_dir_info[5][2] = {
504         { 0, 2 },    /* ALC_PIN_DIR_IN */
505         { 3, 4 },    /* ALC_PIN_DIR_OUT */
506         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
507         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
508         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
509 };
510 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
511 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
512 #define alc_pin_mode_n_items(_dir) \
513         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
514
515 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
516                              struct snd_ctl_elem_info *uinfo)
517 {
518         unsigned int item_num = uinfo->value.enumerated.item;
519         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
520
521         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
522         uinfo->count = 1;
523         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
524
525         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
526                 item_num = alc_pin_mode_min(dir);
527         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
528         return 0;
529 }
530
531 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
532                             struct snd_ctl_elem_value *ucontrol)
533 {
534         unsigned int i;
535         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
536         hda_nid_t nid = kcontrol->private_value & 0xffff;
537         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
538         long *valp = ucontrol->value.integer.value;
539         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
540                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
541                                                  0x00);
542
543         /* Find enumerated value for current pinctl setting */
544         i = alc_pin_mode_min(dir);
545         while (alc_pin_mode_values[i] != pinctl && i <= alc_pin_mode_max(dir))
546                 i++;
547         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
548         return 0;
549 }
550
551 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
552                             struct snd_ctl_elem_value *ucontrol)
553 {
554         signed int change;
555         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
556         hda_nid_t nid = kcontrol->private_value & 0xffff;
557         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
558         long val = *ucontrol->value.integer.value;
559         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
560                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
561                                                  0x00);
562
563         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
564                 val = alc_pin_mode_min(dir);
565
566         change = pinctl != alc_pin_mode_values[val];
567         if (change) {
568                 /* Set pin mode to that requested */
569                 snd_hda_codec_write_cache(codec, nid, 0,
570                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
571                                           alc_pin_mode_values[val]);
572
573                 /* Also enable the retasking pin's input/output as required
574                  * for the requested pin mode.  Enum values of 2 or less are
575                  * input modes.
576                  *
577                  * Dynamically switching the input/output buffers probably
578                  * reduces noise slightly (particularly on input) so we'll
579                  * do it.  However, having both input and output buffers
580                  * enabled simultaneously doesn't seem to be problematic if
581                  * this turns out to be necessary in the future.
582                  */
583                 if (val <= 2) {
584                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
585                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
586                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
587                                                  HDA_AMP_MUTE, 0);
588                 } else {
589                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
590                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
591                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
592                                                  HDA_AMP_MUTE, 0);
593                 }
594         }
595         return change;
596 }
597
598 #define ALC_PIN_MODE(xname, nid, dir) \
599         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
600           .info = alc_pin_mode_info, \
601           .get = alc_pin_mode_get, \
602           .put = alc_pin_mode_put, \
603           .private_value = nid | (dir<<16) }
604
605 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
606  * together using a mask with more than one bit set.  This control is
607  * currently used only by the ALC260 test model.  At this stage they are not
608  * needed for any "production" models.
609  */
610 #ifdef CONFIG_SND_DEBUG
611 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
612
613 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
614                              struct snd_ctl_elem_value *ucontrol)
615 {
616         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
617         hda_nid_t nid = kcontrol->private_value & 0xffff;
618         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
619         long *valp = ucontrol->value.integer.value;
620         unsigned int val = snd_hda_codec_read(codec, nid, 0,
621                                               AC_VERB_GET_GPIO_DATA, 0x00);
622
623         *valp = (val & mask) != 0;
624         return 0;
625 }
626 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
627                              struct snd_ctl_elem_value *ucontrol)
628 {
629         signed int change;
630         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
631         hda_nid_t nid = kcontrol->private_value & 0xffff;
632         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
633         long val = *ucontrol->value.integer.value;
634         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
635                                                     AC_VERB_GET_GPIO_DATA,
636                                                     0x00);
637
638         /* Set/unset the masked GPIO bit(s) as needed */
639         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
640         if (val == 0)
641                 gpio_data &= ~mask;
642         else
643                 gpio_data |= mask;
644         snd_hda_codec_write_cache(codec, nid, 0,
645                                   AC_VERB_SET_GPIO_DATA, gpio_data);
646
647         return change;
648 }
649 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
650         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
651           .info = alc_gpio_data_info, \
652           .get = alc_gpio_data_get, \
653           .put = alc_gpio_data_put, \
654           .private_value = nid | (mask<<16) }
655 #endif   /* CONFIG_SND_DEBUG */
656
657 /* A switch control to allow the enabling of the digital IO pins on the
658  * ALC260.  This is incredibly simplistic; the intention of this control is
659  * to provide something in the test model allowing digital outputs to be
660  * identified if present.  If models are found which can utilise these
661  * outputs a more complete mixer control can be devised for those models if
662  * necessary.
663  */
664 #ifdef CONFIG_SND_DEBUG
665 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
666
667 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
668                               struct snd_ctl_elem_value *ucontrol)
669 {
670         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
671         hda_nid_t nid = kcontrol->private_value & 0xffff;
672         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
673         long *valp = ucontrol->value.integer.value;
674         unsigned int val = snd_hda_codec_read(codec, nid, 0,
675                                               AC_VERB_GET_DIGI_CONVERT_1, 0x00);
676
677         *valp = (val & mask) != 0;
678         return 0;
679 }
680 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
681                               struct snd_ctl_elem_value *ucontrol)
682 {
683         signed int change;
684         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
685         hda_nid_t nid = kcontrol->private_value & 0xffff;
686         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
687         long val = *ucontrol->value.integer.value;
688         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
689                                                     AC_VERB_GET_DIGI_CONVERT_1,
690                                                     0x00);
691
692         /* Set/unset the masked control bit(s) as needed */
693         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
694         if (val==0)
695                 ctrl_data &= ~mask;
696         else
697                 ctrl_data |= mask;
698         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
699                                   ctrl_data);
700
701         return change;
702 }
703 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
704         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
705           .info = alc_spdif_ctrl_info, \
706           .get = alc_spdif_ctrl_get, \
707           .put = alc_spdif_ctrl_put, \
708           .private_value = nid | (mask<<16) }
709 #endif   /* CONFIG_SND_DEBUG */
710
711 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
712  * Again, this is only used in the ALC26x test models to help identify when
713  * the EAPD line must be asserted for features to work.
714  */
715 #ifdef CONFIG_SND_DEBUG
716 #define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
717
718 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
719                               struct snd_ctl_elem_value *ucontrol)
720 {
721         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
722         hda_nid_t nid = kcontrol->private_value & 0xffff;
723         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
724         long *valp = ucontrol->value.integer.value;
725         unsigned int val = snd_hda_codec_read(codec, nid, 0,
726                                               AC_VERB_GET_EAPD_BTLENABLE, 0x00);
727
728         *valp = (val & mask) != 0;
729         return 0;
730 }
731
732 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
733                               struct snd_ctl_elem_value *ucontrol)
734 {
735         int change;
736         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
737         hda_nid_t nid = kcontrol->private_value & 0xffff;
738         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
739         long val = *ucontrol->value.integer.value;
740         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
741                                                     AC_VERB_GET_EAPD_BTLENABLE,
742                                                     0x00);
743
744         /* Set/unset the masked control bit(s) as needed */
745         change = (!val ? 0 : mask) != (ctrl_data & mask);
746         if (!val)
747                 ctrl_data &= ~mask;
748         else
749                 ctrl_data |= mask;
750         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
751                                   ctrl_data);
752
753         return change;
754 }
755
756 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
757         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
758           .info = alc_eapd_ctrl_info, \
759           .get = alc_eapd_ctrl_get, \
760           .put = alc_eapd_ctrl_put, \
761           .private_value = nid | (mask<<16) }
762 #endif   /* CONFIG_SND_DEBUG */
763
764 /*
765  */
766 static void add_mixer(struct alc_spec *spec, struct snd_kcontrol_new *mix)
767 {
768         if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
769                 return;
770         spec->mixers[spec->num_mixers++] = mix;
771 }
772
773 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
774 {
775         if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
776                 return;
777         spec->init_verbs[spec->num_init_verbs++] = verb;
778 }
779
780 #ifdef CONFIG_PROC_FS
781 /*
782  * hook for proc
783  */
784 static void print_realtek_coef(struct snd_info_buffer *buffer,
785                                struct hda_codec *codec, hda_nid_t nid)
786 {
787         int coeff;
788
789         if (nid != 0x20)
790                 return;
791         coeff = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PROC_COEF, 0);
792         snd_iprintf(buffer, "  Processing Coefficient: 0x%02x\n", coeff);
793         coeff = snd_hda_codec_read(codec, nid, 0,
794                                    AC_VERB_GET_COEF_INDEX, 0);
795         snd_iprintf(buffer, "  Coefficient Index: 0x%02x\n", coeff);
796 }
797 #else
798 #define print_realtek_coef      NULL
799 #endif
800
801 /*
802  * set up from the preset table
803  */
804 static void setup_preset(struct alc_spec *spec,
805                          const struct alc_config_preset *preset)
806 {
807         int i;
808
809         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
810                 add_mixer(spec, preset->mixers[i]);
811         spec->cap_mixer = preset->cap_mixer;
812         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
813              i++)
814                 add_verb(spec, preset->init_verbs[i]);
815
816         spec->channel_mode = preset->channel_mode;
817         spec->num_channel_mode = preset->num_channel_mode;
818         spec->need_dac_fix = preset->need_dac_fix;
819
820         spec->multiout.max_channels = spec->channel_mode[0].channels;
821
822         spec->multiout.num_dacs = preset->num_dacs;
823         spec->multiout.dac_nids = preset->dac_nids;
824         spec->multiout.dig_out_nid = preset->dig_out_nid;
825         spec->multiout.hp_nid = preset->hp_nid;
826
827         spec->num_mux_defs = preset->num_mux_defs;
828         if (!spec->num_mux_defs)
829                 spec->num_mux_defs = 1;
830         spec->input_mux = preset->input_mux;
831
832         spec->num_adc_nids = preset->num_adc_nids;
833         spec->adc_nids = preset->adc_nids;
834         spec->capsrc_nids = preset->capsrc_nids;
835         spec->dig_in_nid = preset->dig_in_nid;
836
837         spec->unsol_event = preset->unsol_event;
838         spec->init_hook = preset->init_hook;
839 #ifdef CONFIG_SND_HDA_POWER_SAVE
840         spec->loopback.amplist = preset->loopbacks;
841 #endif
842 }
843
844 /* Enable GPIO mask and set output */
845 static struct hda_verb alc_gpio1_init_verbs[] = {
846         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
847         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
848         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
849         { }
850 };
851
852 static struct hda_verb alc_gpio2_init_verbs[] = {
853         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
854         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
855         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
856         { }
857 };
858
859 static struct hda_verb alc_gpio3_init_verbs[] = {
860         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
861         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
862         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
863         { }
864 };
865
866 /*
867  * Fix hardware PLL issue
868  * On some codecs, the analog PLL gating control must be off while
869  * the default value is 1.
870  */
871 static void alc_fix_pll(struct hda_codec *codec)
872 {
873         struct alc_spec *spec = codec->spec;
874         unsigned int val;
875
876         if (!spec->pll_nid)
877                 return;
878         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
879                             spec->pll_coef_idx);
880         val = snd_hda_codec_read(codec, spec->pll_nid, 0,
881                                  AC_VERB_GET_PROC_COEF, 0);
882         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
883                             spec->pll_coef_idx);
884         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
885                             val & ~(1 << spec->pll_coef_bit));
886 }
887
888 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
889                              unsigned int coef_idx, unsigned int coef_bit)
890 {
891         struct alc_spec *spec = codec->spec;
892         spec->pll_nid = nid;
893         spec->pll_coef_idx = coef_idx;
894         spec->pll_coef_bit = coef_bit;
895         alc_fix_pll(codec);
896 }
897
898 static void alc_sku_automute(struct hda_codec *codec)
899 {
900         struct alc_spec *spec = codec->spec;
901         unsigned int present;
902         unsigned int hp_nid = spec->autocfg.hp_pins[0];
903         unsigned int sp_nid = spec->autocfg.speaker_pins[0];
904
905         /* need to execute and sync at first */
906         snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
907         present = snd_hda_codec_read(codec, hp_nid, 0,
908                                      AC_VERB_GET_PIN_SENSE, 0);
909         spec->jack_present = (present & 0x80000000) != 0;
910         snd_hda_codec_write(codec, sp_nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
911                             spec->jack_present ? 0 : PIN_OUT);
912 }
913
914 #if 0 /* it's broken in some acses -- temporarily disabled */
915 static void alc_mic_automute(struct hda_codec *codec)
916 {
917         struct alc_spec *spec = codec->spec;
918         unsigned int present;
919         unsigned int mic_nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
920         unsigned int fmic_nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
921         unsigned int mix_nid = spec->capsrc_nids[0];
922         unsigned int capsrc_idx_mic, capsrc_idx_fmic;
923
924         capsrc_idx_mic = mic_nid - 0x18;
925         capsrc_idx_fmic = fmic_nid - 0x18;
926         present = snd_hda_codec_read(codec, mic_nid, 0,
927                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
928         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
929                     0x7000 | (capsrc_idx_mic << 8) | (present ? 0 : 0x80));
930         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
931                     0x7000 | (capsrc_idx_fmic << 8) | (present ? 0x80 : 0));
932         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, capsrc_idx_fmic,
933                          HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
934 }
935 #else
936 #define alc_mic_automute(codec) /* NOP */
937 #endif /* disabled */
938
939 /* unsolicited event for HP jack sensing */
940 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
941 {
942         if (codec->vendor_id == 0x10ec0880)
943                 res >>= 28;
944         else
945                 res >>= 26;
946         if (res == ALC880_HP_EVENT)
947                 alc_sku_automute(codec);
948
949         if (res == ALC880_MIC_EVENT)
950                 alc_mic_automute(codec);
951 }
952
953 static void alc_inithook(struct hda_codec *codec)
954 {
955         alc_sku_automute(codec);
956         alc_mic_automute(codec);
957 }
958
959 /* additional initialization for ALC888 variants */
960 static void alc888_coef_init(struct hda_codec *codec)
961 {
962         unsigned int tmp;
963
964         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
965         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
966         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
967         if ((tmp & 0xf0) == 2)
968                 /* alc888S-VC */
969                 snd_hda_codec_read(codec, 0x20, 0,
970                                    AC_VERB_SET_PROC_COEF, 0x830);
971          else
972                  /* alc888-VB */
973                  snd_hda_codec_read(codec, 0x20, 0,
974                                     AC_VERB_SET_PROC_COEF, 0x3030);
975 }
976
977 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
978  *      31 ~ 16 :       Manufacture ID
979  *      15 ~ 8  :       SKU ID
980  *      7  ~ 0  :       Assembly ID
981  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
982  */
983 static void alc_subsystem_id(struct hda_codec *codec,
984                              unsigned int porta, unsigned int porte,
985                              unsigned int portd)
986 {
987         unsigned int ass, tmp, i;
988         unsigned nid;
989         struct alc_spec *spec = codec->spec;
990
991         ass = codec->subsystem_id & 0xffff;
992         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
993                 goto do_sku;
994
995         /*
996          * 31~30        : port conetcivity
997          * 29~21        : reserve
998          * 20           : PCBEEP input
999          * 19~16        : Check sum (15:1)
1000          * 15~1         : Custom
1001          * 0            : override
1002         */
1003         nid = 0x1d;
1004         if (codec->vendor_id == 0x10ec0260)
1005                 nid = 0x17;
1006         ass = snd_hda_codec_read(codec, nid, 0,
1007                                  AC_VERB_GET_CONFIG_DEFAULT, 0);
1008         if (!(ass & 1) && !(ass & 0x100000))
1009                 return;
1010         if ((ass >> 30) != 1)   /* no physical connection */
1011                 return;
1012
1013         /* check sum */
1014         tmp = 0;
1015         for (i = 1; i < 16; i++) {
1016                 if ((ass >> i) & 1)
1017                         tmp++;
1018         }
1019         if (((ass >> 16) & 0xf) != tmp)
1020                 return;
1021 do_sku:
1022         /*
1023          * 0 : override
1024          * 1 :  Swap Jack
1025          * 2 : 0 --> Desktop, 1 --> Laptop
1026          * 3~5 : External Amplifier control
1027          * 7~6 : Reserved
1028         */
1029         tmp = (ass & 0x38) >> 3;        /* external Amp control */
1030         switch (tmp) {
1031         case 1:
1032                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
1033                 break;
1034         case 3:
1035                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
1036                 break;
1037         case 7:
1038                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
1039                 break;
1040         case 5: /* set EAPD output high */
1041                 switch (codec->vendor_id) {
1042                 case 0x10ec0260:
1043                         snd_hda_codec_write(codec, 0x0f, 0,
1044                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1045                         snd_hda_codec_write(codec, 0x10, 0,
1046                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1047                         break;
1048                 case 0x10ec0262:
1049                 case 0x10ec0267:
1050                 case 0x10ec0268:
1051                 case 0x10ec0269:
1052                 case 0x10ec0660:
1053                 case 0x10ec0662:
1054                 case 0x10ec0663:
1055                 case 0x10ec0862:
1056                 case 0x10ec0889:
1057                         snd_hda_codec_write(codec, 0x14, 0,
1058                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1059                         snd_hda_codec_write(codec, 0x15, 0,
1060                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1061                         break;
1062                 }
1063                 switch (codec->vendor_id) {
1064                 case 0x10ec0260:
1065                         snd_hda_codec_write(codec, 0x1a, 0,
1066                                             AC_VERB_SET_COEF_INDEX, 7);
1067                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
1068                                                  AC_VERB_GET_PROC_COEF, 0);
1069                         snd_hda_codec_write(codec, 0x1a, 0,
1070                                             AC_VERB_SET_COEF_INDEX, 7);
1071                         snd_hda_codec_write(codec, 0x1a, 0,
1072                                             AC_VERB_SET_PROC_COEF,
1073                                             tmp | 0x2010);
1074                         break;
1075                 case 0x10ec0262:
1076                 case 0x10ec0880:
1077                 case 0x10ec0882:
1078                 case 0x10ec0883:
1079                 case 0x10ec0885:
1080                 case 0x10ec0889:
1081                         snd_hda_codec_write(codec, 0x20, 0,
1082                                             AC_VERB_SET_COEF_INDEX, 7);
1083                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1084                                                  AC_VERB_GET_PROC_COEF, 0);
1085                         snd_hda_codec_write(codec, 0x20, 0,
1086                                             AC_VERB_SET_COEF_INDEX, 7);
1087                         snd_hda_codec_write(codec, 0x20, 0,
1088                                             AC_VERB_SET_PROC_COEF,
1089                                             tmp | 0x2010);
1090                         break;
1091                 case 0x10ec0888:
1092                         /*alc888_coef_init(codec);*/ /* called in alc_init() */
1093                         break;
1094                 case 0x10ec0267:
1095                 case 0x10ec0268:
1096                         snd_hda_codec_write(codec, 0x20, 0,
1097                                             AC_VERB_SET_COEF_INDEX, 7);
1098                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1099                                                  AC_VERB_GET_PROC_COEF, 0);
1100                         snd_hda_codec_write(codec, 0x20, 0,
1101                                             AC_VERB_SET_COEF_INDEX, 7);
1102                         snd_hda_codec_write(codec, 0x20, 0,
1103                                             AC_VERB_SET_PROC_COEF,
1104                                             tmp | 0x3000);
1105                         break;
1106                 }
1107         default:
1108                 break;
1109         }
1110
1111         /* is laptop or Desktop and enable the function "Mute internal speaker
1112          * when the external headphone out jack is plugged"
1113          */
1114         if (!(ass & 0x8000))
1115                 return;
1116         /*
1117          * 10~8 : Jack location
1118          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1119          * 14~13: Resvered
1120          * 15   : 1 --> enable the function "Mute internal speaker
1121          *              when the external headphone out jack is plugged"
1122          */
1123         if (!spec->autocfg.speaker_pins[0]) {
1124                 if (spec->autocfg.line_out_pins[0])
1125                         spec->autocfg.speaker_pins[0] =
1126                                 spec->autocfg.line_out_pins[0];
1127                 else
1128                         return;
1129         }
1130
1131         if (!spec->autocfg.hp_pins[0]) {
1132                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
1133                 if (tmp == 0)
1134                         spec->autocfg.hp_pins[0] = porta;
1135                 else if (tmp == 1)
1136                         spec->autocfg.hp_pins[0] = porte;
1137                 else if (tmp == 2)
1138                         spec->autocfg.hp_pins[0] = portd;
1139                 else
1140                         return;
1141         }
1142         if (spec->autocfg.hp_pins[0])
1143                 snd_hda_codec_write(codec, spec->autocfg.hp_pins[0], 0,
1144                         AC_VERB_SET_UNSOLICITED_ENABLE,
1145                         AC_USRSP_EN | ALC880_HP_EVENT);
1146
1147 #if 0 /* it's broken in some acses -- temporarily disabled */
1148         if (spec->autocfg.input_pins[AUTO_PIN_MIC] &&
1149                 spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC])
1150                 snd_hda_codec_write(codec,
1151                         spec->autocfg.input_pins[AUTO_PIN_MIC], 0,
1152                         AC_VERB_SET_UNSOLICITED_ENABLE,
1153                         AC_USRSP_EN | ALC880_MIC_EVENT);
1154 #endif /* disabled */
1155
1156         spec->unsol_event = alc_sku_unsol_event;
1157 }
1158
1159 /*
1160  * Fix-up pin default configurations
1161  */
1162
1163 struct alc_pincfg {
1164         hda_nid_t nid;
1165         u32 val;
1166 };
1167
1168 static void alc_fix_pincfg(struct hda_codec *codec,
1169                            const struct snd_pci_quirk *quirk,
1170                            const struct alc_pincfg **pinfix)
1171 {
1172         const struct alc_pincfg *cfg;
1173
1174         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1175         if (!quirk)
1176                 return;
1177
1178         cfg = pinfix[quirk->value];
1179         for (; cfg->nid; cfg++) {
1180                 int i;
1181                 u32 val = cfg->val;
1182                 for (i = 0; i < 4; i++) {
1183                         snd_hda_codec_write(codec, cfg->nid, 0,
1184                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0 + i,
1185                                     val & 0xff);
1186                         val >>= 8;
1187                 }
1188         }
1189 }
1190
1191 /*
1192  * ALC888
1193  */
1194
1195 /*
1196  * 2ch mode
1197  */
1198 static struct hda_verb alc888_4ST_ch2_intel_init[] = {
1199 /* Mic-in jack as mic in */
1200         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1201         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1202 /* Line-in jack as Line in */
1203         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1204         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1205 /* Line-Out as Front */
1206         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1207         { } /* end */
1208 };
1209
1210 /*
1211  * 4ch mode
1212  */
1213 static struct hda_verb alc888_4ST_ch4_intel_init[] = {
1214 /* Mic-in jack as mic in */
1215         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1216         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1217 /* Line-in jack as Surround */
1218         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1219         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1220 /* Line-Out as Front */
1221         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1222         { } /* end */
1223 };
1224
1225 /*
1226  * 6ch mode
1227  */
1228 static struct hda_verb alc888_4ST_ch6_intel_init[] = {
1229 /* Mic-in jack as CLFE */
1230         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1231         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1232 /* Line-in jack as Surround */
1233         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1234         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1235 /* Line-Out as CLFE (workaround because Mic-in is not loud enough) */
1236         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1237         { } /* end */
1238 };
1239
1240 /*
1241  * 8ch mode
1242  */
1243 static struct hda_verb alc888_4ST_ch8_intel_init[] = {
1244 /* Mic-in jack as CLFE */
1245         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1246         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1247 /* Line-in jack as Surround */
1248         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1249         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1250 /* Line-Out as Side */
1251         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1252         { } /* end */
1253 };
1254
1255 static struct hda_channel_mode alc888_4ST_8ch_intel_modes[4] = {
1256         { 2, alc888_4ST_ch2_intel_init },
1257         { 4, alc888_4ST_ch4_intel_init },
1258         { 6, alc888_4ST_ch6_intel_init },
1259         { 8, alc888_4ST_ch8_intel_init },
1260 };
1261
1262 /*
1263  * ALC888 Fujitsu Siemens Amillo xa3530
1264  */
1265
1266 static struct hda_verb alc888_fujitsu_xa3530_verbs[] = {
1267 /* Front Mic: set to PIN_IN (empty by default) */
1268         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1269 /* Connect Internal HP to Front */
1270         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1271         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1272         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1273 /* Connect Bass HP to Front */
1274         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1275         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1276         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1277 /* Connect Line-Out side jack (SPDIF) to Side */
1278         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1279         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1280         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1281 /* Connect Mic jack to CLFE */
1282         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1283         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1284         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
1285 /* Connect Line-in jack to Surround */
1286         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1287         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1288         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
1289 /* Connect HP out jack to Front */
1290         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1291         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1292         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1293 /* Enable unsolicited event for HP jack and Line-out jack */
1294         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1295         {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1296         {}
1297 };
1298
1299 static void alc888_fujitsu_xa3530_automute(struct hda_codec *codec)
1300 {
1301         unsigned int present;
1302         unsigned int bits;
1303         /* Line out presence */
1304         present = snd_hda_codec_read(codec, 0x17, 0,
1305                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1306         /* HP out presence */
1307         present = present || snd_hda_codec_read(codec, 0x1b, 0,
1308                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1309         bits = present ? HDA_AMP_MUTE : 0;
1310         /* Toggle internal speakers muting */
1311         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
1312                                  HDA_AMP_MUTE, bits);
1313         /* Toggle internal bass muting */
1314         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
1315                                  HDA_AMP_MUTE, bits);
1316 }
1317
1318 static void alc888_fujitsu_xa3530_unsol_event(struct hda_codec *codec,
1319                 unsigned int res)
1320 {
1321         if (res >> 26 == ALC880_HP_EVENT)
1322                 alc888_fujitsu_xa3530_automute(codec);
1323 }
1324
1325
1326 /*
1327  * ALC888 Acer Aspire 4930G model
1328  */
1329
1330 static struct hda_verb alc888_acer_aspire_4930g_verbs[] = {
1331 /* Front Mic: set to PIN_IN (empty by default) */
1332         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1333 /* Unselect Front Mic by default in input mixer 3 */
1334         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1335 /* Enable unsolicited event for HP jack */
1336         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1337 /* Connect Internal HP to front */
1338         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1339         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1340         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1341 /* Connect HP out to front */
1342         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1343         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1344         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1345         { }
1346 };
1347
1348 static struct hda_input_mux alc888_2_capture_sources[2] = {
1349         /* Front mic only available on one ADC */
1350         {
1351                 .num_items = 4,
1352                 .items = {
1353                         { "Mic", 0x0 },
1354                         { "Line", 0x2 },
1355                         { "CD", 0x4 },
1356                         { "Front Mic", 0xb },
1357                 },
1358         },
1359         {
1360                 .num_items = 3,
1361                 .items = {
1362                         { "Mic", 0x0 },
1363                         { "Line", 0x2 },
1364                         { "CD", 0x4 },
1365                 },
1366         }
1367 };
1368
1369 static struct snd_kcontrol_new alc888_base_mixer[] = {
1370         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1371         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1372         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1373         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1374         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
1375                 HDA_OUTPUT),
1376         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1377         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1378         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1379         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1380         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1381         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1382         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1383         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1384         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1385         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1386         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
1387         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1388         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1389         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1390         { } /* end */
1391 };
1392
1393 static void alc888_acer_aspire_4930g_automute(struct hda_codec *codec)
1394 {
1395         unsigned int present;
1396         unsigned int bits;
1397         present = snd_hda_codec_read(codec, 0x15, 0,
1398                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1399         bits = present ? HDA_AMP_MUTE : 0;
1400         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
1401                                  HDA_AMP_MUTE, bits);
1402 }
1403
1404 static void alc888_acer_aspire_4930g_unsol_event(struct hda_codec *codec,
1405                 unsigned int res)
1406 {
1407         if (res >> 26 == ALC880_HP_EVENT)
1408                 alc888_acer_aspire_4930g_automute(codec);
1409 }
1410
1411 /*
1412  * ALC880 3-stack model
1413  *
1414  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
1415  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
1416  *                 F-Mic = 0x1b, HP = 0x19
1417  */
1418
1419 static hda_nid_t alc880_dac_nids[4] = {
1420         /* front, rear, clfe, rear_surr */
1421         0x02, 0x05, 0x04, 0x03
1422 };
1423
1424 static hda_nid_t alc880_adc_nids[3] = {
1425         /* ADC0-2 */
1426         0x07, 0x08, 0x09,
1427 };
1428
1429 /* The datasheet says the node 0x07 is connected from inputs,
1430  * but it shows zero connection in the real implementation on some devices.
1431  * Note: this is a 915GAV bug, fixed on 915GLV
1432  */
1433 static hda_nid_t alc880_adc_nids_alt[2] = {
1434         /* ADC1-2 */
1435         0x08, 0x09,
1436 };
1437
1438 #define ALC880_DIGOUT_NID       0x06
1439 #define ALC880_DIGIN_NID        0x0a
1440
1441 static struct hda_input_mux alc880_capture_source = {
1442         .num_items = 4,
1443         .items = {
1444                 { "Mic", 0x0 },
1445                 { "Front Mic", 0x3 },
1446                 { "Line", 0x2 },
1447                 { "CD", 0x4 },
1448         },
1449 };
1450
1451 /* channel source setting (2/6 channel selection for 3-stack) */
1452 /* 2ch mode */
1453 static struct hda_verb alc880_threestack_ch2_init[] = {
1454         /* set line-in to input, mute it */
1455         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1456         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1457         /* set mic-in to input vref 80%, mute it */
1458         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1459         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1460         { } /* end */
1461 };
1462
1463 /* 6ch mode */
1464 static struct hda_verb alc880_threestack_ch6_init[] = {
1465         /* set line-in to output, unmute it */
1466         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1467         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1468         /* set mic-in to output, unmute it */
1469         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1470         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1471         { } /* end */
1472 };
1473
1474 static struct hda_channel_mode alc880_threestack_modes[2] = {
1475         { 2, alc880_threestack_ch2_init },
1476         { 6, alc880_threestack_ch6_init },
1477 };
1478
1479 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1480         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1481         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1482         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1483         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1484         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1485         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1486         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1487         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1488         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1489         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1490         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1491         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1492         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1493         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1494         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
1495         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
1496         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1497         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1498         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
1499         {
1500                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1501                 .name = "Channel Mode",
1502                 .info = alc_ch_mode_info,
1503                 .get = alc_ch_mode_get,
1504                 .put = alc_ch_mode_put,
1505         },
1506         { } /* end */
1507 };
1508
1509 /* capture mixer elements */
1510 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1511                             struct snd_ctl_elem_info *uinfo)
1512 {
1513         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1514         struct alc_spec *spec = codec->spec;
1515         int err;
1516
1517         mutex_lock(&codec->control_mutex);
1518         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1519                                                       HDA_INPUT);
1520         err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1521         mutex_unlock(&codec->control_mutex);
1522         return err;
1523 }
1524
1525 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1526                            unsigned int size, unsigned int __user *tlv)
1527 {
1528         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1529         struct alc_spec *spec = codec->spec;
1530         int err;
1531
1532         mutex_lock(&codec->control_mutex);
1533         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1534                                                       HDA_INPUT);
1535         err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1536         mutex_unlock(&codec->control_mutex);
1537         return err;
1538 }
1539
1540 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1541                              struct snd_ctl_elem_value *ucontrol);
1542
1543 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1544                                  struct snd_ctl_elem_value *ucontrol,
1545                                  getput_call_t func)
1546 {
1547         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1548         struct alc_spec *spec = codec->spec;
1549         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1550         int err;
1551
1552         mutex_lock(&codec->control_mutex);
1553         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[adc_idx],
1554                                                       3, 0, HDA_INPUT);
1555         err = func(kcontrol, ucontrol);
1556         mutex_unlock(&codec->control_mutex);
1557         return err;
1558 }
1559
1560 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1561                            struct snd_ctl_elem_value *ucontrol)
1562 {
1563         return alc_cap_getput_caller(kcontrol, ucontrol,
1564                                      snd_hda_mixer_amp_volume_get);
1565 }
1566
1567 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1568                            struct snd_ctl_elem_value *ucontrol)
1569 {
1570         return alc_cap_getput_caller(kcontrol, ucontrol,
1571                                      snd_hda_mixer_amp_volume_put);
1572 }
1573
1574 /* capture mixer elements */
1575 #define alc_cap_sw_info         snd_ctl_boolean_stereo_info
1576
1577 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1578                           struct snd_ctl_elem_value *ucontrol)
1579 {
1580         return alc_cap_getput_caller(kcontrol, ucontrol,
1581                                      snd_hda_mixer_amp_switch_get);
1582 }
1583
1584 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1585                           struct snd_ctl_elem_value *ucontrol)
1586 {
1587         return alc_cap_getput_caller(kcontrol, ucontrol,
1588                                      snd_hda_mixer_amp_switch_put);
1589 }
1590
1591 #define DEFINE_CAPMIX(num) \
1592 static struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1593         { \
1594                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1595                 .name = "Capture Switch", \
1596                 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1597                 .count = num, \
1598                 .info = alc_cap_sw_info, \
1599                 .get = alc_cap_sw_get, \
1600                 .put = alc_cap_sw_put, \
1601         }, \
1602         { \
1603                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1604                 .name = "Capture Volume", \
1605                 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1606                            SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1607                            SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1608                 .count = num, \
1609                 .info = alc_cap_vol_info, \
1610                 .get = alc_cap_vol_get, \
1611                 .put = alc_cap_vol_put, \
1612                 .tlv = { .c = alc_cap_vol_tlv }, \
1613         }, \
1614         { \
1615                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1616                 /* .name = "Capture Source", */ \
1617                 .name = "Input Source", \
1618                 .count = num, \
1619                 .info = alc_mux_enum_info, \
1620                 .get = alc_mux_enum_get, \
1621                 .put = alc_mux_enum_put, \
1622         }, \
1623         { } /* end */ \
1624 }
1625
1626 /* up to three ADCs */
1627 DEFINE_CAPMIX(1);
1628 DEFINE_CAPMIX(2);
1629 DEFINE_CAPMIX(3);
1630
1631
1632 /*
1633  * ALC880 5-stack model
1634  *
1635  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
1636  *      Side = 0x02 (0xd)
1637  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
1638  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
1639  */
1640
1641 /* additional mixers to alc880_three_stack_mixer */
1642 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
1643         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1644         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
1645         { } /* end */
1646 };
1647
1648 /* channel source setting (6/8 channel selection for 5-stack) */
1649 /* 6ch mode */
1650 static struct hda_verb alc880_fivestack_ch6_init[] = {
1651         /* set line-in to input, mute it */
1652         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1653         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1654         { } /* end */
1655 };
1656
1657 /* 8ch mode */
1658 static struct hda_verb alc880_fivestack_ch8_init[] = {
1659         /* set line-in to output, unmute it */
1660         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1661         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1662         { } /* end */
1663 };
1664
1665 static struct hda_channel_mode alc880_fivestack_modes[2] = {
1666         { 6, alc880_fivestack_ch6_init },
1667         { 8, alc880_fivestack_ch8_init },
1668 };
1669
1670
1671 /*
1672  * ALC880 6-stack model
1673  *
1674  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
1675  *      Side = 0x05 (0x0f)
1676  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
1677  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
1678  */
1679
1680 static hda_nid_t alc880_6st_dac_nids[4] = {
1681         /* front, rear, clfe, rear_surr */
1682         0x02, 0x03, 0x04, 0x05
1683 };
1684
1685 static struct hda_input_mux alc880_6stack_capture_source = {
1686         .num_items = 4,
1687         .items = {
1688                 { "Mic", 0x0 },
1689                 { "Front Mic", 0x1 },
1690                 { "Line", 0x2 },
1691                 { "CD", 0x4 },
1692         },
1693 };
1694
1695 /* fixed 8-channels */
1696 static struct hda_channel_mode alc880_sixstack_modes[1] = {
1697         { 8, NULL },
1698 };
1699
1700 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
1701         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1702         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1703         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1704         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1705         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1706         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1707         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1708         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1709         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1710         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1711         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1712         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1713         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1714         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1715         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1716         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1717         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1718         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1719         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1720         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1721         {
1722                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1723                 .name = "Channel Mode",
1724                 .info = alc_ch_mode_info,
1725                 .get = alc_ch_mode_get,
1726                 .put = alc_ch_mode_put,
1727         },
1728         { } /* end */
1729 };
1730
1731
1732 /*
1733  * ALC880 W810 model
1734  *
1735  * W810 has rear IO for:
1736  * Front (DAC 02)
1737  * Surround (DAC 03)
1738  * Center/LFE (DAC 04)
1739  * Digital out (06)
1740  *
1741  * The system also has a pair of internal speakers, and a headphone jack.
1742  * These are both connected to Line2 on the codec, hence to DAC 02.
1743  *
1744  * There is a variable resistor to control the speaker or headphone
1745  * volume. This is a hardware-only device without a software API.
1746  *
1747  * Plugging headphones in will disable the internal speakers. This is
1748  * implemented in hardware, not via the driver using jack sense. In
1749  * a similar fashion, plugging into the rear socket marked "front" will
1750  * disable both the speakers and headphones.
1751  *
1752  * For input, there's a microphone jack, and an "audio in" jack.
1753  * These may not do anything useful with this driver yet, because I
1754  * haven't setup any initialization verbs for these yet...
1755  */
1756
1757 static hda_nid_t alc880_w810_dac_nids[3] = {
1758         /* front, rear/surround, clfe */
1759         0x02, 0x03, 0x04
1760 };
1761
1762 /* fixed 6 channels */
1763 static struct hda_channel_mode alc880_w810_modes[1] = {
1764         { 6, NULL }
1765 };
1766
1767 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
1768 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
1769         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1770         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1771         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1772         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1773         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1774         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1775         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1776         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1777         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1778         { } /* end */
1779 };
1780
1781
1782 /*
1783  * Z710V model
1784  *
1785  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
1786  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
1787  *                 Line = 0x1a
1788  */
1789
1790 static hda_nid_t alc880_z71v_dac_nids[1] = {
1791         0x02
1792 };
1793 #define ALC880_Z71V_HP_DAC      0x03
1794
1795 /* fixed 2 channels */
1796 static struct hda_channel_mode alc880_2_jack_modes[1] = {
1797         { 2, NULL }
1798 };
1799
1800 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
1801         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1802         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1803         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1804         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
1805         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1806         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1807         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1808         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1809         { } /* end */
1810 };
1811
1812
1813 /*
1814  * ALC880 F1734 model
1815  *
1816  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
1817  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
1818  */
1819
1820 static hda_nid_t alc880_f1734_dac_nids[1] = {
1821         0x03
1822 };
1823 #define ALC880_F1734_HP_DAC     0x02
1824
1825 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
1826         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1827         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1828         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1829         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1830         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1831         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1832         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1833         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1834         { } /* end */
1835 };
1836
1837 static struct hda_input_mux alc880_f1734_capture_source = {
1838         .num_items = 2,
1839         .items = {
1840                 { "Mic", 0x1 },
1841                 { "CD", 0x4 },
1842         },
1843 };
1844
1845
1846 /*
1847  * ALC880 ASUS model
1848  *
1849  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1850  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1851  *  Mic = 0x18, Line = 0x1a
1852  */
1853
1854 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
1855 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
1856
1857 static struct snd_kcontrol_new alc880_asus_mixer[] = {
1858         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1859         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1860         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1861         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1862         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1863         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1864         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1865         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1866         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1867         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1868         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1869         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1870         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1871         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1872         {
1873                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1874                 .name = "Channel Mode",
1875                 .info = alc_ch_mode_info,
1876                 .get = alc_ch_mode_get,
1877                 .put = alc_ch_mode_put,
1878         },
1879         { } /* end */
1880 };
1881
1882 /*
1883  * ALC880 ASUS W1V model
1884  *
1885  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1886  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1887  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
1888  */
1889
1890 /* additional mixers to alc880_asus_mixer */
1891 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
1892         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
1893         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
1894         { } /* end */
1895 };
1896
1897 /* additional mixers to alc880_asus_mixer */
1898 static struct snd_kcontrol_new alc880_pcbeep_mixer[] = {
1899         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1900         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1901         { } /* end */
1902 };
1903
1904 /* TCL S700 */
1905 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
1906         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1907         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1908         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1909         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
1910         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
1911         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
1912         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
1913         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1914         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1915         { } /* end */
1916 };
1917
1918 /* Uniwill */
1919 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
1920         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1921         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1922         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1923         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1924         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1925         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1926         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1927         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1928         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1929         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1930         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1931         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1932         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1933         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1934         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1935         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1936         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1937         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1938         {
1939                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1940                 .name = "Channel Mode",
1941                 .info = alc_ch_mode_info,
1942                 .get = alc_ch_mode_get,
1943                 .put = alc_ch_mode_put,
1944         },
1945         { } /* end */
1946 };
1947
1948 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
1949         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1950         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1951         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1952         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1953         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1954         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1955         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1956         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1957         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1958         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1959         { } /* end */
1960 };
1961
1962 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
1963         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1964         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1965         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1966         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1967         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1968         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1969         { } /* end */
1970 };
1971
1972 /*
1973  * virtual master controls
1974  */
1975
1976 /*
1977  * slave controls for virtual master
1978  */
1979 static const char *alc_slave_vols[] = {
1980         "Front Playback Volume",
1981         "Surround Playback Volume",
1982         "Center Playback Volume",
1983         "LFE Playback Volume",
1984         "Side Playback Volume",
1985         "Headphone Playback Volume",
1986         "Speaker Playback Volume",
1987         "Mono Playback Volume",
1988         "Line-Out Playback Volume",
1989         "PCM Playback Volume",
1990         NULL,
1991 };
1992
1993 static const char *alc_slave_sws[] = {
1994         "Front Playback Switch",
1995         "Surround Playback Switch",
1996         "Center Playback Switch",
1997         "LFE Playback Switch",
1998         "Side Playback Switch",
1999         "Headphone Playback Switch",
2000         "Speaker Playback Switch",
2001         "Mono Playback Switch",
2002         "IEC958 Playback Switch",
2003         NULL,
2004 };
2005
2006 /*
2007  * build control elements
2008  */
2009
2010 static void alc_free_kctls(struct hda_codec *codec);
2011
2012 static int alc_build_controls(struct hda_codec *codec)
2013 {
2014         struct alc_spec *spec = codec->spec;
2015         int err;
2016         int i;
2017
2018         for (i = 0; i < spec->num_mixers; i++) {
2019                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
2020                 if (err < 0)
2021                         return err;
2022         }
2023         if (spec->cap_mixer) {
2024                 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
2025                 if (err < 0)
2026                         return err;
2027         }
2028         if (spec->multiout.dig_out_nid) {
2029                 err = snd_hda_create_spdif_out_ctls(codec,
2030                                                     spec->multiout.dig_out_nid);
2031                 if (err < 0)
2032                         return err;
2033                 if (!spec->no_analog) {
2034                         err = snd_hda_create_spdif_share_sw(codec,
2035                                                             &spec->multiout);
2036                         if (err < 0)
2037                                 return err;
2038                         spec->multiout.share_spdif = 1;
2039                 }
2040         }
2041         if (spec->dig_in_nid) {
2042                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
2043                 if (err < 0)
2044                         return err;
2045         }
2046
2047         /* if we have no master control, let's create it */
2048         if (!spec->no_analog &&
2049             !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
2050                 unsigned int vmaster_tlv[4];
2051                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
2052                                         HDA_OUTPUT, vmaster_tlv);
2053                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
2054                                           vmaster_tlv, alc_slave_vols);
2055                 if (err < 0)
2056                         return err;
2057         }
2058         if (!spec->no_analog &&
2059             !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
2060                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
2061                                           NULL, alc_slave_sws);
2062                 if (err < 0)
2063                         return err;
2064         }
2065
2066         alc_free_kctls(codec); /* no longer needed */
2067         return 0;
2068 }
2069
2070
2071 /*
2072  * initialize the codec volumes, etc
2073  */
2074
2075 /*
2076  * generic initialization of ADC, input mixers and output mixers
2077  */
2078 static struct hda_verb alc880_volume_init_verbs[] = {
2079         /*
2080          * Unmute ADC0-2 and set the default input to mic-in
2081          */
2082         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2083         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2084         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2085         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2086         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2087         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2088
2089         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2090          * mixer widget
2091          * Note: PASD motherboards uses the Line In 2 as the input for front
2092          * panel mic (mic 2)
2093          */
2094         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
2095         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2096         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2097         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2098         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2099         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2100         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2101         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2102
2103         /*
2104          * Set up output mixers (0x0c - 0x0f)
2105          */
2106         /* set vol=0 to output mixers */
2107         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2108         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2109         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2110         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2111         /* set up input amps for analog loopback */
2112         /* Amp Indices: DAC = 0, mixer = 1 */
2113         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2114         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2115         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2116         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2117         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2118         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2119         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2120         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2121
2122         { }
2123 };
2124
2125 /*
2126  * 3-stack pin configuration:
2127  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
2128  */
2129 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
2130         /*
2131          * preset connection lists of input pins
2132          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2133          */
2134         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2135         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2136         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2137
2138         /*
2139          * Set pin mode and muting
2140          */
2141         /* set front pin widgets 0x14 for output */
2142         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2143         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2144         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2145         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2146         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2147         /* Mic2 (as headphone out) for HP output */
2148         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2149         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2150         /* Line In pin widget for input */
2151         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2152         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2153         /* Line2 (as front mic) pin widget for input and vref at 80% */
2154         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2155         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2156         /* CD pin widget for input */
2157         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2158
2159         { }
2160 };
2161
2162 /*
2163  * 5-stack pin configuration:
2164  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
2165  * line-in/side = 0x1a, f-mic = 0x1b
2166  */
2167 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
2168         /*
2169          * preset connection lists of input pins
2170          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2171          */
2172         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2173         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
2174
2175         /*
2176          * Set pin mode and muting
2177          */
2178         /* set pin widgets 0x14-0x17 for output */
2179         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2180         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2181         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2182         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2183         /* unmute pins for output (no gain on this amp) */
2184         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2185         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2186         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2187         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2188
2189         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2190         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2191         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2192         /* Mic2 (as headphone out) for HP output */
2193         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2194         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2195         /* Line In pin widget for input */
2196         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2197         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2198         /* Line2 (as front mic) pin widget for input and vref at 80% */
2199         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2200         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2201         /* CD pin widget for input */
2202         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2203
2204         { }
2205 };
2206
2207 /*
2208  * W810 pin configuration:
2209  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
2210  */
2211 static struct hda_verb alc880_pin_w810_init_verbs[] = {
2212         /* hphone/speaker input selector: front DAC */
2213         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
2214
2215         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2216         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2217         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2218         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2219         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2220         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2221
2222         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2223         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2224
2225         { }
2226 };
2227
2228 /*
2229  * Z71V pin configuration:
2230  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
2231  */
2232 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
2233         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2234         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2235         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2236         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2237
2238         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2239         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2240         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2241         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2242
2243         { }
2244 };
2245
2246 /*
2247  * 6-stack pin configuration:
2248  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
2249  * f-mic = 0x19, line = 0x1a, HP = 0x1b
2250  */
2251 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
2252         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2253
2254         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2255         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2256         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2257         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2258         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2259         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2260         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2261         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2262
2263         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2264         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2265         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2266         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2267         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2268         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2269         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2270         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2271         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2272
2273         { }
2274 };
2275
2276 /*
2277  * Uniwill pin configuration:
2278  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
2279  * line = 0x1a
2280  */
2281 static struct hda_verb alc880_uniwill_init_verbs[] = {
2282         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2283
2284         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2285         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2286         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2287         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2288         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2289         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2290         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2291         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2292         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2293         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2294         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2295         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2296         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2297         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2298
2299         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2300         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2301         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2302         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2303         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2304         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2305         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
2306         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
2307         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2308
2309         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2310         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
2311
2312         { }
2313 };
2314
2315 /*
2316 * Uniwill P53
2317 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19,
2318  */
2319 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
2320         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2321
2322         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2323         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2324         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2325         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2326         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2327         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2328         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2329         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2330         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2331         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2332         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2333         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2334
2335         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2336         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2337         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2338         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2339         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2340         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2341
2342         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2343         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
2344
2345         { }
2346 };
2347
2348 static struct hda_verb alc880_beep_init_verbs[] = {
2349         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
2350         { }
2351 };
2352
2353 /* toggle speaker-output according to the hp-jack state */
2354 static void alc880_uniwill_hp_automute(struct hda_codec *codec)
2355 {
2356         unsigned int present;
2357         unsigned char bits;
2358
2359         present = snd_hda_codec_read(codec, 0x14, 0,
2360                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2361         bits = present ? HDA_AMP_MUTE : 0;
2362         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
2363                                  HDA_AMP_MUTE, bits);
2364         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
2365                                  HDA_AMP_MUTE, bits);
2366 }
2367
2368 /* auto-toggle front mic */
2369 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
2370 {
2371         unsigned int present;
2372         unsigned char bits;
2373
2374         present = snd_hda_codec_read(codec, 0x18, 0,
2375                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2376         bits = present ? HDA_AMP_MUTE : 0;
2377         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
2378 }
2379
2380 static void alc880_uniwill_automute(struct hda_codec *codec)
2381 {
2382         alc880_uniwill_hp_automute(codec);
2383         alc880_uniwill_mic_automute(codec);
2384 }
2385
2386 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
2387                                        unsigned int res)
2388 {
2389         /* Looks like the unsol event is incompatible with the standard
2390          * definition.  4bit tag is placed at 28 bit!
2391          */
2392         switch (res >> 28) {
2393         case ALC880_HP_EVENT:
2394                 alc880_uniwill_hp_automute(codec);
2395                 break;
2396         case ALC880_MIC_EVENT:
2397                 alc880_uniwill_mic_automute(codec);
2398                 break;
2399         }
2400 }
2401
2402 static void alc880_uniwill_p53_hp_automute(struct hda_codec *codec)
2403 {
2404         unsigned int present;
2405         unsigned char bits;
2406
2407         present = snd_hda_codec_read(codec, 0x14, 0,
2408                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2409         bits = present ? HDA_AMP_MUTE : 0;
2410         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, HDA_AMP_MUTE, bits);
2411 }
2412
2413 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
2414 {
2415         unsigned int present;
2416
2417         present = snd_hda_codec_read(codec, 0x21, 0,
2418                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
2419         present &= HDA_AMP_VOLMASK;
2420         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
2421                                  HDA_AMP_VOLMASK, present);
2422         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
2423                                  HDA_AMP_VOLMASK, present);
2424 }
2425
2426 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
2427                                            unsigned int res)
2428 {
2429         /* Looks like the unsol event is incompatible with the standard
2430          * definition.  4bit tag is placed at 28 bit!
2431          */
2432         if ((res >> 28) == ALC880_HP_EVENT)
2433                 alc880_uniwill_p53_hp_automute(codec);
2434         if ((res >> 28) == ALC880_DCVOL_EVENT)
2435                 alc880_uniwill_p53_dcvol_automute(codec);
2436 }
2437
2438 /*
2439  * F1734 pin configuration:
2440  * HP = 0x14, speaker-out = 0x15, mic = 0x18
2441  */
2442 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
2443         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
2444         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2445         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2446         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2447         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2448
2449         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2450         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2451         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2452         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2453
2454         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2455         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2456         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
2457         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2458         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2459         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2460         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2461         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2462         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2463
2464         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
2465         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
2466
2467         { }
2468 };
2469
2470 /*
2471  * ASUS pin configuration:
2472  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
2473  */
2474 static struct hda_verb alc880_pin_asus_init_verbs[] = {
2475         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2476         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2477         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2478         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2479
2480         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2481         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2482         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2483         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2484         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2485         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2486         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2487         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2488
2489         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2490         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2491         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2492         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2493         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2494         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2495         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2496         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2497         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2498
2499         { }
2500 };
2501
2502 /* Enable GPIO mask and set output */
2503 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
2504 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
2505
2506 /* Clevo m520g init */
2507 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
2508         /* headphone output */
2509         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2510         /* line-out */
2511         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2512         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2513         /* Line-in */
2514         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2515         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2516         /* CD */
2517         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2518         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2519         /* Mic1 (rear panel) */
2520         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2521         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2522         /* Mic2 (front panel) */
2523         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2524         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2525         /* headphone */
2526         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2527         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2528         /* change to EAPD mode */
2529         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2530         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2531
2532         { }
2533 };
2534
2535 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
2536         /* change to EAPD mode */
2537         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2538         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2539
2540         /* Headphone output */
2541         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2542         /* Front output*/
2543         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2544         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2545
2546         /* Line In pin widget for input */
2547         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2548         /* CD pin widget for input */
2549         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2550         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2551         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2552
2553         /* change to EAPD mode */
2554         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2555         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
2556
2557         { }
2558 };
2559
2560 /*
2561  * LG m1 express dual
2562  *
2563  * Pin assignment:
2564  *   Rear Line-In/Out (blue): 0x14
2565  *   Build-in Mic-In: 0x15
2566  *   Speaker-out: 0x17
2567  *   HP-Out (green): 0x1b
2568  *   Mic-In/Out (red): 0x19
2569  *   SPDIF-Out: 0x1e
2570  */
2571
2572 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
2573 static hda_nid_t alc880_lg_dac_nids[3] = {
2574         0x05, 0x02, 0x03
2575 };
2576
2577 /* seems analog CD is not working */
2578 static struct hda_input_mux alc880_lg_capture_source = {
2579         .num_items = 3,
2580         .items = {
2581                 { "Mic", 0x1 },
2582                 { "Line", 0x5 },
2583                 { "Internal Mic", 0x6 },
2584         },
2585 };
2586
2587 /* 2,4,6 channel modes */
2588 static struct hda_verb alc880_lg_ch2_init[] = {
2589         /* set line-in and mic-in to input */
2590         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2591         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2592         { }
2593 };
2594
2595 static struct hda_verb alc880_lg_ch4_init[] = {
2596         /* set line-in to out and mic-in to input */
2597         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2598         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2599         { }
2600 };
2601
2602 static struct hda_verb alc880_lg_ch6_init[] = {
2603         /* set line-in and mic-in to output */
2604         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2605         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2606         { }
2607 };
2608
2609 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
2610         { 2, alc880_lg_ch2_init },
2611         { 4, alc880_lg_ch4_init },
2612         { 6, alc880_lg_ch6_init },
2613 };
2614
2615 static struct snd_kcontrol_new alc880_lg_mixer[] = {
2616         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2617         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
2618         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2619         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
2620         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
2621         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
2622         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
2623         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
2624         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2625         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2626         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
2627         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
2628         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
2629         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
2630         {
2631                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2632                 .name = "Channel Mode",
2633                 .info = alc_ch_mode_info,
2634                 .get = alc_ch_mode_get,
2635                 .put = alc_ch_mode_put,
2636         },
2637         { } /* end */
2638 };
2639
2640 static struct hda_verb alc880_lg_init_verbs[] = {
2641         /* set capture source to mic-in */
2642         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2643         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2644         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2645         /* mute all amp mixer inputs */
2646         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
2647         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2648         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2649         /* line-in to input */
2650         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2651         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2652         /* built-in mic */
2653         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2654         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2655         /* speaker-out */
2656         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2657         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2658         /* mic-in to input */
2659         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2660         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2661         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2662         /* HP-out */
2663         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
2664         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2665         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2666         /* jack sense */
2667         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2668         { }
2669 };
2670
2671 /* toggle speaker-output according to the hp-jack state */
2672 static void alc880_lg_automute(struct hda_codec *codec)
2673 {
2674         unsigned int present;
2675         unsigned char bits;
2676
2677         present = snd_hda_codec_read(codec, 0x1b, 0,
2678                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2679         bits = present ? HDA_AMP_MUTE : 0;
2680         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
2681                                  HDA_AMP_MUTE, bits);
2682 }
2683
2684 static void alc880_lg_unsol_event(struct hda_codec *codec, unsigned int res)
2685 {
2686         /* Looks like the unsol event is incompatible with the standard
2687          * definition.  4bit tag is placed at 28 bit!
2688          */
2689         if ((res >> 28) == 0x01)
2690                 alc880_lg_automute(codec);
2691 }
2692
2693 /*
2694  * LG LW20
2695  *
2696  * Pin assignment:
2697  *   Speaker-out: 0x14
2698  *   Mic-In: 0x18
2699  *   Built-in Mic-In: 0x19
2700  *   Line-In: 0x1b
2701  *   HP-Out: 0x1a
2702  *   SPDIF-Out: 0x1e
2703  */
2704
2705 static struct hda_input_mux alc880_lg_lw_capture_source = {
2706         .num_items = 3,
2707         .items = {
2708                 { "Mic", 0x0 },
2709                 { "Internal Mic", 0x1 },
2710                 { "Line In", 0x2 },
2711         },
2712 };
2713
2714 #define alc880_lg_lw_modes alc880_threestack_modes
2715
2716 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
2717         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2718         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2719         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2720         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
2721         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2722         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2723         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2724         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2725         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2726         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2727         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2728         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2729         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
2730         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
2731         {
2732                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2733                 .name = "Channel Mode",
2734                 .info = alc_ch_mode_info,
2735                 .get = alc_ch_mode_get,
2736                 .put = alc_ch_mode_put,
2737         },
2738         { } /* end */
2739 };
2740
2741 static struct hda_verb alc880_lg_lw_init_verbs[] = {
2742         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2743         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2744         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2745
2746         /* set capture source to mic-in */
2747         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2748         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2749         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2750         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2751         /* speaker-out */
2752         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2753         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2754         /* HP-out */
2755         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2756         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2757         /* mic-in to input */
2758         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2759         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2760         /* built-in mic */
2761         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2762         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2763         /* jack sense */
2764         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2765         { }
2766 };
2767
2768 /* toggle speaker-output according to the hp-jack state */
2769 static void alc880_lg_lw_automute(struct hda_codec *codec)
2770 {
2771         unsigned int present;
2772         unsigned char bits;
2773
2774         present = snd_hda_codec_read(codec, 0x1b, 0,
2775                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2776         bits = present ? HDA_AMP_MUTE : 0;
2777         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
2778                                  HDA_AMP_MUTE, bits);
2779 }
2780
2781 static void alc880_lg_lw_unsol_event(struct hda_codec *codec, unsigned int res)
2782 {
2783         /* Looks like the unsol event is incompatible with the standard
2784          * definition.  4bit tag is placed at 28 bit!
2785          */
2786         if ((res >> 28) == 0x01)
2787                 alc880_lg_lw_automute(codec);
2788 }
2789
2790 static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
2791         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2792         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
2793         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2794         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2795         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2796         HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
2797         { } /* end */
2798 };
2799
2800 static struct hda_input_mux alc880_medion_rim_capture_source = {
2801         .num_items = 2,
2802         .items = {
2803                 { "Mic", 0x0 },
2804                 { "Internal Mic", 0x1 },
2805         },
2806 };
2807
2808 static struct hda_verb alc880_medion_rim_init_verbs[] = {
2809         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2810
2811         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2812         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2813
2814         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2815         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2816         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2817         /* Mic2 (as headphone out) for HP output */
2818         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2819         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2820         /* Internal Speaker */
2821         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2822         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2823
2824         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2825         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2826
2827         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2828         { }
2829 };
2830
2831 /* toggle speaker-output according to the hp-jack state */
2832 static void alc880_medion_rim_automute(struct hda_codec *codec)
2833 {
2834         unsigned int present;
2835         unsigned char bits;
2836
2837         present = snd_hda_codec_read(codec, 0x14, 0,
2838                                      AC_VERB_GET_PIN_SENSE, 0)
2839                 & AC_PINSENSE_PRESENCE;
2840         bits = present ? HDA_AMP_MUTE : 0;
2841         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
2842                                  HDA_AMP_MUTE, bits);
2843         if (present)
2844                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
2845         else
2846                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
2847 }
2848
2849 static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
2850                                           unsigned int res)
2851 {
2852         /* Looks like the unsol event is incompatible with the standard
2853          * definition.  4bit tag is placed at 28 bit!
2854          */
2855         if ((res >> 28) == ALC880_HP_EVENT)
2856                 alc880_medion_rim_automute(codec);
2857 }
2858
2859 #ifdef CONFIG_SND_HDA_POWER_SAVE
2860 static struct hda_amp_list alc880_loopbacks[] = {
2861         { 0x0b, HDA_INPUT, 0 },
2862         { 0x0b, HDA_INPUT, 1 },
2863         { 0x0b, HDA_INPUT, 2 },
2864         { 0x0b, HDA_INPUT, 3 },
2865         { 0x0b, HDA_INPUT, 4 },
2866         { } /* end */
2867 };
2868
2869 static struct hda_amp_list alc880_lg_loopbacks[] = {
2870         { 0x0b, HDA_INPUT, 1 },
2871         { 0x0b, HDA_INPUT, 6 },
2872         { 0x0b, HDA_INPUT, 7 },
2873         { } /* end */
2874 };
2875 #endif
2876
2877 /*
2878  * Common callbacks
2879  */
2880
2881 static int alc_init(struct hda_codec *codec)
2882 {
2883         struct alc_spec *spec = codec->spec;
2884         unsigned int i;
2885
2886         alc_fix_pll(codec);
2887         if (codec->vendor_id == 0x10ec0888)
2888                 alc888_coef_init(codec);
2889
2890         for (i = 0; i < spec->num_init_verbs; i++)
2891                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2892
2893         if (spec->init_hook)
2894                 spec->init_hook(codec);
2895
2896         return 0;
2897 }
2898
2899 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2900 {
2901         struct alc_spec *spec = codec->spec;
2902
2903         if (spec->unsol_event)
2904                 spec->unsol_event(codec, res);
2905 }
2906
2907 #ifdef CONFIG_SND_HDA_POWER_SAVE
2908 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2909 {
2910         struct alc_spec *spec = codec->spec;
2911         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2912 }
2913 #endif
2914
2915 /*
2916  * Analog playback callbacks
2917  */
2918 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
2919                                     struct hda_codec *codec,
2920                                     struct snd_pcm_substream *substream)
2921 {
2922         struct alc_spec *spec = codec->spec;
2923         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2924                                              hinfo);
2925 }
2926
2927 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2928                                        struct hda_codec *codec,
2929                                        unsigned int stream_tag,
2930                                        unsigned int format,
2931                                        struct snd_pcm_substream *substream)
2932 {
2933         struct alc_spec *spec = codec->spec;
2934         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2935                                                 stream_tag, format, substream);
2936 }
2937
2938 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2939                                        struct hda_codec *codec,
2940                                        struct snd_pcm_substream *substream)
2941 {
2942         struct alc_spec *spec = codec->spec;
2943         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2944 }
2945
2946 /*
2947  * Digital out
2948  */
2949 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2950                                         struct hda_codec *codec,
2951                                         struct snd_pcm_substream *substream)
2952 {
2953         struct alc_spec *spec = codec->spec;
2954         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2955 }
2956
2957 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2958                                            struct hda_codec *codec,
2959                                            unsigned int stream_tag,
2960                                            unsigned int format,
2961                                            struct snd_pcm_substream *substream)
2962 {
2963         struct alc_spec *spec = codec->spec;
2964         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2965                                              stream_tag, format, substream);
2966 }
2967
2968 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2969                                          struct hda_codec *codec,
2970                                          struct snd_pcm_substream *substream)
2971 {
2972         struct alc_spec *spec = codec->spec;
2973         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2974 }
2975
2976 /*
2977  * Analog capture
2978  */
2979 static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2980                                       struct hda_codec *codec,
2981                                       unsigned int stream_tag,
2982                                       unsigned int format,
2983                                       struct snd_pcm_substream *substream)
2984 {
2985         struct alc_spec *spec = codec->spec;
2986
2987         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2988                                    stream_tag, 0, format);
2989         return 0;
2990 }
2991
2992 static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2993                                       struct hda_codec *codec,
2994                                       struct snd_pcm_substream *substream)
2995 {
2996         struct alc_spec *spec = codec->spec;
2997
2998         snd_hda_codec_cleanup_stream(codec,
2999                                      spec->adc_nids[substream->number + 1]);
3000         return 0;
3001 }
3002
3003
3004 /*
3005  */
3006 static struct hda_pcm_stream alc880_pcm_analog_playback = {
3007         .substreams = 1,
3008         .channels_min = 2,
3009         .channels_max = 8,
3010         /* NID is set in alc_build_pcms */
3011         .ops = {
3012                 .open = alc880_playback_pcm_open,
3013                 .prepare = alc880_playback_pcm_prepare,
3014                 .cleanup = alc880_playback_pcm_cleanup
3015         },
3016 };
3017
3018 static struct hda_pcm_stream alc880_pcm_analog_capture = {
3019         .substreams = 1,
3020         .channels_min = 2,
3021         .channels_max = 2,
3022         /* NID is set in alc_build_pcms */
3023 };
3024
3025 static struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
3026         .substreams = 1,
3027         .channels_min = 2,
3028         .channels_max = 2,
3029         /* NID is set in alc_build_pcms */
3030 };
3031
3032 static struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
3033         .substreams = 2, /* can be overridden */
3034         .channels_min = 2,
3035         .channels_max = 2,
3036         /* NID is set in alc_build_pcms */
3037         .ops = {
3038                 .prepare = alc880_alt_capture_pcm_prepare,
3039                 .cleanup = alc880_alt_capture_pcm_cleanup
3040         },
3041 };
3042
3043 static struct hda_pcm_stream alc880_pcm_digital_playback = {
3044         .substreams = 1,
3045         .channels_min = 2,
3046         .channels_max = 2,
3047         /* NID is set in alc_build_pcms */
3048         .ops = {
3049                 .open = alc880_dig_playback_pcm_open,
3050                 .close = alc880_dig_playback_pcm_close,
3051                 .prepare = alc880_dig_playback_pcm_prepare
3052         },
3053 };
3054
3055 static struct hda_pcm_stream alc880_pcm_digital_capture = {
3056         .substreams = 1,
3057         .channels_min = 2,
3058         .channels_max = 2,
3059         /* NID is set in alc_build_pcms */
3060 };
3061
3062 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
3063 static struct hda_pcm_stream alc_pcm_null_stream = {
3064         .substreams = 0,
3065         .channels_min = 0,
3066         .channels_max = 0,
3067 };
3068
3069 static int alc_build_pcms(struct hda_codec *codec)
3070 {
3071         struct alc_spec *spec = codec->spec;
3072         struct hda_pcm *info = spec->pcm_rec;
3073         int i;
3074
3075         codec->num_pcms = 1;
3076         codec->pcm_info = info;
3077
3078         if (spec->no_analog)
3079                 goto skip_analog;
3080
3081         info->name = spec->stream_name_analog;
3082         if (spec->stream_analog_playback) {
3083                 if (snd_BUG_ON(!spec->multiout.dac_nids))
3084                         return -EINVAL;
3085                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
3086                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
3087         }
3088         if (spec->stream_analog_capture) {
3089                 if (snd_BUG_ON(!spec->adc_nids))
3090                         return -EINVAL;
3091                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
3092                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
3093         }
3094
3095         if (spec->channel_mode) {
3096                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
3097                 for (i = 0; i < spec->num_channel_mode; i++) {
3098                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
3099                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
3100                         }
3101                 }
3102         }
3103
3104  skip_analog:
3105         /* SPDIF for stream index #1 */
3106         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
3107                 codec->num_pcms = 2;
3108                 info = spec->pcm_rec + 1;
3109                 info->name = spec->stream_name_digital;
3110                 if (spec->dig_out_type)
3111                         info->pcm_type = spec->dig_out_type;
3112                 else
3113                         info->pcm_type = HDA_PCM_TYPE_SPDIF;
3114                 if (spec->multiout.dig_out_nid &&
3115                     spec->stream_digital_playback) {
3116                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
3117                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
3118                 }
3119                 if (spec->dig_in_nid &&
3120                     spec->stream_digital_capture) {
3121                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
3122                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
3123                 }
3124                 /* FIXME: do we need this for all Realtek codec models? */
3125                 codec->spdif_status_reset = 1;
3126         }
3127
3128         if (spec->no_analog)
3129                 return 0;
3130
3131         /* If the use of more than one ADC is requested for the current
3132          * model, configure a second analog capture-only PCM.
3133          */
3134         /* Additional Analaog capture for index #2 */
3135         if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
3136             (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
3137                 codec->num_pcms = 3;
3138                 info = spec->pcm_rec + 2;
3139                 info->name = spec->stream_name_analog;
3140                 if (spec->alt_dac_nid) {
3141                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3142                                 *spec->stream_analog_alt_playback;
3143                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
3144                                 spec->alt_dac_nid;
3145                 } else {
3146                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3147                                 alc_pcm_null_stream;
3148                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
3149                 }
3150                 if (spec->num_adc_nids > 1) {
3151                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3152                                 *spec->stream_analog_alt_capture;
3153                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
3154                                 spec->adc_nids[1];
3155                         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
3156                                 spec->num_adc_nids - 1;
3157                 } else {
3158                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3159                                 alc_pcm_null_stream;
3160                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
3161                 }
3162         }
3163
3164         return 0;
3165 }
3166
3167 static void alc_free_kctls(struct hda_codec *codec)
3168 {
3169         struct alc_spec *spec = codec->spec;
3170
3171         if (spec->kctls.list) {
3172                 struct snd_kcontrol_new *kctl = spec->kctls.list;
3173                 int i;
3174                 for (i = 0; i < spec->kctls.used; i++)
3175                         kfree(kctl[i].name);
3176         }
3177         snd_array_free(&spec->kctls);
3178 }
3179
3180 static void alc_free(struct hda_codec *codec)
3181 {
3182         struct alc_spec *spec = codec->spec;
3183
3184         if (!spec)
3185                 return;
3186
3187         alc_free_kctls(codec);
3188         kfree(spec);
3189         codec->spec = NULL; /* to be sure */
3190 }
3191
3192 #ifdef SND_HDA_NEEDS_RESUME
3193 static void store_pin_configs(struct hda_codec *codec)
3194 {
3195         struct alc_spec *spec = codec->spec;
3196         hda_nid_t nid, end_nid;
3197
3198         end_nid = codec->start_nid + codec->num_nodes;
3199         for (nid = codec->start_nid; nid < end_nid; nid++) {
3200                 unsigned int wid_caps = get_wcaps(codec, nid);
3201                 unsigned int wid_type =
3202                         (wid_caps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
3203                 if (wid_type != AC_WID_PIN)
3204                         continue;
3205                 if (spec->num_pins >= ARRAY_SIZE(spec->pin_nids))
3206                         break;
3207                 spec->pin_nids[spec->num_pins] = nid;
3208                 spec->pin_cfgs[spec->num_pins] =
3209                         snd_hda_codec_read(codec, nid, 0,
3210                                            AC_VERB_GET_CONFIG_DEFAULT, 0);
3211                 spec->num_pins++;
3212         }
3213 }
3214
3215 static void resume_pin_configs(struct hda_codec *codec)
3216 {
3217         struct alc_spec *spec = codec->spec;
3218         int i;
3219
3220         for (i = 0; i < spec->num_pins; i++) {
3221                 hda_nid_t pin_nid = spec->pin_nids[i];
3222                 unsigned int pin_config = spec->pin_cfgs[i];
3223                 snd_hda_codec_write(codec, pin_nid, 0,
3224                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
3225                                     pin_config & 0x000000ff);
3226                 snd_hda_codec_write(codec, pin_nid, 0,
3227                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
3228                                     (pin_config & 0x0000ff00) >> 8);
3229                 snd_hda_codec_write(codec, pin_nid, 0,
3230                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
3231                                     (pin_config & 0x00ff0000) >> 16);
3232                 snd_hda_codec_write(codec, pin_nid, 0,
3233                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
3234                                     pin_config >> 24);
3235         }
3236 }
3237
3238 static int alc_resume(struct hda_codec *codec)
3239 {
3240         resume_pin_configs(codec);
3241         codec->patch_ops.init(codec);
3242         snd_hda_codec_resume_amp(codec);
3243         snd_hda_codec_resume_cache(codec);
3244         return 0;
3245 }
3246 #else
3247 #define store_pin_configs(codec)
3248 #endif
3249
3250 /*
3251  */
3252 static struct hda_codec_ops alc_patch_ops = {
3253         .build_controls = alc_build_controls,
3254         .build_pcms = alc_build_pcms,
3255         .init = alc_init,
3256         .free = alc_free,
3257         .unsol_event = alc_unsol_event,
3258 #ifdef SND_HDA_NEEDS_RESUME
3259         .resume = alc_resume,
3260 #endif
3261 #ifdef CONFIG_SND_HDA_POWER_SAVE
3262         .check_power_status = alc_check_power_status,
3263 #endif
3264 };
3265
3266
3267 /*
3268  * Test configuration for debugging
3269  *
3270  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
3271  * enum controls.
3272  */
3273 #ifdef CONFIG_SND_DEBUG
3274 static hda_nid_t alc880_test_dac_nids[4] = {
3275         0x02, 0x03, 0x04, 0x05
3276 };
3277
3278 static struct hda_input_mux alc880_test_capture_source = {
3279         .num_items = 7,
3280         .items = {
3281                 { "In-1", 0x0 },
3282                 { "In-2", 0x1 },
3283                 { "In-3", 0x2 },
3284                 { "In-4", 0x3 },
3285                 { "CD", 0x4 },
3286                 { "Front", 0x5 },
3287                 { "Surround", 0x6 },
3288         },
3289 };
3290
3291 static struct hda_channel_mode alc880_test_modes[4] = {
3292         { 2, NULL },
3293         { 4, NULL },
3294         { 6, NULL },
3295         { 8, NULL },
3296 };
3297
3298 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
3299                                  struct snd_ctl_elem_info *uinfo)
3300 {
3301         static char *texts[] = {
3302                 "N/A", "Line Out", "HP Out",
3303                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
3304         };
3305         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3306         uinfo->count = 1;
3307         uinfo->value.enumerated.items = 8;
3308         if (uinfo->value.enumerated.item >= 8)
3309                 uinfo->value.enumerated.item = 7;
3310         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3311         return 0;
3312 }
3313
3314 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
3315                                 struct snd_ctl_elem_value *ucontrol)
3316 {
3317         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3318         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3319         unsigned int pin_ctl, item = 0;
3320
3321         pin_ctl = snd_hda_codec_read(codec, nid, 0,
3322                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3323         if (pin_ctl & AC_PINCTL_OUT_EN) {
3324                 if (pin_ctl & AC_PINCTL_HP_EN)
3325                         item = 2;
3326                 else
3327                         item = 1;
3328         } else if (pin_ctl & AC_PINCTL_IN_EN) {
3329                 switch (pin_ctl & AC_PINCTL_VREFEN) {
3330                 case AC_PINCTL_VREF_HIZ: item = 3; break;
3331                 case AC_PINCTL_VREF_50:  item = 4; break;
3332                 case AC_PINCTL_VREF_GRD: item = 5; break;
3333                 case AC_PINCTL_VREF_80:  item = 6; break;
3334                 case AC_PINCTL_VREF_100: item = 7; break;
3335                 }
3336         }
3337         ucontrol->value.enumerated.item[0] = item;
3338         return 0;
3339 }
3340
3341 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
3342                                 struct snd_ctl_elem_value *ucontrol)
3343 {
3344         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3345         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3346         static unsigned int ctls[] = {
3347                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
3348                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
3349                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
3350                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
3351                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
3352                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
3353         };
3354         unsigned int old_ctl, new_ctl;
3355
3356         old_ctl = snd_hda_codec_read(codec, nid, 0,
3357                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3358         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
3359         if (old_ctl != new_ctl) {
3360                 int val;
3361                 snd_hda_codec_write_cache(codec, nid, 0,
3362                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
3363                                           new_ctl);
3364                 val = ucontrol->value.enumerated.item[0] >= 3 ?
3365                         HDA_AMP_MUTE : 0;
3366                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3367                                          HDA_AMP_MUTE, val);
3368                 return 1;
3369         }
3370         return 0;
3371 }
3372
3373 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
3374                                  struct snd_ctl_elem_info *uinfo)
3375 {
3376         static char *texts[] = {
3377                 "Front", "Surround", "CLFE", "Side"
3378         };
3379         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3380         uinfo->count = 1;
3381         uinfo->value.enumerated.items = 4;
3382         if (uinfo->value.enumerated.item >= 4)
3383                 uinfo->value.enumerated.item = 3;
3384         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3385         return 0;
3386 }
3387
3388 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
3389                                 struct snd_ctl_elem_value *ucontrol)
3390 {
3391         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3392         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3393         unsigned int sel;
3394
3395         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
3396         ucontrol->value.enumerated.item[0] = sel & 3;
3397         return 0;
3398 }
3399
3400 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
3401                                 struct snd_ctl_elem_value *ucontrol)
3402 {
3403         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3404         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3405         unsigned int sel;
3406
3407         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
3408         if (ucontrol->value.enumerated.item[0] != sel) {
3409                 sel = ucontrol->value.enumerated.item[0] & 3;
3410                 snd_hda_codec_write_cache(codec, nid, 0,
3411                                           AC_VERB_SET_CONNECT_SEL, sel);
3412                 return 1;
3413         }
3414         return 0;
3415 }
3416
3417 #define PIN_CTL_TEST(xname,nid) {                       \
3418                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3419                         .name = xname,                 \
3420                         .info = alc_test_pin_ctl_info, \
3421                         .get = alc_test_pin_ctl_get,   \
3422                         .put = alc_test_pin_ctl_put,   \
3423                         .private_value = nid           \
3424                         }
3425
3426 #define PIN_SRC_TEST(xname,nid) {                       \
3427                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3428                         .name = xname,                 \
3429                         .info = alc_test_pin_src_info, \
3430                         .get = alc_test_pin_src_get,   \
3431                         .put = alc_test_pin_src_put,   \
3432                         .private_value = nid           \
3433                         }
3434
3435 static struct snd_kcontrol_new alc880_test_mixer[] = {
3436         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3437         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
3438         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
3439         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3440         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3441         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
3442         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
3443         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
3444         PIN_CTL_TEST("Front Pin Mode", 0x14),
3445         PIN_CTL_TEST("Surround Pin Mode", 0x15),
3446         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
3447         PIN_CTL_TEST("Side Pin Mode", 0x17),
3448         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
3449         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
3450         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
3451         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
3452         PIN_SRC_TEST("In-1 Pin Source", 0x18),
3453         PIN_SRC_TEST("In-2 Pin Source", 0x19),
3454         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
3455         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
3456         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
3457         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
3458         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
3459         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
3460         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
3461         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
3462         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
3463         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
3464         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
3465         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
3466         {
3467                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3468                 .name = "Channel Mode",
3469                 .info = alc_ch_mode_info,
3470                 .get = alc_ch_mode_get,
3471                 .put = alc_ch_mode_put,
3472         },
3473         { } /* end */
3474 };
3475
3476 static struct hda_verb alc880_test_init_verbs[] = {
3477         /* Unmute inputs of 0x0c - 0x0f */
3478         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3479         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3480         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3481         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3482         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3483         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3484         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3485         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3486         /* Vol output for 0x0c-0x0f */
3487         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3488         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3489         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3490         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3491         /* Set output pins 0x14-0x17 */
3492         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3493         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3494         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3495         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3496         /* Unmute output pins 0x14-0x17 */
3497         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3498         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3499         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3500         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3501         /* Set input pins 0x18-0x1c */
3502         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3503         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3504         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3505         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3506         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3507         /* Mute input pins 0x18-0x1b */
3508         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3509         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3510         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3511         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3512         /* ADC set up */
3513         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3514         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
3515         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3516         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
3517         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3518         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
3519         /* Analog input/passthru */
3520         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3521         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3522         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3523         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3524         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3525         { }
3526 };
3527 #endif
3528
3529 /*
3530  */
3531
3532 static const char *alc880_models[ALC880_MODEL_LAST] = {
3533         [ALC880_3ST]            = "3stack",
3534         [ALC880_TCL_S700]       = "tcl",
3535         [ALC880_3ST_DIG]        = "3stack-digout",
3536         [ALC880_CLEVO]          = "clevo",
3537         [ALC880_5ST]            = "5stack",
3538         [ALC880_5ST_DIG]        = "5stack-digout",
3539         [ALC880_W810]           = "w810",
3540         [ALC880_Z71V]           = "z71v",
3541         [ALC880_6ST]            = "6stack",
3542         [ALC880_6ST_DIG]        = "6stack-digout",
3543         [ALC880_ASUS]           = "asus",
3544         [ALC880_ASUS_W1V]       = "asus-w1v",
3545         [ALC880_ASUS_DIG]       = "asus-dig",
3546         [ALC880_ASUS_DIG2]      = "asus-dig2",
3547         [ALC880_UNIWILL_DIG]    = "uniwill",
3548         [ALC880_UNIWILL_P53]    = "uniwill-p53",
3549         [ALC880_FUJITSU]        = "fujitsu",
3550         [ALC880_F1734]          = "F1734",
3551         [ALC880_LG]             = "lg",
3552         [ALC880_LG_LW]          = "lg-lw",
3553         [ALC880_MEDION_RIM]     = "medion",
3554 #ifdef CONFIG_SND_DEBUG
3555         [ALC880_TEST]           = "test",
3556 #endif
3557         [ALC880_AUTO]           = "auto",
3558 };
3559
3560 static struct snd_pci_quirk alc880_cfg_tbl[] = {
3561         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
3562         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
3563         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
3564         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
3565         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
3566         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
3567         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
3568         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
3569         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
3570         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
3571         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
3572         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
3573         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
3574         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
3575         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
3576         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
3577         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
3578         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
3579         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
3580         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
3581         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
3582         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS P5GD1 w/SPDIF", ALC880_6ST_DIG),
3583         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
3584         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
3585         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
3586         SND_PCI_QUIRK(0x1043, 0, "ASUS", ALC880_ASUS), /* default ASUS */
3587         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
3588         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
3589         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
3590         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
3591         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
3592         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
3593         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
3594         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
3595         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
3596         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
3597         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
3598         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
3599         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
3600         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
3601         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
3602         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
3603         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
3604         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
3605         SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_MEDION_RIM),
3606         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
3607         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
3608         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
3609         SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FUJITSU),
3610         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
3611         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
3612         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
3613         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
3614         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
3615         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
3616         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
3617         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
3618         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
3619         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
3620         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
3621         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
3622         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
3623         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
3624         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
3625         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
3626         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
3627         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
3628         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
3629         SND_PCI_QUIRK(0x8086, 0, "Intel mobo", ALC880_3ST), /* default Intel */
3630         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
3631         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
3632         {}
3633 };
3634
3635 /*
3636  * ALC880 codec presets
3637  */
3638 static struct alc_config_preset alc880_presets[] = {
3639         [ALC880_3ST] = {
3640                 .mixers = { alc880_three_stack_mixer },
3641                 .init_verbs = { alc880_volume_init_verbs,
3642                                 alc880_pin_3stack_init_verbs },
3643                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3644                 .dac_nids = alc880_dac_nids,
3645                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3646                 .channel_mode = alc880_threestack_modes,
3647                 .need_dac_fix = 1,
3648                 .input_mux = &alc880_capture_source,
3649         },
3650         [ALC880_3ST_DIG] = {
3651                 .mixers = { alc880_three_stack_mixer },
3652                 .init_verbs = { alc880_volume_init_verbs,
3653                                 alc880_pin_3stack_init_verbs },
3654                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3655                 .dac_nids = alc880_dac_nids,
3656                 .dig_out_nid = ALC880_DIGOUT_NID,
3657                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3658                 .channel_mode = alc880_threestack_modes,
3659                 .need_dac_fix = 1,
3660                 .input_mux = &alc880_capture_source,
3661         },
3662         [ALC880_TCL_S700] = {
3663                 .mixers = { alc880_tcl_s700_mixer },
3664                 .init_verbs = { alc880_volume_init_verbs,
3665                                 alc880_pin_tcl_S700_init_verbs,
3666                                 alc880_gpio2_init_verbs },
3667                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3668                 .dac_nids = alc880_dac_nids,
3669                 .adc_nids = alc880_adc_nids_alt, /* FIXME: correct? */
3670                 .num_adc_nids = 1, /* single ADC */
3671                 .hp_nid = 0x03,
3672                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3673                 .channel_mode = alc880_2_jack_modes,
3674                 .input_mux = &alc880_capture_source,
3675         },
3676         [ALC880_5ST] = {
3677                 .mixers = { alc880_three_stack_mixer,
3678                             alc880_five_stack_mixer},
3679                 .init_verbs = { alc880_volume_init_verbs,
3680                                 alc880_pin_5stack_init_verbs },
3681                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3682                 .dac_nids = alc880_dac_nids,
3683                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3684                 .channel_mode = alc880_fivestack_modes,
3685                 .input_mux = &alc880_capture_source,
3686         },
3687         [ALC880_5ST_DIG] = {
3688                 .mixers = { alc880_three_stack_mixer,
3689                             alc880_five_stack_mixer },
3690                 .init_verbs = { alc880_volume_init_verbs,
3691                                 alc880_pin_5stack_init_verbs },
3692                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3693                 .dac_nids = alc880_dac_nids,
3694                 .dig_out_nid = ALC880_DIGOUT_NID,
3695                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3696                 .channel_mode = alc880_fivestack_modes,
3697                 .input_mux = &alc880_capture_source,
3698         },
3699         [ALC880_6ST] = {
3700                 .mixers = { alc880_six_stack_mixer },
3701                 .init_verbs = { alc880_volume_init_verbs,
3702                                 alc880_pin_6stack_init_verbs },
3703                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3704                 .dac_nids = alc880_6st_dac_nids,
3705                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3706                 .channel_mode = alc880_sixstack_modes,
3707                 .input_mux = &alc880_6stack_capture_source,
3708         },
3709         [ALC880_6ST_DIG] = {
3710                 .mixers = { alc880_six_stack_mixer },
3711                 .init_verbs = { alc880_volume_init_verbs,
3712                                 alc880_pin_6stack_init_verbs },
3713                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3714                 .dac_nids = alc880_6st_dac_nids,
3715                 .dig_out_nid = ALC880_DIGOUT_NID,
3716                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3717                 .channel_mode = alc880_sixstack_modes,
3718                 .input_mux = &alc880_6stack_capture_source,
3719         },
3720         [ALC880_W810] = {
3721                 .mixers = { alc880_w810_base_mixer },
3722                 .init_verbs = { alc880_volume_init_verbs,
3723                                 alc880_pin_w810_init_verbs,
3724                                 alc880_gpio2_init_verbs },
3725                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
3726                 .dac_nids = alc880_w810_dac_nids,
3727                 .dig_out_nid = ALC880_DIGOUT_NID,
3728                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3729                 .channel_mode = alc880_w810_modes,
3730                 .input_mux = &alc880_capture_source,
3731         },
3732         [ALC880_Z71V] = {
3733                 .mixers = { alc880_z71v_mixer },
3734                 .init_verbs = { alc880_volume_init_verbs,
3735                                 alc880_pin_z71v_init_verbs },
3736                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
3737                 .dac_nids = alc880_z71v_dac_nids,
3738                 .dig_out_nid = ALC880_DIGOUT_NID,
3739                 .hp_nid = 0x03,
3740                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3741                 .channel_mode = alc880_2_jack_modes,
3742                 .input_mux = &alc880_capture_source,
3743         },
3744         [ALC880_F1734] = {
3745                 .mixers = { alc880_f1734_mixer },
3746                 .init_verbs = { alc880_volume_init_verbs,
3747                                 alc880_pin_f1734_init_verbs },
3748                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
3749                 .dac_nids = alc880_f1734_dac_nids,
3750                 .hp_nid = 0x02,
3751                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3752                 .channel_mode = alc880_2_jack_modes,
3753                 .input_mux = &alc880_f1734_capture_source,
3754                 .unsol_event = alc880_uniwill_p53_unsol_event,
3755                 .init_hook = alc880_uniwill_p53_hp_automute,
3756         },
3757         [ALC880_ASUS] = {
3758                 .mixers = { alc880_asus_mixer },
3759                 .init_verbs = { alc880_volume_init_verbs,
3760                                 alc880_pin_asus_init_verbs,
3761                                 alc880_gpio1_init_verbs },
3762                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3763                 .dac_nids = alc880_asus_dac_nids,
3764                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3765                 .channel_mode = alc880_asus_modes,
3766                 .need_dac_fix = 1,
3767                 .input_mux = &alc880_capture_source,
3768         },
3769         [ALC880_ASUS_DIG] = {
3770                 .mixers = { alc880_asus_mixer },
3771                 .init_verbs = { alc880_volume_init_verbs,
3772                                 alc880_pin_asus_init_verbs,
3773                                 alc880_gpio1_init_verbs },
3774                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3775                 .dac_nids = alc880_asus_dac_nids,
3776                 .dig_out_nid = ALC880_DIGOUT_NID,
3777                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3778                 .channel_mode = alc880_asus_modes,
3779                 .need_dac_fix = 1,
3780                 .input_mux = &alc880_capture_source,
3781         },
3782         [ALC880_ASUS_DIG2] = {
3783                 .mixers = { alc880_asus_mixer },
3784                 .init_verbs = { alc880_volume_init_verbs,
3785                                 alc880_pin_asus_init_verbs,
3786                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
3787                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3788                 .dac_nids = alc880_asus_dac_nids,
3789                 .dig_out_nid = ALC880_DIGOUT_NID,
3790                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3791                 .channel_mode = alc880_asus_modes,
3792                 .need_dac_fix = 1,
3793                 .input_mux = &alc880_capture_source,
3794         },
3795         [ALC880_ASUS_W1V] = {
3796                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
3797                 .init_verbs = { alc880_volume_init_verbs,
3798                                 alc880_pin_asus_init_verbs,
3799                                 alc880_gpio1_init_verbs },
3800                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3801                 .dac_nids = alc880_asus_dac_nids,
3802                 .dig_out_nid = ALC880_DIGOUT_NID,
3803                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3804                 .channel_mode = alc880_asus_modes,
3805                 .need_dac_fix = 1,
3806                 .input_mux = &alc880_capture_source,
3807         },
3808         [ALC880_UNIWILL_DIG] = {
3809                 .mixers = { alc880_asus_mixer, alc880_pcbeep_mixer },
3810                 .init_verbs = { alc880_volume_init_verbs,
3811                                 alc880_pin_asus_init_verbs },
3812                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3813                 .dac_nids = alc880_asus_dac_nids,
3814                 .dig_out_nid = ALC880_DIGOUT_NID,
3815                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3816                 .channel_mode = alc880_asus_modes,
3817                 .need_dac_fix = 1,
3818                 .input_mux = &alc880_capture_source,
3819         },
3820         [ALC880_UNIWILL] = {
3821                 .mixers = { alc880_uniwill_mixer },
3822                 .init_verbs = { alc880_volume_init_verbs,
3823                                 alc880_uniwill_init_verbs },
3824                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3825                 .dac_nids = alc880_asus_dac_nids,
3826                 .dig_out_nid = ALC880_DIGOUT_NID,
3827                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3828                 .channel_mode = alc880_threestack_modes,
3829                 .need_dac_fix = 1,
3830                 .input_mux = &alc880_capture_source,
3831                 .unsol_event = alc880_uniwill_unsol_event,
3832                 .init_hook = alc880_uniwill_automute,
3833         },
3834         [ALC880_UNIWILL_P53] = {
3835                 .mixers = { alc880_uniwill_p53_mixer },
3836                 .init_verbs = { alc880_volume_init_verbs,
3837                                 alc880_uniwill_p53_init_verbs },
3838                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3839                 .dac_nids = alc880_asus_dac_nids,
3840                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3841                 .channel_mode = alc880_threestack_modes,
3842                 .input_mux = &alc880_capture_source,
3843                 .unsol_event = alc880_uniwill_p53_unsol_event,
3844                 .init_hook = alc880_uniwill_p53_hp_automute,
3845         },
3846         [ALC880_FUJITSU] = {
3847                 .mixers = { alc880_fujitsu_mixer,
3848                             alc880_pcbeep_mixer, },
3849                 .init_verbs = { alc880_volume_init_verbs,
3850                                 alc880_uniwill_p53_init_verbs,
3851                                 alc880_beep_init_verbs },
3852                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3853                 .dac_nids = alc880_dac_nids,
3854                 .dig_out_nid = ALC880_DIGOUT_NID,
3855                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3856                 .channel_mode = alc880_2_jack_modes,
3857                 .input_mux = &alc880_capture_source,
3858                 .unsol_event = alc880_uniwill_p53_unsol_event,
3859                 .init_hook = alc880_uniwill_p53_hp_automute,
3860         },
3861         [ALC880_CLEVO] = {
3862                 .mixers = { alc880_three_stack_mixer },
3863                 .init_verbs = { alc880_volume_init_verbs,
3864                                 alc880_pin_clevo_init_verbs },
3865                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3866                 .dac_nids = alc880_dac_nids,
3867                 .hp_nid = 0x03,
3868                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3869                 .channel_mode = alc880_threestack_modes,
3870                 .need_dac_fix = 1,
3871                 .input_mux = &alc880_capture_source,
3872         },
3873         [ALC880_LG] = {
3874                 .mixers = { alc880_lg_mixer },
3875                 .init_verbs = { alc880_volume_init_verbs,
3876                                 alc880_lg_init_verbs },
3877                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
3878                 .dac_nids = alc880_lg_dac_nids,
3879                 .dig_out_nid = ALC880_DIGOUT_NID,
3880                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
3881                 .channel_mode = alc880_lg_ch_modes,
3882                 .need_dac_fix = 1,
3883                 .input_mux = &alc880_lg_capture_source,
3884                 .unsol_event = alc880_lg_unsol_event,
3885                 .init_hook = alc880_lg_automute,
3886 #ifdef CONFIG_SND_HDA_POWER_SAVE
3887                 .loopbacks = alc880_lg_loopbacks,
3888 #endif
3889         },
3890         [ALC880_LG_LW] = {
3891                 .mixers = { alc880_lg_lw_mixer },
3892                 .init_verbs = { alc880_volume_init_verbs,
3893                                 alc880_lg_lw_init_verbs },
3894                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3895                 .dac_nids = alc880_dac_nids,
3896                 .dig_out_nid = ALC880_DIGOUT_NID,
3897                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
3898                 .channel_mode = alc880_lg_lw_modes,
3899                 .input_mux = &alc880_lg_lw_capture_source,
3900                 .unsol_event = alc880_lg_lw_unsol_event,
3901                 .init_hook = alc880_lg_lw_automute,
3902         },
3903         [ALC880_MEDION_RIM] = {
3904                 .mixers = { alc880_medion_rim_mixer },
3905                 .init_verbs = { alc880_volume_init_verbs,
3906                                 alc880_medion_rim_init_verbs,
3907                                 alc_gpio2_init_verbs },
3908                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3909                 .dac_nids = alc880_dac_nids,
3910                 .dig_out_nid = ALC880_DIGOUT_NID,
3911                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3912                 .channel_mode = alc880_2_jack_modes,
3913                 .input_mux = &alc880_medion_rim_capture_source,
3914                 .unsol_event = alc880_medion_rim_unsol_event,
3915                 .init_hook = alc880_medion_rim_automute,
3916         },
3917 #ifdef CONFIG_SND_DEBUG
3918         [ALC880_TEST] = {
3919                 .mixers = { alc880_test_mixer },
3920                 .init_verbs = { alc880_test_init_verbs },
3921                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
3922                 .dac_nids = alc880_test_dac_nids,
3923                 .dig_out_nid = ALC880_DIGOUT_NID,
3924                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
3925                 .channel_mode = alc880_test_modes,
3926                 .input_mux = &alc880_test_capture_source,
3927         },
3928 #endif
3929 };
3930
3931 /*
3932  * Automatic parse of I/O pins from the BIOS configuration
3933  */
3934
3935 enum {
3936         ALC_CTL_WIDGET_VOL,
3937         ALC_CTL_WIDGET_MUTE,
3938         ALC_CTL_BIND_MUTE,
3939 };
3940 static struct snd_kcontrol_new alc880_control_templates[] = {
3941         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
3942         HDA_CODEC_MUTE(NULL, 0, 0, 0),
3943         HDA_BIND_MUTE(NULL, 0, 0, 0),
3944 };
3945
3946 /* add dynamic controls */
3947 static int add_control(struct alc_spec *spec, int type, const char *name,
3948                        unsigned long val)
3949 {
3950         struct snd_kcontrol_new *knew;
3951
3952         snd_array_init(&spec->kctls, sizeof(*knew), 32);
3953         knew = snd_array_new(&spec->kctls);
3954         if (!knew)
3955                 return -ENOMEM;
3956         *knew = alc880_control_templates[type];
3957         knew->name = kstrdup(name, GFP_KERNEL);
3958         if (!knew->name)
3959                 return -ENOMEM;
3960         knew->private_value = val;
3961         return 0;
3962 }
3963
3964 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
3965 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
3966 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
3967 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
3968 #define alc880_is_input_pin(nid)        ((nid) >= 0x18)
3969 #define alc880_input_pin_idx(nid)       ((nid) - 0x18)
3970 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
3971 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
3972 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
3973 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
3974 #define ALC880_PIN_CD_NID               0x1c
3975
3976 /* fill in the dac_nids table from the parsed pin configuration */
3977 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
3978                                      const struct auto_pin_cfg *cfg)
3979 {
3980         hda_nid_t nid;
3981         int assigned[4];
3982         int i, j;
3983
3984         memset(assigned, 0, sizeof(assigned));
3985         spec->multiout.dac_nids = spec->private_dac_nids;
3986
3987         /* check the pins hardwired to audio widget */
3988         for (i = 0; i < cfg->line_outs; i++) {
3989                 nid = cfg->line_out_pins[i];
3990                 if (alc880_is_fixed_pin(nid)) {
3991                         int idx = alc880_fixed_pin_idx(nid);
3992                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
3993                         assigned[idx] = 1;
3994                 }
3995         }
3996         /* left pins can be connect to any audio widget */
3997         for (i = 0; i < cfg->line_outs; i++) {
3998                 nid = cfg->line_out_pins[i];
3999                 if (alc880_is_fixed_pin(nid))
4000                         continue;
4001                 /* search for an empty channel */
4002                 for (j = 0; j < cfg->line_outs; j++) {
4003                         if (!assigned[j]) {
4004                                 spec->multiout.dac_nids[i] =
4005                                         alc880_idx_to_dac(j);
4006                                 assigned[j] = 1;
4007                                 break;
4008                         }
4009                 }
4010         }
4011         spec->multiout.num_dacs = cfg->line_outs;
4012         return 0;
4013 }
4014
4015 /* add playback controls from the parsed DAC table */
4016 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
4017                                              const struct auto_pin_cfg *cfg)
4018 {
4019         char name[32];
4020         static const char *chname[4] = {
4021                 "Front", "Surround", NULL /*CLFE*/, "Side"
4022         };
4023         hda_nid_t nid;
4024         int i, err;
4025
4026         for (i = 0; i < cfg->line_outs; i++) {
4027                 if (!spec->multiout.dac_nids[i])
4028                         continue;
4029                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
4030                 if (i == 2) {
4031                         /* Center/LFE */
4032                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
4033                                           "Center Playback Volume",
4034                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
4035                                                               HDA_OUTPUT));
4036                         if (err < 0)
4037                                 return err;
4038                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
4039                                           "LFE Playback Volume",
4040                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
4041                                                               HDA_OUTPUT));
4042                         if (err < 0)
4043                                 return err;
4044                         err = add_control(spec, ALC_CTL_BIND_MUTE,
4045                                           "Center Playback Switch",
4046                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
4047                                                               HDA_INPUT));
4048                         if (err < 0)
4049                                 return err;
4050                         err = add_control(spec, ALC_CTL_BIND_MUTE,
4051                                           "LFE Playback Switch",
4052                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
4053                                                               HDA_INPUT));
4054                         if (err < 0)
4055                                 return err;
4056                 } else {
4057                         sprintf(name, "%s Playback Volume", chname[i]);
4058                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4059                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
4060                                                               HDA_OUTPUT));
4061                         if (err < 0)
4062                                 return err;
4063                         sprintf(name, "%s Playback Switch", chname[i]);
4064                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
4065                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
4066                                                               HDA_INPUT));
4067                         if (err < 0)
4068                                 return err;
4069                 }
4070         }
4071         return 0;
4072 }
4073
4074 /* add playback controls for speaker and HP outputs */
4075 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
4076                                         const char *pfx)
4077 {
4078         hda_nid_t nid;
4079         int err;
4080         char name[32];
4081
4082         if (!pin)
4083                 return 0;
4084
4085         if (alc880_is_fixed_pin(pin)) {
4086                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
4087                 /* specify the DAC as the extra output */
4088                 if (!spec->multiout.hp_nid)
4089                         spec->multiout.hp_nid = nid;
4090                 else
4091                         spec->multiout.extra_out_nid[0] = nid;
4092                 /* control HP volume/switch on the output mixer amp */
4093                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
4094                 sprintf(name, "%s Playback Volume", pfx);
4095                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4096                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
4097                 if (err < 0)
4098                         return err;
4099                 sprintf(name, "%s Playback Switch", pfx);
4100                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
4101                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
4102                 if (err < 0)
4103                         return err;
4104         } else if (alc880_is_multi_pin(pin)) {
4105                 /* set manual connection */
4106                 /* we have only a switch on HP-out PIN */
4107                 sprintf(name, "%s Playback Switch", pfx);
4108                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
4109                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4110                 if (err < 0)
4111                         return err;
4112         }
4113         return 0;
4114 }
4115
4116 /* create input playback/capture controls for the given pin */
4117 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
4118                             const char *ctlname,
4119                             int idx, hda_nid_t mix_nid)
4120 {
4121         char name[32];
4122         int err;
4123
4124         sprintf(name, "%s Playback Volume", ctlname);
4125         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4126                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4127         if (err < 0)
4128                 return err;
4129         sprintf(name, "%s Playback Switch", ctlname);
4130         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
4131                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4132         if (err < 0)
4133                 return err;
4134         return 0;
4135 }
4136
4137 /* create playback/capture controls for input pins */
4138 static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
4139                                                 const struct auto_pin_cfg *cfg)
4140 {
4141         struct hda_input_mux *imux = &spec->private_imux[0];
4142         int i, err, idx;
4143
4144         for (i = 0; i < AUTO_PIN_LAST; i++) {
4145                 if (alc880_is_input_pin(cfg->input_pins[i])) {
4146                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
4147                         err = new_analog_input(spec, cfg->input_pins[i],
4148                                                auto_pin_cfg_labels[i],
4149                                                idx, 0x0b);
4150                         if (err < 0)
4151                                 return err;
4152                         imux->items[imux->num_items].label =
4153                                 auto_pin_cfg_labels[i];
4154                         imux->items[imux->num_items].index =
4155                                 alc880_input_pin_idx(cfg->input_pins[i]);
4156                         imux->num_items++;
4157                 }
4158         }
4159         return 0;
4160 }
4161
4162 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
4163                                unsigned int pin_type)
4164 {
4165         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4166                             pin_type);
4167         /* unmute pin */
4168         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4169                             AMP_OUT_UNMUTE);
4170 }
4171
4172 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
4173                                               hda_nid_t nid, int pin_type,
4174                                               int dac_idx)
4175 {
4176         alc_set_pin_output(codec, nid, pin_type);
4177         /* need the manual connection? */
4178         if (alc880_is_multi_pin(nid)) {
4179                 struct alc_spec *spec = codec->spec;
4180                 int idx = alc880_multi_pin_idx(nid);
4181                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
4182                                     AC_VERB_SET_CONNECT_SEL,
4183                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
4184         }
4185 }
4186
4187 static int get_pin_type(int line_out_type)
4188 {
4189         if (line_out_type == AUTO_PIN_HP_OUT)
4190                 return PIN_HP;
4191         else
4192                 return PIN_OUT;
4193 }
4194
4195 static void alc880_auto_init_multi_out(struct hda_codec *codec)
4196 {
4197         struct alc_spec *spec = codec->spec;
4198         int i;
4199
4200         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
4201         for (i = 0; i < spec->autocfg.line_outs; i++) {
4202                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
4203                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
4204                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
4205         }
4206 }
4207
4208 static void alc880_auto_init_extra_out(struct hda_codec *codec)
4209 {
4210         struct alc_spec *spec = codec->spec;
4211         hda_nid_t pin;
4212
4213         pin = spec->autocfg.speaker_pins[0];
4214         if (pin) /* connect to front */
4215                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
4216         pin = spec->autocfg.hp_pins[0];
4217         if (pin) /* connect to front */
4218                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
4219 }
4220
4221 static void alc880_auto_init_analog_input(struct hda_codec *codec)
4222 {
4223         struct alc_spec *spec = codec->spec;
4224         int i;
4225
4226         for (i = 0; i < AUTO_PIN_LAST; i++) {
4227                 hda_nid_t nid = spec->autocfg.input_pins[i];
4228                 if (alc880_is_input_pin(nid)) {
4229                         snd_hda_codec_write(codec, nid, 0,
4230                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
4231                                             i <= AUTO_PIN_FRONT_MIC ?
4232                                             PIN_VREF80 : PIN_IN);
4233                         if (nid != ALC880_PIN_CD_NID)
4234                                 snd_hda_codec_write(codec, nid, 0,
4235                                                     AC_VERB_SET_AMP_GAIN_MUTE,
4236                                                     AMP_OUT_MUTE);
4237                 }
4238         }
4239 }
4240
4241 /* parse the BIOS configuration and set up the alc_spec */
4242 /* return 1 if successful, 0 if the proper config is not found,
4243  * or a negative error code
4244  */
4245 static int alc880_parse_auto_config(struct hda_codec *codec)
4246 {
4247         struct alc_spec *spec = codec->spec;
4248         int err;
4249         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4250
4251         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
4252                                            alc880_ignore);
4253         if (err < 0)
4254                 return err;
4255         if (!spec->autocfg.line_outs)
4256                 return 0; /* can't find valid BIOS pin config */
4257
4258         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
4259         if (err < 0)
4260                 return err;
4261         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
4262         if (err < 0)
4263                 return err;
4264         err = alc880_auto_create_extra_out(spec,
4265                                            spec->autocfg.speaker_pins[0],
4266                                            "Speaker");
4267         if (err < 0)
4268                 return err;
4269         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
4270                                            "Headphone");
4271         if (err < 0)
4272                 return err;
4273         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
4274         if (err < 0)
4275                 return err;
4276
4277         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4278
4279         if (spec->autocfg.dig_out_pin)
4280                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
4281         if (spec->autocfg.dig_in_pin)
4282                 spec->dig_in_nid = ALC880_DIGIN_NID;
4283
4284         if (spec->kctls.list)
4285                 add_mixer(spec, spec->kctls.list);
4286
4287         add_verb(spec, alc880_volume_init_verbs);
4288
4289         spec->num_mux_defs = 1;
4290         spec->input_mux = &spec->private_imux[0];
4291
4292         store_pin_configs(codec);
4293         return 1;
4294 }
4295
4296 /* additional initialization for auto-configuration model */
4297 static void alc880_auto_init(struct hda_codec *codec)
4298 {
4299         struct alc_spec *spec = codec->spec;
4300         alc880_auto_init_multi_out(codec);
4301         alc880_auto_init_extra_out(codec);
4302         alc880_auto_init_analog_input(codec);
4303         if (spec->unsol_event)
4304                 alc_inithook(codec);
4305 }
4306
4307 /*
4308  * OK, here we have finally the patch for ALC880
4309  */
4310
4311 static void set_capture_mixer(struct alc_spec *spec)
4312 {
4313         static struct snd_kcontrol_new *caps[3] = {
4314                 alc_capture_mixer1,
4315                 alc_capture_mixer2,
4316                 alc_capture_mixer3,
4317         };
4318         if (spec->num_adc_nids > 0 && spec->num_adc_nids <= 3)
4319                 spec->cap_mixer = caps[spec->num_adc_nids - 1];
4320 }
4321
4322 static int patch_alc880(struct hda_codec *codec)
4323 {
4324         struct alc_spec *spec;
4325         int board_config;
4326         int err;
4327
4328         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4329         if (spec == NULL)
4330                 return -ENOMEM;
4331
4332         codec->spec = spec;
4333
4334         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
4335                                                   alc880_models,
4336                                                   alc880_cfg_tbl);
4337         if (board_config < 0) {
4338                 printk(KERN_INFO "hda_codec: Unknown model for ALC880, "
4339                        "trying auto-probe from BIOS...\n");
4340                 board_config = ALC880_AUTO;
4341         }
4342
4343         if (board_config == ALC880_AUTO) {
4344                 /* automatic parse from the BIOS config */
4345                 err = alc880_parse_auto_config(codec);
4346                 if (err < 0) {
4347                         alc_free(codec);
4348                         return err;
4349                 } else if (!err) {
4350                         printk(KERN_INFO
4351                                "hda_codec: Cannot set up configuration "
4352                                "from BIOS.  Using 3-stack mode...\n");
4353                         board_config = ALC880_3ST;
4354                 }
4355         }
4356
4357         if (board_config != ALC880_AUTO)
4358                 setup_preset(spec, &alc880_presets[board_config]);
4359
4360         spec->stream_name_analog = "ALC880 Analog";
4361         spec->stream_analog_playback = &alc880_pcm_analog_playback;
4362         spec->stream_analog_capture = &alc880_pcm_analog_capture;
4363         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
4364
4365         spec->stream_name_digital = "ALC880 Digital";
4366         spec->stream_digital_playback = &alc880_pcm_digital_playback;
4367         spec->stream_digital_capture = &alc880_pcm_digital_capture;
4368
4369         if (!spec->adc_nids && spec->input_mux) {
4370                 /* check whether NID 0x07 is valid */
4371                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
4372                 /* get type */
4373                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
4374                 if (wcap != AC_WID_AUD_IN) {
4375                         spec->adc_nids = alc880_adc_nids_alt;
4376                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
4377                 } else {
4378                         spec->adc_nids = alc880_adc_nids;
4379                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
4380                 }
4381         }
4382         set_capture_mixer(spec);
4383
4384         spec->vmaster_nid = 0x0c;
4385
4386         codec->patch_ops = alc_patch_ops;
4387         if (board_config == ALC880_AUTO)
4388                 spec->init_hook = alc880_auto_init;
4389 #ifdef CONFIG_SND_HDA_POWER_SAVE
4390         if (!spec->loopback.amplist)
4391                 spec->loopback.amplist = alc880_loopbacks;
4392 #endif
4393         codec->proc_widget_hook = print_realtek_coef;
4394
4395         return 0;
4396 }
4397
4398
4399 /*
4400  * ALC260 support
4401  */
4402
4403 static hda_nid_t alc260_dac_nids[1] = {
4404         /* front */
4405         0x02,
4406 };
4407
4408 static hda_nid_t alc260_adc_nids[1] = {
4409         /* ADC0 */
4410         0x04,
4411 };
4412
4413 static hda_nid_t alc260_adc_nids_alt[1] = {
4414         /* ADC1 */
4415         0x05,
4416 };
4417
4418 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
4419  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
4420  */
4421 static hda_nid_t alc260_dual_adc_nids[2] = {
4422         /* ADC0, ADC1 */
4423         0x04, 0x05
4424 };
4425
4426 #define ALC260_DIGOUT_NID       0x03
4427 #define ALC260_DIGIN_NID        0x06
4428
4429 static struct hda_input_mux alc260_capture_source = {
4430         .num_items = 4,
4431         .items = {
4432                 { "Mic", 0x0 },
4433                 { "Front Mic", 0x1 },
4434                 { "Line", 0x2 },
4435                 { "CD", 0x4 },
4436         },
4437 };
4438
4439 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
4440  * headphone jack and the internal CD lines since these are the only pins at
4441  * which audio can appear.  For flexibility, also allow the option of
4442  * recording the mixer output on the second ADC (ADC0 doesn't have a
4443  * connection to the mixer output).
4444  */
4445 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
4446         {
4447                 .num_items = 3,
4448                 .items = {
4449                         { "Mic/Line", 0x0 },
4450                         { "CD", 0x4 },
4451                         { "Headphone", 0x2 },
4452                 },
4453         },
4454         {
4455                 .num_items = 4,
4456                 .items = {
4457                         { "Mic/Line", 0x0 },
4458                         { "CD", 0x4 },
4459                         { "Headphone", 0x2 },
4460                         { "Mixer", 0x5 },
4461                 },
4462         },
4463
4464 };
4465
4466 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
4467  * the Fujitsu S702x, but jacks are marked differently.
4468  */
4469 static struct hda_input_mux alc260_acer_capture_sources[2] = {
4470         {
4471                 .num_items = 4,
4472                 .items = {
4473                         { "Mic", 0x0 },
4474                         { "Line", 0x2 },
4475                         { "CD", 0x4 },
4476                         { "Headphone", 0x5 },
4477                 },
4478         },
4479         {
4480                 .num_items = 5,
4481                 .items = {
4482                         { "Mic", 0x0 },
4483                         { "Line", 0x2 },
4484                         { "CD", 0x4 },
4485                         { "Headphone", 0x6 },
4486                         { "Mixer", 0x5 },
4487                 },
4488         },
4489 };
4490 /*
4491  * This is just place-holder, so there's something for alc_build_pcms to look
4492  * at when it calculates the maximum number of channels. ALC260 has no mixer
4493  * element which allows changing the channel mode, so the verb list is
4494  * never used.
4495  */
4496 static struct hda_channel_mode alc260_modes[1] = {
4497         { 2, NULL },
4498 };
4499
4500
4501 /* Mixer combinations
4502  *
4503  * basic: base_output + input + pc_beep + capture
4504  * HP: base_output + input + capture_alt
4505  * HP_3013: hp_3013 + input + capture
4506  * fujitsu: fujitsu + capture
4507  * acer: acer + capture
4508  */
4509
4510 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
4511         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4512         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4513         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4514         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4515         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4516         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4517         { } /* end */
4518 };
4519
4520 static struct snd_kcontrol_new alc260_input_mixer[] = {
4521         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4522         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4523         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4524         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4525         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4526         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4527         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
4528         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
4529         { } /* end */
4530 };
4531
4532 static struct snd_kcontrol_new alc260_pc_beep_mixer[] = {
4533         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT),
4534         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT),
4535         { } /* end */
4536 };
4537
4538 /* update HP, line and mono out pins according to the master switch */
4539 static void alc260_hp_master_update(struct hda_codec *codec,
4540                                     hda_nid_t hp, hda_nid_t line,
4541                                     hda_nid_t mono)
4542 {
4543         struct alc_spec *spec = codec->spec;
4544         unsigned int val = spec->master_sw ? PIN_HP : 0;
4545         /* change HP and line-out pins */
4546         snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4547                             val);
4548         snd_hda_codec_write(codec, line, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4549                             val);
4550         /* mono (speaker) depending on the HP jack sense */
4551         val = (val && !spec->jack_present) ? PIN_OUT : 0;
4552         snd_hda_codec_write(codec, mono, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4553                             val);
4554 }
4555
4556 static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
4557                                    struct snd_ctl_elem_value *ucontrol)
4558 {
4559         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4560         struct alc_spec *spec = codec->spec;
4561         *ucontrol->value.integer.value = spec->master_sw;
4562         return 0;
4563 }
4564
4565 static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
4566                                    struct snd_ctl_elem_value *ucontrol)
4567 {
4568         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4569         struct alc_spec *spec = codec->spec;
4570         int val = !!*ucontrol->value.integer.value;
4571         hda_nid_t hp, line, mono;
4572
4573         if (val == spec->master_sw)
4574                 return 0;
4575         spec->master_sw = val;
4576         hp = (kcontrol->private_value >> 16) & 0xff;
4577         line = (kcontrol->private_value >> 8) & 0xff;
4578         mono = kcontrol->private_value & 0xff;
4579         alc260_hp_master_update(codec, hp, line, mono);
4580         return 1;
4581 }
4582
4583 static struct snd_kcontrol_new alc260_hp_output_mixer[] = {
4584         {
4585                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4586                 .name = "Master Playback Switch",
4587                 .info = snd_ctl_boolean_mono_info,
4588                 .get = alc260_hp_master_sw_get,
4589                 .put = alc260_hp_master_sw_put,
4590                 .private_value = (0x0f << 16) | (0x10 << 8) | 0x11
4591         },
4592         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4593         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4594         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4595         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4596         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4597                               HDA_OUTPUT),
4598         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4599         { } /* end */
4600 };
4601
4602 static struct hda_verb alc260_hp_unsol_verbs[] = {
4603         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4604         {},
4605 };
4606
4607 static void alc260_hp_automute(struct hda_codec *codec)
4608 {
4609         struct alc_spec *spec = codec->spec;
4610         unsigned int present;
4611
4612         present = snd_hda_codec_read(codec, 0x10, 0,
4613                                      AC_VERB_GET_PIN_SENSE, 0);
4614         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4615         alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
4616 }
4617
4618 static void alc260_hp_unsol_event(struct hda_codec *codec, unsigned int res)
4619 {
4620         if ((res >> 26) == ALC880_HP_EVENT)
4621                 alc260_hp_automute(codec);
4622 }
4623
4624 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
4625         {
4626                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4627                 .name = "Master Playback Switch",
4628                 .info = snd_ctl_boolean_mono_info,
4629                 .get = alc260_hp_master_sw_get,
4630                 .put = alc260_hp_master_sw_put,
4631                 .private_value = (0x15 << 16) | (0x10 << 8) | 0x11
4632         },
4633         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4634         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4635         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
4636         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
4637         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4638         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
4639         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4640         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
4641         { } /* end */
4642 };
4643
4644 static struct hda_bind_ctls alc260_dc7600_bind_master_vol = {
4645         .ops = &snd_hda_bind_vol,
4646         .values = {
4647                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_OUTPUT),
4648                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
4649                 HDA_COMPOSE_AMP_VAL(0x0a, 3, 0, HDA_OUTPUT),
4650                 0
4651         },
4652 };
4653
4654 static struct hda_bind_ctls alc260_dc7600_bind_switch = {
4655         .ops = &snd_hda_bind_sw,
4656         .values = {
4657                 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
4658                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
4659                 0
4660         },
4661 };
4662
4663 static struct snd_kcontrol_new alc260_hp_dc7600_mixer[] = {
4664         HDA_BIND_VOL("Master Playback Volume", &alc260_dc7600_bind_master_vol),
4665         HDA_BIND_SW("LineOut Playback Switch", &alc260_dc7600_bind_switch),
4666         HDA_CODEC_MUTE("Speaker Playback Switch", 0x0f, 0x0, HDA_OUTPUT),
4667         HDA_CODEC_MUTE("Headphone Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4668         { } /* end */
4669 };
4670
4671 static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
4672         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4673         {},
4674 };
4675
4676 static void alc260_hp_3013_automute(struct hda_codec *codec)
4677 {
4678         struct alc_spec *spec = codec->spec;
4679         unsigned int present;
4680
4681         present = snd_hda_codec_read(codec, 0x15, 0,
4682                                      AC_VERB_GET_PIN_SENSE, 0);
4683         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4684         alc260_hp_master_update(codec, 0x15, 0x10, 0x11);
4685 }
4686
4687 static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
4688                                        unsigned int res)
4689 {
4690         if ((res >> 26) == ALC880_HP_EVENT)
4691                 alc260_hp_3013_automute(codec);
4692 }
4693
4694 static void alc260_hp_3012_automute(struct hda_codec *codec)
4695 {
4696         unsigned int present, bits;
4697
4698         present = snd_hda_codec_read(codec, 0x10, 0,
4699                         AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
4700
4701         bits = present ? 0 : PIN_OUT;
4702         snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4703                             bits);
4704         snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4705                             bits);
4706         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4707                             bits);
4708 }
4709
4710 static void alc260_hp_3012_unsol_event(struct hda_codec *codec,
4711                                        unsigned int res)
4712 {
4713         if ((res >> 26) == ALC880_HP_EVENT)
4714                 alc260_hp_3012_automute(codec);
4715 }
4716
4717 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12,
4718  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
4719  */
4720 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
4721         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4722         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
4723         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4724         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4725         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4726         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
4727         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
4728         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
4729         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4730         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4731         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4732         HDA_BIND_MUTE("Speaker Playback Switch", 0x09, 2, HDA_INPUT),
4733         { } /* end */
4734 };
4735
4736 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
4737  * versions of the ALC260 don't act on requests to enable mic bias from NID
4738  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
4739  * datasheet doesn't mention this restriction.  At this stage it's not clear
4740  * whether this behaviour is intentional or is a hardware bug in chip
4741  * revisions available in early 2006.  Therefore for now allow the
4742  * "Headphone Jack Mode" control to span all choices, but if it turns out
4743  * that the lack of mic bias for this NID is intentional we could change the
4744  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4745  *
4746  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
4747  * don't appear to make the mic bias available from the "line" jack, even
4748  * though the NID used for this jack (0x14) can supply it.  The theory is
4749  * that perhaps Acer have included blocking capacitors between the ALC260
4750  * and the output jack.  If this turns out to be the case for all such
4751  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
4752  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
4753  *
4754  * The C20x Tablet series have a mono internal speaker which is controlled
4755  * via the chip's Mono sum widget and pin complex, so include the necessary
4756  * controls for such models.  On models without a "mono speaker" the control
4757  * won't do anything.
4758  */
4759 static struct snd_kcontrol_new alc260_acer_mixer[] = {
4760         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4761         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
4762         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
4763         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4764                               HDA_OUTPUT),
4765         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2,
4766                            HDA_INPUT),
4767         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4768         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4769         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4770         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4771         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4772         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4773         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4774         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4775         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4776         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4777         { } /* end */
4778 };
4779
4780 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
4781  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
4782  */
4783 static struct snd_kcontrol_new alc260_will_mixer[] = {
4784         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4785         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4786         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4787         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4788         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4789         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4790         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4791         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4792         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4793         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4794         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4795         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4796         { } /* end */
4797 };
4798
4799 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
4800  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
4801  */
4802 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
4803         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4804         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4805         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4806         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4807         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4808         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
4809         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
4810         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4811         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4812         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4813         { } /* end */
4814 };
4815
4816 /*
4817  * initialization verbs
4818  */
4819 static struct hda_verb alc260_init_verbs[] = {
4820         /* Line In pin widget for input */
4821         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4822         /* CD pin widget for input */
4823         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4824         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4825         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4826         /* Mic2 (front panel) pin widget for input and vref at 80% */
4827         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4828         /* LINE-2 is used for line-out in rear */
4829         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4830         /* select line-out */
4831         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
4832         /* LINE-OUT pin */
4833         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4834         /* enable HP */
4835         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4836         /* enable Mono */
4837         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4838         /* mute capture amp left and right */
4839         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4840         /* set connection select to line in (default select for this ADC) */
4841         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4842         /* mute capture amp left and right */
4843         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4844         /* set connection select to line in (default select for this ADC) */
4845         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
4846         /* set vol=0 Line-Out mixer amp left and right */
4847         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4848         /* unmute pin widget amp left and right (no gain on this amp) */
4849         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4850         /* set vol=0 HP mixer amp left and right */
4851         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4852         /* unmute pin widget amp left and right (no gain on this amp) */
4853         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4854         /* set vol=0 Mono mixer amp left and right */
4855         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4856         /* unmute pin widget amp left and right (no gain on this amp) */
4857         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4858         /* unmute LINE-2 out pin */
4859         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4860         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4861          * Line In 2 = 0x03
4862          */
4863         /* mute analog inputs */
4864         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4865         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4866         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4867         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4868         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4869         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4870         /* mute Front out path */
4871         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4872         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4873         /* mute Headphone out path */
4874         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4875         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4876         /* mute Mono out path */
4877         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4878         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4879         { }
4880 };
4881
4882 #if 0 /* should be identical with alc260_init_verbs? */
4883 static struct hda_verb alc260_hp_init_verbs[] = {
4884         /* Headphone and output */
4885         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4886         /* mono output */
4887         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4888         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4889         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4890         /* Mic2 (front panel) pin widget for input and vref at 80% */
4891         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4892         /* Line In pin widget for input */
4893         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4894         /* Line-2 pin widget for output */
4895         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4896         /* CD pin widget for input */
4897         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4898         /* unmute amp left and right */
4899         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4900         /* set connection select to line in (default select for this ADC) */
4901         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4902         /* unmute Line-Out mixer amp left and right (volume = 0) */
4903         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4904         /* mute pin widget amp left and right (no gain on this amp) */
4905         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4906         /* unmute HP mixer amp left and right (volume = 0) */
4907         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4908         /* mute pin widget amp left and right (no gain on this amp) */
4909         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4910         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4911          * Line In 2 = 0x03
4912          */
4913         /* mute analog inputs */
4914         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4915         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4916         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4917         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4918         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4919         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4920         /* Unmute Front out path */
4921         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4922         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4923         /* Unmute Headphone out path */
4924         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4925         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4926         /* Unmute Mono out path */
4927         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4928         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4929         { }
4930 };
4931 #endif
4932
4933 static struct hda_verb alc260_hp_3013_init_verbs[] = {
4934         /* Line out and output */
4935         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4936         /* mono output */
4937         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4938         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4939         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4940         /* Mic2 (front panel) pin widget for input and vref at 80% */
4941         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4942         /* Line In pin widget for input */
4943         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4944         /* Headphone pin widget for output */
4945         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4946         /* CD pin widget for input */
4947         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4948         /* unmute amp left and right */
4949         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4950         /* set connection select to line in (default select for this ADC) */
4951         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4952         /* unmute Line-Out mixer amp left and right (volume = 0) */
4953         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4954         /* mute pin widget amp left and right (no gain on this amp) */
4955         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4956         /* unmute HP mixer amp left and right (volume = 0) */
4957         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4958         /* mute pin widget amp left and right (no gain on this amp) */
4959         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4960         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4961          * Line In 2 = 0x03
4962          */
4963         /* mute analog inputs */
4964         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4965         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4966         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4967         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4968         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4969         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4970         /* Unmute Front out path */
4971         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4972         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4973         /* Unmute Headphone out path */
4974         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4975         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4976         /* Unmute Mono out path */
4977         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4978         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4979         { }
4980 };
4981
4982 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
4983  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
4984  * audio = 0x16, internal speaker = 0x10.
4985  */
4986 static struct hda_verb alc260_fujitsu_init_verbs[] = {
4987         /* Disable all GPIOs */
4988         {0x01, AC_VERB_SET_GPIO_MASK, 0},
4989         /* Internal speaker is connected to headphone pin */
4990         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4991         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
4992         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4993         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
4994         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4995         /* Ensure all other unused pins are disabled and muted. */
4996         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4997         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4998         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4999         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5000         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5001         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5002         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5003         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5004
5005         /* Disable digital (SPDIF) pins */
5006         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5007         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5008
5009         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus
5010          * when acting as an output.
5011          */
5012         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5013
5014         /* Start with output sum widgets muted and their output gains at min */
5015         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5016         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5017         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5018         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5019         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5020         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5021         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5022         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5023         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5024
5025         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
5026         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5027         /* Unmute Line1 pin widget output buffer since it starts as an output.
5028          * If the pin mode is changed by the user the pin mode control will
5029          * take care of enabling the pin's input/output buffers as needed.
5030          * Therefore there's no need to enable the input buffer at this
5031          * stage.
5032          */
5033         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5034         /* Unmute input buffer of pin widget used for Line-in (no equiv
5035          * mixer ctrl)
5036          */
5037         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5038
5039         /* Mute capture amp left and right */
5040         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5041         /* Set ADC connection select to match default mixer setting - line
5042          * in (on mic1 pin)
5043          */
5044         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5045
5046         /* Do the same for the second ADC: mute capture input amp and
5047          * set ADC connection to line in (on mic1 pin)
5048          */
5049         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5050         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5051
5052         /* Mute all inputs to mixer widget (even unconnected ones) */
5053         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5054         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5055         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5056         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5057         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5058         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5059         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5060         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5061
5062         { }
5063 };
5064
5065 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
5066  * similar laptops (adapted from Fujitsu init verbs).
5067  */
5068 static struct hda_verb alc260_acer_init_verbs[] = {
5069         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
5070          * the headphone jack.  Turn this on and rely on the standard mute
5071          * methods whenever the user wants to turn these outputs off.
5072          */
5073         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5074         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5075         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5076         /* Internal speaker/Headphone jack is connected to Line-out pin */
5077         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5078         /* Internal microphone/Mic jack is connected to Mic1 pin */
5079         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
5080         /* Line In jack is connected to Line1 pin */
5081         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5082         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
5083         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5084         /* Ensure all other unused pins are disabled and muted. */
5085         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5086         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5087         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5088         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5089         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5090         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5091         /* Disable digital (SPDIF) pins */
5092         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5093         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5094
5095         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
5096          * bus when acting as outputs.
5097          */
5098         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5099         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5100
5101         /* Start with output sum widgets muted and their output gains at min */
5102         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5103         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5104         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5105         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5106         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5107         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5108         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5109         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5110         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5111
5112         /* Unmute Line-out pin widget amp left and right
5113          * (no equiv mixer ctrl)
5114          */
5115         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5116         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
5117         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5118         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
5119          * inputs. If the pin mode is changed by the user the pin mode control
5120          * will take care of enabling the pin's input/output buffers as needed.
5121          * Therefore there's no need to enable the input buffer at this
5122          * stage.
5123          */
5124         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5125         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5126
5127         /* Mute capture amp left and right */
5128         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5129         /* Set ADC connection select to match default mixer setting - mic
5130          * (on mic1 pin)
5131          */
5132         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5133
5134         /* Do similar with the second ADC: mute capture input amp and
5135          * set ADC connection to mic to match ALSA's default state.
5136          */
5137         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5138         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5139
5140         /* Mute all inputs to mixer widget (even unconnected ones) */
5141         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5142         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5143         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5144         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5145         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5146         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5147         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5148         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5149
5150         { }
5151 };
5152
5153 static struct hda_verb alc260_will_verbs[] = {
5154         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5155         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
5156         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
5157         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5158         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5159         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
5160         {}
5161 };
5162
5163 static struct hda_verb alc260_replacer_672v_verbs[] = {
5164         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5165         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5166         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
5167
5168         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5169         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5170         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5171
5172         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5173         {}
5174 };
5175
5176 /* toggle speaker-output according to the hp-jack state */
5177 static void alc260_replacer_672v_automute(struct hda_codec *codec)
5178 {
5179         unsigned int present;
5180
5181         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
5182         present = snd_hda_codec_read(codec, 0x0f, 0,
5183                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5184         if (present) {
5185                 snd_hda_codec_write_cache(codec, 0x01, 0,
5186                                           AC_VERB_SET_GPIO_DATA, 1);
5187                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5188                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5189                                           PIN_HP);
5190         } else {
5191                 snd_hda_codec_write_cache(codec, 0x01, 0,
5192                                           AC_VERB_SET_GPIO_DATA, 0);
5193                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5194                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5195                                           PIN_OUT);
5196         }
5197 }
5198
5199 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
5200                                        unsigned int res)
5201 {
5202         if ((res >> 26) == ALC880_HP_EVENT)
5203                 alc260_replacer_672v_automute(codec);
5204 }
5205
5206 static struct hda_verb alc260_hp_dc7600_verbs[] = {
5207         {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
5208         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5209         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5210         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5211         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5212         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5213         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5214         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5215         {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5216         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5217         {}
5218 };
5219
5220 /* Test configuration for debugging, modelled after the ALC880 test
5221  * configuration.
5222  */
5223 #ifdef CONFIG_SND_DEBUG
5224 static hda_nid_t alc260_test_dac_nids[1] = {
5225         0x02,
5226 };
5227 static hda_nid_t alc260_test_adc_nids[2] = {
5228         0x04, 0x05,
5229 };
5230 /* For testing the ALC260, each input MUX needs its own definition since
5231  * the signal assignments are different.  This assumes that the first ADC
5232  * is NID 0x04.
5233  */
5234 static struct hda_input_mux alc260_test_capture_sources[2] = {
5235         {
5236                 .num_items = 7,
5237                 .items = {
5238                         { "MIC1 pin", 0x0 },
5239                         { "MIC2 pin", 0x1 },
5240                         { "LINE1 pin", 0x2 },
5241                         { "LINE2 pin", 0x3 },
5242                         { "CD pin", 0x4 },
5243                         { "LINE-OUT pin", 0x5 },
5244                         { "HP-OUT pin", 0x6 },
5245                 },
5246         },
5247         {
5248                 .num_items = 8,
5249                 .items = {
5250                         { "MIC1 pin", 0x0 },
5251                         { "MIC2 pin", 0x1 },
5252                         { "LINE1 pin", 0x2 },
5253                         { "LINE2 pin", 0x3 },
5254                         { "CD pin", 0x4 },
5255                         { "Mixer", 0x5 },
5256                         { "LINE-OUT pin", 0x6 },
5257                         { "HP-OUT pin", 0x7 },
5258                 },
5259         },
5260 };
5261 static struct snd_kcontrol_new alc260_test_mixer[] = {
5262         /* Output driver widgets */
5263         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
5264         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
5265         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5266         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
5267         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5268         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
5269
5270         /* Modes for retasking pin widgets
5271          * Note: the ALC260 doesn't seem to act on requests to enable mic
5272          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
5273          * mention this restriction.  At this stage it's not clear whether
5274          * this behaviour is intentional or is a hardware bug in chip
5275          * revisions available at least up until early 2006.  Therefore for
5276          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
5277          * choices, but if it turns out that the lack of mic bias for these
5278          * NIDs is intentional we could change their modes from
5279          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
5280          */
5281         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
5282         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
5283         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
5284         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
5285         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
5286         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
5287
5288         /* Loopback mixer controls */
5289         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
5290         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
5291         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
5292         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
5293         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
5294         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
5295         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
5296         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
5297         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5298         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5299         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
5300         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
5301         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
5302         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
5303         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
5304         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
5305
5306         /* Controls for GPIO pins, assuming they are configured as outputs */
5307         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
5308         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
5309         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
5310         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
5311
5312         /* Switches to allow the digital IO pins to be enabled.  The datasheet
5313          * is ambigious as to which NID is which; testing on laptops which
5314          * make this output available should provide clarification.
5315          */
5316         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
5317         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
5318
5319         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
5320          * this output to turn on an external amplifier.
5321          */
5322         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
5323         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
5324
5325         { } /* end */
5326 };
5327 static struct hda_verb alc260_test_init_verbs[] = {
5328         /* Enable all GPIOs as outputs with an initial value of 0 */
5329         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
5330         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5331         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
5332
5333         /* Enable retasking pins as output, initially without power amp */
5334         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5335         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5336         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5337         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5338         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5339         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5340
5341         /* Disable digital (SPDIF) pins initially, but users can enable
5342          * them via a mixer switch.  In the case of SPDIF-out, this initverb
5343          * payload also sets the generation to 0, output to be in "consumer"
5344          * PCM format, copyright asserted, no pre-emphasis and no validity
5345          * control.
5346          */
5347         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5348         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5349
5350         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the
5351          * OUT1 sum bus when acting as an output.
5352          */
5353         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5354         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
5355         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5356         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
5357
5358         /* Start with output sum widgets muted and their output gains at min */
5359         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5360         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5361         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5362         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5363         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5364         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5365         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5366         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5367         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5368
5369         /* Unmute retasking pin widget output buffers since the default
5370          * state appears to be output.  As the pin mode is changed by the
5371          * user the pin mode control will take care of enabling the pin's
5372          * input/output buffers as needed.
5373          */
5374         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5375         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5376         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5377         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5378         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5379         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5380         /* Also unmute the mono-out pin widget */
5381         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5382
5383         /* Mute capture amp left and right */
5384         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5385         /* Set ADC connection select to match default mixer setting (mic1
5386          * pin)
5387          */
5388         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5389
5390         /* Do the same for the second ADC: mute capture input amp and
5391          * set ADC connection to mic1 pin
5392          */
5393         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5394         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5395
5396         /* Mute all inputs to mixer widget (even unconnected ones) */
5397         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5398         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5399         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5400         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5401         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5402         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5403         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5404         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5405
5406         { }
5407 };
5408 #endif
5409
5410 #define alc260_pcm_analog_playback      alc880_pcm_analog_alt_playback
5411 #define alc260_pcm_analog_capture       alc880_pcm_analog_capture
5412
5413 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
5414 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
5415
5416 /*
5417  * for BIOS auto-configuration
5418  */
5419
5420 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
5421                                         const char *pfx, int *vol_bits)
5422 {
5423         hda_nid_t nid_vol;
5424         unsigned long vol_val, sw_val;
5425         char name[32];
5426         int err;
5427
5428         if (nid >= 0x0f && nid < 0x11) {
5429                 nid_vol = nid - 0x7;
5430                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
5431                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
5432         } else if (nid == 0x11) {
5433                 nid_vol = nid - 0x7;
5434                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
5435                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
5436         } else if (nid >= 0x12 && nid <= 0x15) {
5437                 nid_vol = 0x08;
5438                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
5439                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
5440         } else
5441                 return 0; /* N/A */
5442
5443         if (!(*vol_bits & (1 << nid_vol))) {
5444                 /* first control for the volume widget */
5445                 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
5446                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val);
5447                 if (err < 0)
5448                         return err;
5449                 *vol_bits |= (1 << nid_vol);
5450         }
5451         snprintf(name, sizeof(name), "%s Playback Switch", pfx);
5452         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val);
5453         if (err < 0)
5454                 return err;
5455         return 1;
5456 }
5457
5458 /* add playback controls from the parsed DAC table */
5459 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
5460                                              const struct auto_pin_cfg *cfg)
5461 {
5462         hda_nid_t nid;
5463         int err;
5464         int vols = 0;
5465
5466         spec->multiout.num_dacs = 1;
5467         spec->multiout.dac_nids = spec->private_dac_nids;
5468         spec->multiout.dac_nids[0] = 0x02;
5469
5470         nid = cfg->line_out_pins[0];
5471         if (nid) {
5472                 err = alc260_add_playback_controls(spec, nid, "Front", &vols);
5473                 if (err < 0)
5474                         return err;
5475         }
5476
5477         nid = cfg->speaker_pins[0];
5478         if (nid) {
5479                 err = alc260_add_playback_controls(spec, nid, "Speaker", &vols);
5480                 if (err < 0)
5481                         return err;
5482         }
5483
5484         nid = cfg->hp_pins[0];
5485         if (nid) {
5486                 err = alc260_add_playback_controls(spec, nid, "Headphone",
5487                                                    &vols);
5488                 if (err < 0)
5489                         return err;
5490         }
5491         return 0;
5492 }
5493
5494 /* create playback/capture controls for input pins */
5495 static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec,
5496                                                 const struct auto_pin_cfg *cfg)
5497 {
5498         struct hda_input_mux *imux = &spec->private_imux[0];
5499         int i, err, idx;
5500
5501         for (i = 0; i < AUTO_PIN_LAST; i++) {
5502                 if (cfg->input_pins[i] >= 0x12) {
5503                         idx = cfg->input_pins[i] - 0x12;
5504                         err = new_analog_input(spec, cfg->input_pins[i],
5505                                                auto_pin_cfg_labels[i], idx,
5506                                                0x07);
5507                         if (err < 0)
5508                                 return err;
5509                         imux->items[imux->num_items].label =
5510                                 auto_pin_cfg_labels[i];
5511                         imux->items[imux->num_items].index = idx;
5512                         imux->num_items++;
5513                 }
5514                 if (cfg->input_pins[i] >= 0x0f && cfg->input_pins[i] <= 0x10){
5515                         idx = cfg->input_pins[i] - 0x09;
5516                         err = new_analog_input(spec, cfg->input_pins[i],
5517                                                auto_pin_cfg_labels[i], idx,
5518                                                0x07);
5519                         if (err < 0)
5520                                 return err;
5521                         imux->items[imux->num_items].label =
5522                                 auto_pin_cfg_labels[i];
5523                         imux->items[imux->num_items].index = idx;
5524                         imux->num_items++;
5525                 }
5526         }
5527         return 0;
5528 }
5529
5530 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
5531                                               hda_nid_t nid, int pin_type,
5532                                               int sel_idx)
5533 {
5534         alc_set_pin_output(codec, nid, pin_type);
5535         /* need the manual connection? */
5536         if (nid >= 0x12) {
5537                 int idx = nid - 0x12;
5538                 snd_hda_codec_write(codec, idx + 0x0b, 0,
5539                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
5540         }
5541 }
5542
5543 static void alc260_auto_init_multi_out(struct hda_codec *codec)
5544 {
5545         struct alc_spec *spec = codec->spec;
5546         hda_nid_t nid;
5547
5548         alc_subsystem_id(codec, 0x10, 0x15, 0x0f);
5549         nid = spec->autocfg.line_out_pins[0];
5550         if (nid) {
5551                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
5552                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
5553         }
5554
5555         nid = spec->autocfg.speaker_pins[0];
5556         if (nid)
5557                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
5558
5559         nid = spec->autocfg.hp_pins[0];
5560         if (nid)
5561                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
5562 }
5563
5564 #define ALC260_PIN_CD_NID               0x16
5565 static void alc260_auto_init_analog_input(struct hda_codec *codec)
5566 {
5567         struct alc_spec *spec = codec->spec;
5568         int i;
5569
5570         for (i = 0; i < AUTO_PIN_LAST; i++) {
5571                 hda_nid_t nid = spec->autocfg.input_pins[i];
5572                 if (nid >= 0x12) {
5573                         snd_hda_codec_write(codec, nid, 0,
5574                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
5575                                             i <= AUTO_PIN_FRONT_MIC ?
5576                                             PIN_VREF80 : PIN_IN);
5577                         if (nid != ALC260_PIN_CD_NID)
5578                                 snd_hda_codec_write(codec, nid, 0,
5579                                                     AC_VERB_SET_AMP_GAIN_MUTE,
5580                                                     AMP_OUT_MUTE);
5581                 }
5582         }
5583 }
5584
5585 /*
5586  * generic initialization of ADC, input mixers and output mixers
5587  */
5588 static struct hda_verb alc260_volume_init_verbs[] = {
5589         /*
5590          * Unmute ADC0-1 and set the default input to mic-in
5591          */
5592         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5593         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5594         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5595         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5596
5597         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5598          * mixer widget
5599          * Note: PASD motherboards uses the Line In 2 as the input for
5600          * front panel mic (mic 2)
5601          */
5602         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
5603         /* mute analog inputs */
5604         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5605         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5606         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5607         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5608         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5609
5610         /*
5611          * Set up output mixers (0x08 - 0x0a)
5612          */
5613         /* set vol=0 to output mixers */
5614         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5615         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5616         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5617         /* set up input amps for analog loopback */
5618         /* Amp Indices: DAC = 0, mixer = 1 */
5619         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5620         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5621         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5622         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5623         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5624         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5625
5626         { }
5627 };
5628
5629 static int alc260_parse_auto_config(struct hda_codec *codec)
5630 {
5631         struct alc_spec *spec = codec->spec;
5632         int err;
5633         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
5634
5635         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
5636                                            alc260_ignore);
5637         if (err < 0)
5638                 return err;
5639         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
5640         if (err < 0)
5641                 return err;
5642         if (!spec->kctls.list)
5643                 return 0; /* can't find valid BIOS pin config */
5644         err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg);
5645         if (err < 0)
5646                 return err;
5647
5648         spec->multiout.max_channels = 2;
5649
5650         if (spec->autocfg.dig_out_pin)
5651                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
5652         if (spec->kctls.list)
5653                 add_mixer(spec, spec->kctls.list);
5654
5655         add_verb(spec, alc260_volume_init_verbs);
5656
5657         spec->num_mux_defs = 1;
5658         spec->input_mux = &spec->private_imux[0];
5659
5660         store_pin_configs(codec);
5661         return 1;
5662 }
5663
5664 /* additional initialization for auto-configuration model */
5665 static void alc260_auto_init(struct hda_codec *codec)
5666 {
5667         struct alc_spec *spec = codec->spec;
5668         alc260_auto_init_multi_out(codec);
5669         alc260_auto_init_analog_input(codec);
5670         if (spec->unsol_event)
5671                 alc_inithook(codec);
5672 }
5673
5674 #ifdef CONFIG_SND_HDA_POWER_SAVE
5675 static struct hda_amp_list alc260_loopbacks[] = {
5676         { 0x07, HDA_INPUT, 0 },
5677         { 0x07, HDA_INPUT, 1 },
5678         { 0x07, HDA_INPUT, 2 },
5679         { 0x07, HDA_INPUT, 3 },
5680         { 0x07, HDA_INPUT, 4 },
5681         { } /* end */
5682 };
5683 #endif
5684
5685 /*
5686  * ALC260 configurations
5687  */
5688 static const char *alc260_models[ALC260_MODEL_LAST] = {
5689         [ALC260_BASIC]          = "basic",
5690         [ALC260_HP]             = "hp",
5691         [ALC260_HP_3013]        = "hp-3013",
5692         [ALC260_HP_DC7600]      = "hp-dc7600",
5693         [ALC260_FUJITSU_S702X]  = "fujitsu",
5694         [ALC260_ACER]           = "acer",
5695         [ALC260_WILL]           = "will",
5696         [ALC260_REPLACER_672V]  = "replacer",
5697 #ifdef CONFIG_SND_DEBUG
5698         [ALC260_TEST]           = "test",
5699 #endif
5700         [ALC260_AUTO]           = "auto",
5701 };
5702
5703 static struct snd_pci_quirk alc260_cfg_tbl[] = {
5704         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
5705         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
5706         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
5707         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013),
5708         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
5709         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP_3013),
5710         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_DC7600),
5711         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
5712         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
5713         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
5714         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
5715         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
5716         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
5717         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
5718         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
5719         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
5720         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
5721         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
5722         {}
5723 };
5724
5725 static struct alc_config_preset alc260_presets[] = {
5726         [ALC260_BASIC] = {
5727                 .mixers = { alc260_base_output_mixer,
5728                             alc260_input_mixer,
5729                             alc260_pc_beep_mixer },
5730                 .init_verbs = { alc260_init_verbs },
5731                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5732                 .dac_nids = alc260_dac_nids,
5733                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5734                 .adc_nids = alc260_adc_nids,
5735                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5736                 .channel_mode = alc260_modes,
5737                 .input_mux = &alc260_capture_source,
5738         },
5739         [ALC260_HP] = {
5740                 .mixers = { alc260_hp_output_mixer,
5741                             alc260_input_mixer },
5742                 .init_verbs = { alc260_init_verbs,
5743                                 alc260_hp_unsol_verbs },
5744                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5745                 .dac_nids = alc260_dac_nids,
5746                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5747                 .adc_nids = alc260_adc_nids_alt,
5748                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5749                 .channel_mode = alc260_modes,
5750                 .input_mux = &alc260_capture_source,
5751                 .unsol_event = alc260_hp_unsol_event,
5752                 .init_hook = alc260_hp_automute,
5753         },
5754         [ALC260_HP_DC7600] = {
5755                 .mixers = { alc260_hp_dc7600_mixer,
5756                             alc260_input_mixer },
5757                 .init_verbs = { alc260_init_verbs,
5758                                 alc260_hp_dc7600_verbs },
5759                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5760                 .dac_nids = alc260_dac_nids,
5761                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5762                 .adc_nids = alc260_adc_nids_alt,
5763                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5764                 .channel_mode = alc260_modes,
5765                 .input_mux = &alc260_capture_source,
5766                 .unsol_event = alc260_hp_3012_unsol_event,
5767                 .init_hook = alc260_hp_3012_automute,
5768         },
5769         [ALC260_HP_3013] = {
5770                 .mixers = { alc260_hp_3013_mixer,
5771                             alc260_input_mixer },
5772                 .init_verbs = { alc260_hp_3013_init_verbs,
5773                                 alc260_hp_3013_unsol_verbs },
5774                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5775                 .dac_nids = alc260_dac_nids,
5776                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5777                 .adc_nids = alc260_adc_nids_alt,
5778                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5779                 .channel_mode = alc260_modes,
5780                 .input_mux = &alc260_capture_source,
5781                 .unsol_event = alc260_hp_3013_unsol_event,
5782                 .init_hook = alc260_hp_3013_automute,
5783         },
5784         [ALC260_FUJITSU_S702X] = {
5785                 .mixers = { alc260_fujitsu_mixer },
5786                 .init_verbs = { alc260_fujitsu_init_verbs },
5787                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5788                 .dac_nids = alc260_dac_nids,
5789                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5790                 .adc_nids = alc260_dual_adc_nids,
5791                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5792                 .channel_mode = alc260_modes,
5793                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
5794                 .input_mux = alc260_fujitsu_capture_sources,
5795         },
5796         [ALC260_ACER] = {
5797                 .mixers = { alc260_acer_mixer },
5798                 .init_verbs = { alc260_acer_init_verbs },
5799                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5800                 .dac_nids = alc260_dac_nids,
5801                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5802                 .adc_nids = alc260_dual_adc_nids,
5803                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5804                 .channel_mode = alc260_modes,
5805                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
5806                 .input_mux = alc260_acer_capture_sources,
5807         },
5808         [ALC260_WILL] = {
5809                 .mixers = { alc260_will_mixer },
5810                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
5811                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5812                 .dac_nids = alc260_dac_nids,
5813                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5814                 .adc_nids = alc260_adc_nids,
5815                 .dig_out_nid = ALC260_DIGOUT_NID,
5816                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5817                 .channel_mode = alc260_modes,
5818                 .input_mux = &alc260_capture_source,
5819         },
5820         [ALC260_REPLACER_672V] = {
5821                 .mixers = { alc260_replacer_672v_mixer },
5822                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
5823                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5824                 .dac_nids = alc260_dac_nids,
5825                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5826                 .adc_nids = alc260_adc_nids,
5827                 .dig_out_nid = ALC260_DIGOUT_NID,
5828                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5829                 .channel_mode = alc260_modes,
5830                 .input_mux = &alc260_capture_source,
5831                 .unsol_event = alc260_replacer_672v_unsol_event,
5832                 .init_hook = alc260_replacer_672v_automute,
5833         },
5834 #ifdef CONFIG_SND_DEBUG
5835         [ALC260_TEST] = {
5836                 .mixers = { alc260_test_mixer },
5837                 .init_verbs = { alc260_test_init_verbs },
5838                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
5839                 .dac_nids = alc260_test_dac_nids,
5840                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
5841                 .adc_nids = alc260_test_adc_nids,
5842                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5843                 .channel_mode = alc260_modes,
5844                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
5845                 .input_mux = alc260_test_capture_sources,
5846         },
5847 #endif
5848 };
5849
5850 static int patch_alc260(struct hda_codec *codec)
5851 {
5852         struct alc_spec *spec;
5853         int err, board_config;
5854
5855         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5856         if (spec == NULL)
5857                 return -ENOMEM;
5858
5859         codec->spec = spec;
5860
5861         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
5862                                                   alc260_models,
5863                                                   alc260_cfg_tbl);
5864         if (board_config < 0) {
5865                 snd_printd(KERN_INFO "hda_codec: Unknown model for ALC260, "
5866                            "trying auto-probe from BIOS...\n");
5867                 board_config = ALC260_AUTO;
5868         }
5869
5870         if (board_config == ALC260_AUTO) {
5871                 /* automatic parse from the BIOS config */
5872                 err = alc260_parse_auto_config(codec);
5873                 if (err < 0) {
5874                         alc_free(codec);
5875                         return err;
5876                 } else if (!err) {
5877                         printk(KERN_INFO
5878                                "hda_codec: Cannot set up configuration "
5879                                "from BIOS.  Using base mode...\n");
5880                         board_config = ALC260_BASIC;
5881                 }
5882         }
5883
5884         if (board_config != ALC260_AUTO)
5885                 setup_preset(spec, &alc260_presets[board_config]);
5886
5887         spec->stream_name_analog = "ALC260 Analog";
5888         spec->stream_analog_playback = &alc260_pcm_analog_playback;
5889         spec->stream_analog_capture = &alc260_pcm_analog_capture;
5890
5891         spec->stream_name_digital = "ALC260 Digital";
5892         spec->stream_digital_playback = &alc260_pcm_digital_playback;
5893         spec->stream_digital_capture = &alc260_pcm_digital_capture;
5894
5895         if (!spec->adc_nids && spec->input_mux) {
5896                 /* check whether NID 0x04 is valid */
5897                 unsigned int wcap = get_wcaps(codec, 0x04);
5898                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
5899                 /* get type */
5900                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
5901                         spec->adc_nids = alc260_adc_nids_alt;
5902                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
5903                 } else {
5904                         spec->adc_nids = alc260_adc_nids;
5905                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
5906                 }
5907         }
5908         set_capture_mixer(spec);
5909
5910         spec->vmaster_nid = 0x08;
5911
5912         codec->patch_ops = alc_patch_ops;
5913         if (board_config == ALC260_AUTO)
5914                 spec->init_hook = alc260_auto_init;
5915 #ifdef CONFIG_SND_HDA_POWER_SAVE
5916         if (!spec->loopback.amplist)
5917                 spec->loopback.amplist = alc260_loopbacks;
5918 #endif
5919         codec->proc_widget_hook = print_realtek_coef;
5920
5921         return 0;
5922 }
5923
5924
5925 /*
5926  * ALC882 support
5927  *
5928  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5929  * configuration.  Each pin widget can choose any input DACs and a mixer.
5930  * Each ADC is connected from a mixer of all inputs.  This makes possible
5931  * 6-channel independent captures.
5932  *
5933  * In addition, an independent DAC for the multi-playback (not used in this
5934  * driver yet).
5935  */
5936 #define ALC882_DIGOUT_NID       0x06
5937 #define ALC882_DIGIN_NID        0x0a
5938
5939 static struct hda_channel_mode alc882_ch_modes[1] = {
5940         { 8, NULL }
5941 };
5942
5943 static hda_nid_t alc882_dac_nids[4] = {
5944         /* front, rear, clfe, rear_surr */
5945         0x02, 0x03, 0x04, 0x05
5946 };
5947
5948 /* identical with ALC880 */
5949 #define alc882_adc_nids         alc880_adc_nids
5950 #define alc882_adc_nids_alt     alc880_adc_nids_alt
5951
5952 static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
5953 static hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 };
5954
5955 /* input MUX */
5956 /* FIXME: should be a matrix-type input source selection */
5957
5958 static struct hda_input_mux alc882_capture_source = {
5959         .num_items = 4,
5960         .items = {
5961                 { "Mic", 0x0 },
5962                 { "Front Mic", 0x1 },
5963                 { "Line", 0x2 },
5964                 { "CD", 0x4 },
5965         },
5966 };
5967 /*
5968  * 2ch mode
5969  */
5970 static struct hda_verb alc882_3ST_ch2_init[] = {
5971         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
5972         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5973         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5974         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5975         { } /* end */
5976 };
5977
5978 /*
5979  * 6ch mode
5980  */
5981 static struct hda_verb alc882_3ST_ch6_init[] = {
5982         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5983         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5984         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
5985         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5986         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5987         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5988         { } /* end */
5989 };
5990
5991 static struct hda_channel_mode alc882_3ST_6ch_modes[2] = {
5992         { 2, alc882_3ST_ch2_init },
5993         { 6, alc882_3ST_ch6_init },
5994 };
5995
5996 /*
5997  * 6ch mode
5998  */
5999 static struct hda_verb alc882_sixstack_ch6_init[] = {
6000         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6001         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6002         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6003         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6004         { } /* end */
6005 };
6006
6007 /*
6008  * 8ch mode
6009  */
6010 static struct hda_verb alc882_sixstack_ch8_init[] = {
6011         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6012         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6013         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6014         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6015         { } /* end */
6016 };
6017
6018 static struct hda_channel_mode alc882_sixstack_modes[2] = {
6019         { 6, alc882_sixstack_ch6_init },
6020         { 8, alc882_sixstack_ch8_init },
6021 };
6022
6023 /*
6024  * macbook pro ALC885 can switch LineIn to LineOut without loosing Mic
6025  */
6026
6027 /*
6028  * 2ch mode
6029  */
6030 static struct hda_verb alc885_mbp_ch2_init[] = {
6031         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6032         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6033         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6034         { } /* end */
6035 };
6036
6037 /*
6038  * 6ch mode
6039  */
6040 static struct hda_verb alc885_mbp_ch6_init[] = {
6041         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6042         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6043         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6044         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6045         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6046         { } /* end */
6047 };
6048
6049 static struct hda_channel_mode alc885_mbp_6ch_modes[2] = {
6050         { 2, alc885_mbp_ch2_init },
6051         { 6, alc885_mbp_ch6_init },
6052 };
6053
6054
6055 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
6056  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
6057  */
6058 static struct snd_kcontrol_new alc882_base_mixer[] = {
6059         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6060         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6061         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6062         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6063         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6064         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6065         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6066         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6067         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6068         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6069         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6070         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6071         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6072         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6073         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6074         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6075         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6076         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6077         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6078         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6079         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6080         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6081         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6082         { } /* end */
6083 };
6084
6085 static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
6086         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
6087         HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
6088         HDA_CODEC_MUTE  ("Speaker Playback Switch", 0x14, 0x00, HDA_OUTPUT),
6089         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
6090         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6091         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6092         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
6093         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
6094         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
6095         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
6096         { } /* end */
6097 };
6098 static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
6099         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6100         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6101         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6102         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6103         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6104         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6105         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6106         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6107         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6108         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6109         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6110         { } /* end */
6111 };
6112
6113 static struct snd_kcontrol_new alc882_targa_mixer[] = {
6114         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6115         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6116         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6117         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6118         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6119         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6120         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6121         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6122         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6123         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6124         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6125         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6126         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6127         { } /* end */
6128 };
6129
6130 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
6131  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
6132  */
6133 static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
6134         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6135         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6136         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6137         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
6138         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6139         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6140         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6141         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6142         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
6143         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
6144         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6145         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6146         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6147         { } /* end */
6148 };
6149
6150 static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
6151         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6152         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6153         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6154         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6155         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6156         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6157         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6158         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6159         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6160         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6161         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6162         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6163         { } /* end */
6164 };
6165
6166 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
6167         {
6168                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6169                 .name = "Channel Mode",
6170                 .info = alc_ch_mode_info,
6171                 .get = alc_ch_mode_get,
6172                 .put = alc_ch_mode_put,
6173         },
6174         { } /* end */
6175 };
6176
6177 static struct hda_verb alc882_init_verbs[] = {
6178         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6179         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6180         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6181         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6182         /* Rear mixer */
6183         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6184         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6185         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6186         /* CLFE mixer */
6187         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6188         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6189         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6190         /* Side mixer */
6191         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6192         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6193         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6194
6195         /* Front Pin: output 0 (0x0c) */
6196         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6197         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6198         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6199         /* Rear Pin: output 1 (0x0d) */
6200         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6201         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6202         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
6203         /* CLFE Pin: output 2 (0x0e) */
6204         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6205         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6206         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
6207         /* Side Pin: output 3 (0x0f) */
6208         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6209         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6210         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
6211         /* Mic (rear) pin: input vref at 80% */
6212         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6213         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6214         /* Front Mic pin: input vref at 80% */
6215         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6216         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6217         /* Line In pin: input */
6218         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6219         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6220         /* Line-2 In: Headphone output (output 0 - 0x0c) */
6221         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6222         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6223         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
6224         /* CD pin widget for input */
6225         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6226
6227         /* FIXME: use matrix-type input source selection */
6228         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6229         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6230         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6231         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6232         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6233         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6234         /* Input mixer2 */
6235         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6236         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6237         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6238         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6239         /* Input mixer3 */
6240         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6241         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6242         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6243         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6244         /* ADC1: mute amp left and right */
6245         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6246         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6247         /* ADC2: mute amp left and right */
6248         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6249         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6250         /* ADC3: mute amp left and right */
6251         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6252         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6253
6254         { }
6255 };
6256
6257 static struct hda_verb alc882_eapd_verbs[] = {
6258         /* change to EAPD mode */
6259         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
6260         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
6261         { }
6262 };
6263
6264 /* Mac Pro test */
6265 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
6266         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6267         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6268         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
6269         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
6270         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
6271         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT),
6272         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT),
6273         { } /* end */
6274 };
6275
6276 static struct hda_verb alc882_macpro_init_verbs[] = {
6277         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6278         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6279         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6280         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6281         /* Front Pin: output 0 (0x0c) */
6282         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6283         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6284         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6285         /* Front Mic pin: input vref at 80% */
6286         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6287         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6288         /* Speaker:  output */
6289         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6290         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6291         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
6292         /* Headphone output (output 0 - 0x0c) */
6293         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6294         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6295         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
6296
6297         /* FIXME: use matrix-type input source selection */
6298         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6299         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6300         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6301         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6302         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6303         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6304         /* Input mixer2 */
6305         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6306         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6307         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6308         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6309         /* Input mixer3 */
6310         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6311         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6312         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6313         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6314         /* ADC1: mute amp left and right */
6315         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6316         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6317         /* ADC2: mute amp left and right */
6318         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6319         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6320         /* ADC3: mute amp left and right */
6321         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6322         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6323
6324         { }
6325 };
6326
6327 /* Macbook Pro rev3 */
6328 static struct hda_verb alc885_mbp3_init_verbs[] = {
6329         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6330         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6331         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6332         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6333         /* Rear mixer */
6334         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6335         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6336         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6337         /* Front Pin: output 0 (0x0c) */
6338         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6339         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6340         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6341         /* HP Pin: output 0 (0x0d) */
6342         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
6343         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6344         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6345         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6346         /* Mic (rear) pin: input vref at 80% */
6347         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6348         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6349         /* Front Mic pin: input vref at 80% */
6350         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6351         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6352         /* Line In pin: use output 1 when in LineOut mode */
6353         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6354         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6355         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
6356
6357         /* FIXME: use matrix-type input source selection */
6358         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6359         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6360         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6361         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6362         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6363         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6364         /* Input mixer2 */
6365         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6366         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6367         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6368         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6369         /* Input mixer3 */
6370         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6371         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6372         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6373         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6374         /* ADC1: mute amp left and right */
6375         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6376         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6377         /* ADC2: mute amp left and right */
6378         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6379         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6380         /* ADC3: mute amp left and right */
6381         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6382         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6383
6384         { }
6385 };
6386
6387 /* iMac 24 mixer. */
6388 static struct snd_kcontrol_new alc885_imac24_mixer[] = {
6389         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
6390         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
6391         { } /* end */
6392 };
6393
6394 /* iMac 24 init verbs. */
6395 static struct hda_verb alc885_imac24_init_verbs[] = {
6396         /* Internal speakers: output 0 (0x0c) */
6397         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6398         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6399         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
6400         /* Internal speakers: output 0 (0x0c) */
6401         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6402         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6403         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
6404         /* Headphone: output 0 (0x0c) */
6405         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6406         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6407         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6408         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6409         /* Front Mic: input vref at 80% */
6410         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6411         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6412         { }
6413 };
6414
6415 /* Toggle speaker-output according to the hp-jack state */
6416 static void alc885_imac24_automute(struct hda_codec *codec)
6417 {
6418         unsigned int present;
6419
6420         present = snd_hda_codec_read(codec, 0x14, 0,
6421                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6422         snd_hda_codec_amp_stereo(codec, 0x18, HDA_OUTPUT, 0,
6423                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6424         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
6425                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6426 }
6427
6428 /* Processes unsolicited events. */
6429 static void alc885_imac24_unsol_event(struct hda_codec *codec,
6430                                       unsigned int res)
6431 {
6432         /* Headphone insertion or removal. */
6433         if ((res >> 26) == ALC880_HP_EVENT)
6434                 alc885_imac24_automute(codec);
6435 }
6436
6437 static void alc885_mbp3_automute(struct hda_codec *codec)
6438 {
6439         unsigned int present;
6440
6441         present = snd_hda_codec_read(codec, 0x15, 0,
6442                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6443         snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
6444                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6445         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
6446                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
6447
6448 }
6449 static void alc885_mbp3_unsol_event(struct hda_codec *codec,
6450                                     unsigned int res)
6451 {
6452         /* Headphone insertion or removal. */
6453         if ((res >> 26) == ALC880_HP_EVENT)
6454                 alc885_mbp3_automute(codec);
6455 }
6456
6457
6458 static struct hda_verb alc882_targa_verbs[] = {
6459         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6460         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6461
6462         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6463         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6464
6465         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6466         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6467         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6468
6469         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6470         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6471         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
6472         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
6473         { } /* end */
6474 };
6475
6476 /* toggle speaker-output according to the hp-jack state */
6477 static void alc882_targa_automute(struct hda_codec *codec)
6478 {
6479         unsigned int present;
6480
6481         present = snd_hda_codec_read(codec, 0x14, 0,
6482                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6483         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
6484                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6485         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
6486                                   present ? 1 : 3);
6487 }
6488
6489 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
6490 {
6491         /* Looks like the unsol event is incompatible with the standard
6492          * definition.  4bit tag is placed at 26 bit!
6493          */
6494         if (((res >> 26) == ALC880_HP_EVENT)) {
6495                 alc882_targa_automute(codec);
6496         }
6497 }
6498
6499 static struct hda_verb alc882_asus_a7j_verbs[] = {
6500         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6501         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6502
6503         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6504         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6505         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6506
6507         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6508         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6509         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6510
6511         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6512         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6513         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6514         { } /* end */
6515 };
6516
6517 static struct hda_verb alc882_asus_a7m_verbs[] = {
6518         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6519         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6520
6521         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6522         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6523         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6524
6525         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6526         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6527         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6528
6529         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6530         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6531         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6532         { } /* end */
6533 };
6534
6535 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
6536 {
6537         unsigned int gpiostate, gpiomask, gpiodir;
6538
6539         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
6540                                        AC_VERB_GET_GPIO_DATA, 0);
6541
6542         if (!muted)
6543                 gpiostate |= (1 << pin);
6544         else
6545                 gpiostate &= ~(1 << pin);
6546
6547         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
6548                                       AC_VERB_GET_GPIO_MASK, 0);
6549         gpiomask |= (1 << pin);
6550
6551         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
6552                                      AC_VERB_GET_GPIO_DIRECTION, 0);
6553         gpiodir |= (1 << pin);
6554
6555
6556         snd_hda_codec_write(codec, codec->afg, 0,
6557                             AC_VERB_SET_GPIO_MASK, gpiomask);
6558         snd_hda_codec_write(codec, codec->afg, 0,
6559                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
6560
6561         msleep(1);
6562
6563         snd_hda_codec_write(codec, codec->afg, 0,
6564                             AC_VERB_SET_GPIO_DATA, gpiostate);
6565 }
6566
6567 /* set up GPIO at initialization */
6568 static void alc885_macpro_init_hook(struct hda_codec *codec)
6569 {
6570         alc882_gpio_mute(codec, 0, 0);
6571         alc882_gpio_mute(codec, 1, 0);
6572 }
6573
6574 /* set up GPIO and update auto-muting at initialization */
6575 static void alc885_imac24_init_hook(struct hda_codec *codec)
6576 {
6577         alc885_macpro_init_hook(codec);
6578         alc885_imac24_automute(codec);
6579 }
6580
6581 /*
6582  * generic initialization of ADC, input mixers and output mixers
6583  */
6584 static struct hda_verb alc882_auto_init_verbs[] = {
6585         /*
6586          * Unmute ADC0-2 and set the default input to mic-in
6587          */
6588         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6589         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6590         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6591         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6592         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6593         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6594
6595         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
6596          * mixer widget
6597          * Note: PASD motherboards uses the Line In 2 as the input for
6598          * front panel mic (mic 2)
6599          */
6600         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
6601         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6602         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6603         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6604         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6605         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6606
6607         /*
6608          * Set up output mixers (0x0c - 0x0f)
6609          */
6610         /* set vol=0 to output mixers */
6611         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6612         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6613         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6614         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6615         /* set up input amps for analog loopback */
6616         /* Amp Indices: DAC = 0, mixer = 1 */
6617         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6618         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6619         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6620         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6621         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6622         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6623         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6624         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6625         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6626         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6627
6628         /* FIXME: use matrix-type input source selection */
6629         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6630         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6631         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6632         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6633         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6634         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6635         /* Input mixer2 */
6636         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6637         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6638         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6639         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6640         /* Input mixer3 */
6641         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6642         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6643         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6644         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6645
6646         { }
6647 };
6648
6649 #ifdef CONFIG_SND_HDA_POWER_SAVE
6650 #define alc882_loopbacks        alc880_loopbacks
6651 #endif
6652
6653 /* pcm configuration: identiacal with ALC880 */
6654 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
6655 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
6656 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
6657 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
6658
6659 /*
6660  * configuration and preset
6661  */
6662 static const char *alc882_models[ALC882_MODEL_LAST] = {
6663         [ALC882_3ST_DIG]        = "3stack-dig",
6664         [ALC882_6ST_DIG]        = "6stack-dig",
6665         [ALC882_ARIMA]          = "arima",
6666         [ALC882_W2JC]           = "w2jc",
6667         [ALC882_TARGA]          = "targa",
6668         [ALC882_ASUS_A7J]       = "asus-a7j",
6669         [ALC882_ASUS_A7M]       = "asus-a7m",
6670         [ALC885_MACPRO]         = "macpro",
6671         [ALC885_MBP3]           = "mbp3",
6672         [ALC885_IMAC24]         = "imac24",
6673         [ALC882_AUTO]           = "auto",
6674 };
6675
6676 static struct snd_pci_quirk alc882_cfg_tbl[] = {
6677         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
6678         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
6679         SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
6680         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
6681         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
6682         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
6683         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
6684         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
6685         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),
6686         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
6687         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
6688         SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA),
6689         {}
6690 };
6691
6692 static struct alc_config_preset alc882_presets[] = {
6693         [ALC882_3ST_DIG] = {
6694                 .mixers = { alc882_base_mixer },
6695                 .init_verbs = { alc882_init_verbs },
6696                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6697                 .dac_nids = alc882_dac_nids,
6698                 .dig_out_nid = ALC882_DIGOUT_NID,
6699                 .dig_in_nid = ALC882_DIGIN_NID,
6700                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6701                 .channel_mode = alc882_ch_modes,
6702                 .need_dac_fix = 1,
6703                 .input_mux = &alc882_capture_source,
6704         },
6705         [ALC882_6ST_DIG] = {
6706                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6707                 .init_verbs = { alc882_init_verbs },
6708                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6709                 .dac_nids = alc882_dac_nids,
6710                 .dig_out_nid = ALC882_DIGOUT_NID,
6711                 .dig_in_nid = ALC882_DIGIN_NID,
6712                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6713                 .channel_mode = alc882_sixstack_modes,
6714                 .input_mux = &alc882_capture_source,
6715         },
6716         [ALC882_ARIMA] = {
6717                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6718                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs },
6719                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6720                 .dac_nids = alc882_dac_nids,
6721                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6722                 .channel_mode = alc882_sixstack_modes,
6723                 .input_mux = &alc882_capture_source,
6724         },
6725         [ALC882_W2JC] = {
6726                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
6727                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6728                                 alc880_gpio1_init_verbs },
6729                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6730                 .dac_nids = alc882_dac_nids,
6731                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6732                 .channel_mode = alc880_threestack_modes,
6733                 .need_dac_fix = 1,
6734                 .input_mux = &alc882_capture_source,
6735                 .dig_out_nid = ALC882_DIGOUT_NID,
6736         },
6737         [ALC885_MBP3] = {
6738                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
6739                 .init_verbs = { alc885_mbp3_init_verbs,
6740                                 alc880_gpio1_init_verbs },
6741                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6742                 .dac_nids = alc882_dac_nids,
6743                 .channel_mode = alc885_mbp_6ch_modes,
6744                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_6ch_modes),
6745                 .input_mux = &alc882_capture_source,
6746                 .dig_out_nid = ALC882_DIGOUT_NID,
6747                 .dig_in_nid = ALC882_DIGIN_NID,
6748                 .unsol_event = alc885_mbp3_unsol_event,
6749                 .init_hook = alc885_mbp3_automute,
6750         },
6751         [ALC885_MACPRO] = {
6752                 .mixers = { alc882_macpro_mixer },
6753                 .init_verbs = { alc882_macpro_init_verbs },
6754                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6755                 .dac_nids = alc882_dac_nids,
6756                 .dig_out_nid = ALC882_DIGOUT_NID,
6757                 .dig_in_nid = ALC882_DIGIN_NID,
6758                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6759                 .channel_mode = alc882_ch_modes,
6760                 .input_mux = &alc882_capture_source,
6761                 .init_hook = alc885_macpro_init_hook,
6762         },
6763         [ALC885_IMAC24] = {
6764                 .mixers = { alc885_imac24_mixer },
6765                 .init_verbs = { alc885_imac24_init_verbs },
6766                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6767                 .dac_nids = alc882_dac_nids,
6768                 .dig_out_nid = ALC882_DIGOUT_NID,
6769                 .dig_in_nid = ALC882_DIGIN_NID,
6770                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6771                 .channel_mode = alc882_ch_modes,
6772                 .input_mux = &alc882_capture_source,
6773                 .unsol_event = alc885_imac24_unsol_event,
6774                 .init_hook = alc885_imac24_init_hook,
6775         },
6776         [ALC882_TARGA] = {
6777                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer },
6778                 .init_verbs = { alc882_init_verbs, alc882_targa_verbs},
6779                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6780                 .dac_nids = alc882_dac_nids,
6781                 .dig_out_nid = ALC882_DIGOUT_NID,
6782                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6783                 .adc_nids = alc882_adc_nids,
6784                 .capsrc_nids = alc882_capsrc_nids,
6785                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6786                 .channel_mode = alc882_3ST_6ch_modes,
6787                 .need_dac_fix = 1,
6788                 .input_mux = &alc882_capture_source,
6789                 .unsol_event = alc882_targa_unsol_event,
6790                 .init_hook = alc882_targa_automute,
6791         },
6792         [ALC882_ASUS_A7J] = {
6793                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer },
6794                 .init_verbs = { alc882_init_verbs, alc882_asus_a7j_verbs},
6795                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6796                 .dac_nids = alc882_dac_nids,
6797                 .dig_out_nid = ALC882_DIGOUT_NID,
6798                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6799                 .adc_nids = alc882_adc_nids,
6800                 .capsrc_nids = alc882_capsrc_nids,
6801                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6802                 .channel_mode = alc882_3ST_6ch_modes,
6803                 .need_dac_fix = 1,
6804                 .input_mux = &alc882_capture_source,
6805         },
6806         [ALC882_ASUS_A7M] = {
6807                 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
6808                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6809                                 alc880_gpio1_init_verbs,
6810                                 alc882_asus_a7m_verbs },
6811                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6812                 .dac_nids = alc882_dac_nids,
6813                 .dig_out_nid = ALC882_DIGOUT_NID,
6814                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6815                 .channel_mode = alc880_threestack_modes,
6816                 .need_dac_fix = 1,
6817                 .input_mux = &alc882_capture_source,
6818         },
6819 };
6820
6821
6822 /*
6823  * Pin config fixes
6824  */
6825 enum {
6826         PINFIX_ABIT_AW9D_MAX
6827 };
6828
6829 static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
6830         { 0x15, 0x01080104 }, /* side */
6831         { 0x16, 0x01011012 }, /* rear */
6832         { 0x17, 0x01016011 }, /* clfe */
6833         { }
6834 };
6835
6836 static const struct alc_pincfg *alc882_pin_fixes[] = {
6837         [PINFIX_ABIT_AW9D_MAX] = alc882_abit_aw9d_pinfix,
6838 };
6839
6840 static struct snd_pci_quirk alc882_pinfix_tbl[] = {
6841         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
6842         {}
6843 };
6844
6845 /*
6846  * BIOS auto configuration
6847  */
6848 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
6849                                               hda_nid_t nid, int pin_type,
6850                                               int dac_idx)
6851 {
6852         /* set as output */
6853         struct alc_spec *spec = codec->spec;
6854         int idx;
6855
6856         alc_set_pin_output(codec, nid, pin_type);
6857         if (spec->multiout.dac_nids[dac_idx] == 0x25)
6858                 idx = 4;
6859         else
6860                 idx = spec->multiout.dac_nids[dac_idx] - 2;
6861         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
6862
6863 }
6864
6865 static void alc882_auto_init_multi_out(struct hda_codec *codec)
6866 {
6867         struct alc_spec *spec = codec->spec;
6868         int i;
6869
6870         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
6871         for (i = 0; i <= HDA_SIDE; i++) {
6872                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
6873                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
6874                 if (nid)
6875                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
6876                                                           i);
6877         }
6878 }
6879
6880 static void alc882_auto_init_hp_out(struct hda_codec *codec)
6881 {
6882         struct alc_spec *spec = codec->spec;
6883         hda_nid_t pin;
6884
6885         pin = spec->autocfg.hp_pins[0];
6886         if (pin) /* connect to front */
6887                 /* use dac 0 */
6888                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
6889         pin = spec->autocfg.speaker_pins[0];
6890         if (pin)
6891                 alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
6892 }
6893
6894 #define alc882_is_input_pin(nid)        alc880_is_input_pin(nid)
6895 #define ALC882_PIN_CD_NID               ALC880_PIN_CD_NID
6896
6897 static void alc882_auto_init_analog_input(struct hda_codec *codec)
6898 {
6899         struct alc_spec *spec = codec->spec;
6900         int i;
6901
6902         for (i = 0; i < AUTO_PIN_LAST; i++) {
6903                 hda_nid_t nid = spec->autocfg.input_pins[i];
6904                 unsigned int vref;
6905                 if (!nid)
6906                         continue;
6907                 vref = PIN_IN;
6908                 if (1 /*i <= AUTO_PIN_FRONT_MIC*/) {
6909                         unsigned int pincap;
6910                         pincap = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
6911                         if ((pincap >> AC_PINCAP_VREF_SHIFT) &
6912                             AC_PINCAP_VREF_80)
6913                                 vref = PIN_VREF80;
6914                 }
6915                 snd_hda_codec_write(codec, nid, 0,
6916                                     AC_VERB_SET_PIN_WIDGET_CONTROL, vref);
6917                 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
6918                         snd_hda_codec_write(codec, nid, 0,
6919                                             AC_VERB_SET_AMP_GAIN_MUTE,
6920                                             AMP_OUT_MUTE);
6921         }
6922 }
6923
6924 static void alc882_auto_init_input_src(struct hda_codec *codec)
6925 {
6926         struct alc_spec *spec = codec->spec;
6927         const struct hda_input_mux *imux = spec->input_mux;
6928         int c;
6929
6930         for (c = 0; c < spec->num_adc_nids; c++) {
6931                 hda_nid_t conn_list[HDA_MAX_NUM_INPUTS];
6932                 hda_nid_t nid = spec->capsrc_nids[c];
6933                 int conns, mute, idx, item;
6934
6935                 conns = snd_hda_get_connections(codec, nid, conn_list,
6936                                                 ARRAY_SIZE(conn_list));
6937                 if (conns < 0)
6938                         continue;
6939                 for (idx = 0; idx < conns; idx++) {
6940                         /* if the current connection is the selected one,
6941                          * unmute it as default - otherwise mute it
6942                          */
6943                         mute = AMP_IN_MUTE(idx);
6944                         for (item = 0; item < imux->num_items; item++) {
6945                                 if (imux->items[item].index == idx) {
6946                                         if (spec->cur_mux[c] == item)
6947                                                 mute = AMP_IN_UNMUTE(idx);
6948                                         break;
6949                                 }
6950                         }
6951                         snd_hda_codec_write(codec, nid, 0,
6952                                             AC_VERB_SET_AMP_GAIN_MUTE, mute);
6953                 }
6954         }
6955 }
6956
6957 /* add mic boosts if needed */
6958 static int alc_auto_add_mic_boost(struct hda_codec *codec)
6959 {
6960         struct alc_spec *spec = codec->spec;
6961         int err;
6962         hda_nid_t nid;
6963
6964         nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
6965         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6966                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6967                                   "Mic Boost",
6968                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6969                 if (err < 0)
6970                         return err;
6971         }
6972         nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
6973         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6974                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6975                                   "Front Mic Boost",
6976                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6977                 if (err < 0)
6978                         return err;
6979         }
6980         return 0;
6981 }
6982
6983 /* almost identical with ALC880 parser... */
6984 static int alc882_parse_auto_config(struct hda_codec *codec)
6985 {
6986         struct alc_spec *spec = codec->spec;
6987         int err = alc880_parse_auto_config(codec);
6988
6989         if (err < 0)
6990                 return err;
6991         else if (!err)
6992                 return 0; /* no config found */
6993
6994         err = alc_auto_add_mic_boost(codec);
6995         if (err < 0)
6996                 return err;
6997
6998         /* hack - override the init verbs */
6999         spec->init_verbs[0] = alc882_auto_init_verbs;
7000
7001         return 1; /* config found */
7002 }
7003
7004 /* additional initialization for auto-configuration model */
7005 static void alc882_auto_init(struct hda_codec *codec)
7006 {
7007         struct alc_spec *spec = codec->spec;
7008         alc882_auto_init_multi_out(codec);
7009         alc882_auto_init_hp_out(codec);
7010         alc882_auto_init_analog_input(codec);
7011         alc882_auto_init_input_src(codec);
7012         if (spec->unsol_event)
7013                 alc_inithook(codec);
7014 }
7015
7016 static int patch_alc883(struct hda_codec *codec); /* called in patch_alc882() */
7017
7018 static int patch_alc882(struct hda_codec *codec)
7019 {
7020         struct alc_spec *spec;
7021         int err, board_config;
7022
7023         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
7024         if (spec == NULL)
7025                 return -ENOMEM;
7026
7027         codec->spec = spec;
7028
7029         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
7030                                                   alc882_models,
7031                                                   alc882_cfg_tbl);
7032
7033         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
7034                 /* Pick up systems that don't supply PCI SSID */
7035                 switch (codec->subsystem_id) {
7036                 case 0x106b0c00: /* Mac Pro */
7037                         board_config = ALC885_MACPRO;
7038                         break;
7039                 case 0x106b1000: /* iMac 24 */
7040                 case 0x106b2800: /* AppleTV */
7041                         board_config = ALC885_IMAC24;
7042                         break;
7043                 case 0x106b00a1: /* Macbook (might be wrong - PCI SSID?) */
7044                 case 0x106b00a4: /* MacbookPro4,1 */
7045                 case 0x106b2c00: /* Macbook Pro rev3 */
7046                 case 0x106b3600: /* Macbook 3.1 */
7047                         board_config = ALC885_MBP3;
7048                         break;
7049                 default:
7050                         /* ALC889A is handled better as ALC888-compatible */
7051                         if (codec->revision_id == 0x100101 ||
7052                             codec->revision_id == 0x100103) {
7053                                 alc_free(codec);
7054                                 return patch_alc883(codec);
7055                         }
7056                         printk(KERN_INFO "hda_codec: Unknown model for ALC882, "
7057                                          "trying auto-probe from BIOS...\n");
7058                         board_config = ALC882_AUTO;
7059                 }
7060         }
7061
7062         alc_fix_pincfg(codec, alc882_pinfix_tbl, alc882_pin_fixes);
7063
7064         if (board_config == ALC882_AUTO) {
7065                 /* automatic parse from the BIOS config */
7066                 err = alc882_parse_auto_config(codec);
7067                 if (err < 0) {
7068                         alc_free(codec);
7069                         return err;
7070                 } else if (!err) {
7071                         printk(KERN_INFO
7072                                "hda_codec: Cannot set up configuration "
7073                                "from BIOS.  Using base mode...\n");
7074                         board_config = ALC882_3ST_DIG;
7075                 }
7076         }
7077
7078         if (board_config != ALC882_AUTO)
7079                 setup_preset(spec, &alc882_presets[board_config]);
7080
7081         if (codec->vendor_id == 0x10ec0885) {
7082                 spec->stream_name_analog = "ALC885 Analog";
7083                 spec->stream_name_digital = "ALC885 Digital";
7084         } else {
7085                 spec->stream_name_analog = "ALC882 Analog";
7086                 spec->stream_name_digital = "ALC882 Digital";
7087         }
7088
7089         spec->stream_analog_playback = &alc882_pcm_analog_playback;
7090         spec->stream_analog_capture = &alc882_pcm_analog_capture;
7091         /* FIXME: setup DAC5 */
7092         /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
7093         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
7094
7095         spec->stream_digital_playback = &alc882_pcm_digital_playback;
7096         spec->stream_digital_capture = &alc882_pcm_digital_capture;
7097
7098         spec->capture_style = CAPT_MIX; /* matrix-style capture */
7099         if (!spec->adc_nids && spec->input_mux) {
7100                 /* check whether NID 0x07 is valid */
7101                 unsigned int wcap = get_wcaps(codec, 0x07);
7102                 /* get type */
7103                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
7104                 if (wcap != AC_WID_AUD_IN) {
7105                         spec->adc_nids = alc882_adc_nids_alt;
7106                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
7107                         spec->capsrc_nids = alc882_capsrc_nids_alt;
7108                 } else {
7109                         spec->adc_nids = alc882_adc_nids;
7110                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
7111                         spec->capsrc_nids = alc882_capsrc_nids;
7112                 }
7113         }
7114         set_capture_mixer(spec);
7115
7116         spec->vmaster_nid = 0x0c;
7117
7118         codec->patch_ops = alc_patch_ops;
7119         if (board_config == ALC882_AUTO)
7120                 spec->init_hook = alc882_auto_init;
7121 #ifdef CONFIG_SND_HDA_POWER_SAVE
7122         if (!spec->loopback.amplist)
7123                 spec->loopback.amplist = alc882_loopbacks;
7124 #endif
7125         codec->proc_widget_hook = print_realtek_coef;
7126
7127         return 0;
7128 }
7129
7130 /*
7131  * ALC883 support
7132  *
7133  * ALC883 is almost identical with ALC880 but has cleaner and more flexible
7134  * configuration.  Each pin widget can choose any input DACs and a mixer.
7135  * Each ADC is connected from a mixer of all inputs.  This makes possible
7136  * 6-channel independent captures.
7137  *
7138  * In addition, an independent DAC for the multi-playback (not used in this
7139  * driver yet).
7140  */
7141 #define ALC883_DIGOUT_NID       0x06
7142 #define ALC883_DIGIN_NID        0x0a
7143
7144 #define ALC1200_DIGOUT_NID      0x10
7145
7146 static hda_nid_t alc883_dac_nids[4] = {
7147         /* front, rear, clfe, rear_surr */
7148         0x02, 0x03, 0x04, 0x05
7149 };
7150
7151 static hda_nid_t alc883_adc_nids[2] = {
7152         /* ADC1-2 */
7153         0x08, 0x09,
7154 };
7155
7156 static hda_nid_t alc883_adc_nids_alt[1] = {
7157         /* ADC1 */
7158         0x08,
7159 };
7160
7161 static hda_nid_t alc883_adc_nids_rev[2] = {
7162         /* ADC2-1 */
7163         0x09, 0x08
7164 };
7165
7166 #define alc889_adc_nids         alc880_adc_nids
7167
7168 static hda_nid_t alc883_capsrc_nids[2] = { 0x23, 0x22 };
7169
7170 static hda_nid_t alc883_capsrc_nids_rev[2] = { 0x22, 0x23 };
7171
7172 #define alc889_capsrc_nids      alc882_capsrc_nids
7173
7174 /* input MUX */
7175 /* FIXME: should be a matrix-type input source selection */
7176
7177 static struct hda_input_mux alc883_capture_source = {
7178         .num_items = 4,
7179         .items = {
7180                 { "Mic", 0x0 },
7181                 { "Front Mic", 0x1 },
7182                 { "Line", 0x2 },
7183                 { "CD", 0x4 },
7184         },
7185 };
7186
7187 static struct hda_input_mux alc883_3stack_6ch_intel = {
7188         .num_items = 4,
7189         .items = {
7190                 { "Mic", 0x1 },
7191                 { "Front Mic", 0x0 },
7192                 { "Line", 0x2 },
7193                 { "CD", 0x4 },
7194         },
7195 };
7196
7197 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
7198         .num_items = 2,
7199         .items = {
7200                 { "Mic", 0x1 },
7201                 { "Line", 0x2 },
7202         },
7203 };
7204
7205 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
7206         .num_items = 4,
7207         .items = {
7208                 { "Mic", 0x0 },
7209                 { "iMic", 0x1 },
7210                 { "Line", 0x2 },
7211                 { "CD", 0x4 },
7212         },
7213 };
7214
7215 static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
7216         .num_items = 2,
7217         .items = {
7218                 { "Mic", 0x0 },
7219                 { "Int Mic", 0x1 },
7220         },
7221 };
7222
7223 static struct hda_input_mux alc883_lenovo_sky_capture_source = {
7224         .num_items = 3,
7225         .items = {
7226                 { "Mic", 0x0 },
7227                 { "Front Mic", 0x1 },
7228                 { "Line", 0x4 },
7229         },
7230 };
7231
7232 static struct hda_input_mux alc883_asus_eee1601_capture_source = {
7233         .num_items = 2,
7234         .items = {
7235                 { "Mic", 0x0 },
7236                 { "Line", 0x2 },
7237         },
7238 };
7239
7240 /*
7241  * 2ch mode
7242  */
7243 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
7244         { 2, NULL }
7245 };
7246
7247 /*
7248  * 2ch mode
7249  */
7250 static struct hda_verb alc883_3ST_ch2_init[] = {
7251         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7252         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7253         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7254         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7255         { } /* end */
7256 };
7257
7258 /*
7259  * 4ch mode
7260  */
7261 static struct hda_verb alc883_3ST_ch4_init[] = {
7262         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7263         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7264         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7265         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7266         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7267         { } /* end */
7268 };
7269
7270 /*
7271  * 6ch mode
7272  */
7273 static struct hda_verb alc883_3ST_ch6_init[] = {
7274         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7275         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7276         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
7277         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7278         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7279         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7280         { } /* end */
7281 };
7282
7283 static struct hda_channel_mode alc883_3ST_6ch_modes[3] = {
7284         { 2, alc883_3ST_ch2_init },
7285         { 4, alc883_3ST_ch4_init },
7286         { 6, alc883_3ST_ch6_init },
7287 };
7288
7289 /*
7290  * 2ch mode
7291  */
7292 static struct hda_verb alc883_3ST_ch2_intel_init[] = {
7293         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7294         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7295         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7296         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7297         { } /* end */
7298 };
7299
7300 /*
7301  * 4ch mode
7302  */
7303 static struct hda_verb alc883_3ST_ch4_intel_init[] = {
7304         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7305         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7306         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7307         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7308         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7309         { } /* end */
7310 };
7311
7312 /*
7313  * 6ch mode
7314  */
7315 static struct hda_verb alc883_3ST_ch6_intel_init[] = {
7316         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7317         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7318         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x02 },
7319         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7320         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7321         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7322         { } /* end */
7323 };
7324
7325 static struct hda_channel_mode alc883_3ST_6ch_intel_modes[3] = {
7326         { 2, alc883_3ST_ch2_intel_init },
7327         { 4, alc883_3ST_ch4_intel_init },
7328         { 6, alc883_3ST_ch6_intel_init },
7329 };
7330
7331 /*
7332  * 6ch mode
7333  */
7334 static struct hda_verb alc883_sixstack_ch6_init[] = {
7335         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
7336         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7337         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7338         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7339         { } /* end */
7340 };
7341
7342 /*
7343  * 8ch mode
7344  */
7345 static struct hda_verb alc883_sixstack_ch8_init[] = {
7346         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7347         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7348         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7349         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7350         { } /* end */
7351 };
7352
7353 static struct hda_channel_mode alc883_sixstack_modes[2] = {
7354         { 6, alc883_sixstack_ch6_init },
7355         { 8, alc883_sixstack_ch8_init },
7356 };
7357
7358 static struct hda_verb alc883_medion_eapd_verbs[] = {
7359         /* eanable EAPD on medion laptop */
7360         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7361         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
7362         { }
7363 };
7364
7365 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
7366  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
7367  */
7368
7369 static struct snd_kcontrol_new alc883_base_mixer[] = {
7370         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7371         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7372         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7373         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7374         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7375         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7376         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7377         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7378         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7379         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7380         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7381         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7382         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7383         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7384         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7385         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7386         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7387         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7388         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7389         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7390         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7391         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7392         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7393         { } /* end */
7394 };
7395
7396 static struct snd_kcontrol_new alc883_mitac_mixer[] = {
7397         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7398         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7399         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7400         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7401         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7402         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7403         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7404         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7405         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7406         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7407         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7408         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7409         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7410         { } /* end */
7411 };
7412
7413 static struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
7414         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7415         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7416         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7417         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7418         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7419         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7420         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7421         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7422         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7423         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7424         { } /* end */
7425 };
7426
7427 static struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
7428         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7429         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7430         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7431         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7432         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7433         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7434         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7435         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7436         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7437         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7438         { } /* end */
7439 };
7440
7441 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
7442         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7443         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7444         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7445         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7446         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7447         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7448         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7449         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7450         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7451         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7452         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7453         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7454         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7455         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7456         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7457         { } /* end */
7458 };
7459
7460 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
7461         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7462         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7463         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7464         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7465         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7466         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7467         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7468         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7469         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7470         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7471         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7472         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7473         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7474         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7475         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7476         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7477         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7478         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7479         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7480         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7481         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7482         { } /* end */
7483 };
7484
7485 static struct snd_kcontrol_new alc883_3ST_6ch_intel_mixer[] = {
7486         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7487         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7488         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7489         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7490         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
7491                               HDA_OUTPUT),
7492         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7493         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7494         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7495         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7496         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7497         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7498         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7499         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7500         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7501         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
7502         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7503         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7504         HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
7505         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7506         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7507         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7508         { } /* end */
7509 };
7510
7511 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
7512         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7513         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7514         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7515         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7516         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7517         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7518         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7519         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7520         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7521         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7522         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7523         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7524         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7525         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7526         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7527         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7528         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7529         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7530         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7531         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7532         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7533         { } /* end */
7534 };
7535
7536 static struct snd_kcontrol_new alc883_tagra_mixer[] = {
7537         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7538         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7539         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7540         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7541         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7542         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7543         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7544         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7545         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7546         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7547         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7548         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7549         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7550         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7551         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7552         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7553         { } /* end */
7554 };
7555
7556 static struct snd_kcontrol_new alc883_tagra_2ch_mixer[] = {
7557         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7558         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7559         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7560         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7561         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7562         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7563         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7564         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7565         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7566         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7567         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7568         { } /* end */
7569 };
7570
7571 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
7572         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7573         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7574         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7575         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7576         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7577         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7578         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7579         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7580         { } /* end */
7581 };
7582
7583 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
7584         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7585         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
7586         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7587         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7588         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7589         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7590         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7591         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7592         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7593         { } /* end */
7594 };
7595
7596 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
7597         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7598         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7599         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7600         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7601         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7602         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7603         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7604         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7605         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7606         { } /* end */
7607 };
7608
7609 static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
7610         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7611         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7612         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7613         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7614         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7615         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7616         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7617         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7618         { } /* end */
7619 };
7620
7621 static struct snd_kcontrol_new alc888_lenovo_sky_mixer[] = {
7622         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7623         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7624         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
7625         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
7626         HDA_CODEC_VOLUME_MONO("Center Playback Volume",
7627                                                 0x0d, 1, 0x0, HDA_OUTPUT),
7628         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
7629         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
7630         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
7631         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7632         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7633         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7634         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
7635         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7636         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7637         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7638         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7639         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7640         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7641         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7642         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7643         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7644         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7645         { } /* end */
7646 };
7647
7648 static struct hda_bind_ctls alc883_bind_cap_vol = {
7649         .ops = &snd_hda_bind_vol,
7650         .values = {
7651                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
7652                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
7653                 0
7654         },
7655 };
7656
7657 static struct hda_bind_ctls alc883_bind_cap_switch = {
7658         .ops = &snd_hda_bind_sw,
7659         .values = {
7660                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
7661                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
7662                 0
7663         },
7664 };
7665
7666 static struct snd_kcontrol_new alc883_asus_eee1601_mixer[] = {
7667         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7668         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7669         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7670         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7671         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7672         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7673         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7674         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7675         { } /* end */
7676 };
7677
7678 static struct snd_kcontrol_new alc883_asus_eee1601_cap_mixer[] = {
7679         HDA_BIND_VOL("Capture Volume", &alc883_bind_cap_vol),
7680         HDA_BIND_SW("Capture Switch", &alc883_bind_cap_switch),
7681         {
7682                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7683                 /* .name = "Capture Source", */
7684                 .name = "Input Source",
7685                 .count = 1,
7686                 .info = alc_mux_enum_info,
7687                 .get = alc_mux_enum_get,
7688                 .put = alc_mux_enum_put,
7689         },
7690         { } /* end */
7691 };
7692
7693 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
7694         {
7695                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7696                 .name = "Channel Mode",
7697                 .info = alc_ch_mode_info,
7698                 .get = alc_ch_mode_get,
7699                 .put = alc_ch_mode_put,
7700         },
7701         { } /* end */
7702 };
7703
7704 static struct hda_verb alc883_init_verbs[] = {
7705         /* ADC1: mute amp left and right */
7706         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7707         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7708         /* ADC2: mute amp left and right */
7709         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7710         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7711         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7712         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7713         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7714         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7715         /* Rear mixer */
7716         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7717         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7718         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7719         /* CLFE mixer */
7720         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7721         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7722         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7723         /* Side mixer */
7724         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7725         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7726         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7727
7728         /* mute analog input loopbacks */
7729         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7730         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7731         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7732         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7733         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7734
7735         /* Front Pin: output 0 (0x0c) */
7736         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7737         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7738         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7739         /* Rear Pin: output 1 (0x0d) */
7740         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7741         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7742         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7743         /* CLFE Pin: output 2 (0x0e) */
7744         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7745         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7746         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
7747         /* Side Pin: output 3 (0x0f) */
7748         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7749         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7750         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
7751         /* Mic (rear) pin: input vref at 80% */
7752         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7753         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7754         /* Front Mic pin: input vref at 80% */
7755         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7756         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7757         /* Line In pin: input */
7758         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7759         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7760         /* Line-2 In: Headphone output (output 0 - 0x0c) */
7761         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7762         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7763         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7764         /* CD pin widget for input */
7765         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7766
7767         /* FIXME: use matrix-type input source selection */
7768         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7769         /* Input mixer2 */
7770         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7771         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7772         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7773         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7774         /* Input mixer3 */
7775         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7776         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7777         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7778         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7779         { }
7780 };
7781
7782 /* toggle speaker-output according to the hp-jack state */
7783 static void alc883_mitac_hp_automute(struct hda_codec *codec)
7784 {
7785         unsigned int present;
7786
7787         present = snd_hda_codec_read(codec, 0x15, 0,
7788                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7789         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7790                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7791         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
7792                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7793 }
7794
7795 /* auto-toggle front mic */
7796 /*
7797 static void alc883_mitac_mic_automute(struct hda_codec *codec)
7798 {
7799         unsigned int present;
7800         unsigned char bits;
7801
7802         present = snd_hda_codec_read(codec, 0x18, 0,
7803                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7804         bits = present ? HDA_AMP_MUTE : 0;
7805         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
7806 }
7807 */
7808
7809 static void alc883_mitac_automute(struct hda_codec *codec)
7810 {
7811         alc883_mitac_hp_automute(codec);
7812         /* alc883_mitac_mic_automute(codec); */
7813 }
7814
7815 static void alc883_mitac_unsol_event(struct hda_codec *codec,
7816                                            unsigned int res)
7817 {
7818         switch (res >> 26) {
7819         case ALC880_HP_EVENT:
7820                 alc883_mitac_hp_automute(codec);
7821                 break;
7822         case ALC880_MIC_EVENT:
7823                 /* alc883_mitac_mic_automute(codec); */
7824                 break;
7825         }
7826 }
7827
7828 static struct hda_verb alc883_mitac_verbs[] = {
7829         /* HP */
7830         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7831         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7832         /* Subwoofer */
7833         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
7834         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7835
7836         /* enable unsolicited event */
7837         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7838         /* {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN}, */
7839
7840         { } /* end */
7841 };
7842
7843 static struct hda_verb alc883_clevo_m720_verbs[] = {
7844         /* HP */
7845         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7846         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7847         /* Int speaker */
7848         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
7849         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7850
7851         /* enable unsolicited event */
7852         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7853         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
7854
7855         { } /* end */
7856 };
7857
7858 static struct hda_verb alc883_2ch_fujitsu_pi2515_verbs[] = {
7859         /* HP */
7860         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7861         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7862         /* Subwoofer */
7863         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7864         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7865
7866         /* enable unsolicited event */
7867         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7868
7869         { } /* end */
7870 };
7871
7872 static struct hda_verb alc883_tagra_verbs[] = {
7873         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7874         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7875
7876         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7877         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7878
7879         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7880         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7881         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7882
7883         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7884         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
7885         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
7886         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
7887
7888         { } /* end */
7889 };
7890
7891 static struct hda_verb alc883_lenovo_101e_verbs[] = {
7892         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7893         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
7894         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
7895         { } /* end */
7896 };
7897
7898 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
7899         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7900         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7901         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7902         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7903         { } /* end */
7904 };
7905
7906 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
7907         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7908         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7909         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7910         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
7911         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
7912         { } /* end */
7913 };
7914
7915 static struct hda_verb alc883_haier_w66_verbs[] = {
7916         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7917         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7918
7919         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7920
7921         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7922         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7923         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7924         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7925         { } /* end */
7926 };
7927
7928 static struct hda_verb alc888_lenovo_sky_verbs[] = {
7929         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7930         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7931         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7932         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7933         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7934         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7935         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
7936         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7937         { } /* end */
7938 };
7939
7940 static struct hda_verb alc888_3st_hp_verbs[] = {
7941         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
7942         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
7943         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
7944         { }
7945 };
7946
7947 static struct hda_verb alc888_6st_dell_verbs[] = {
7948         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7949         { }
7950 };
7951
7952 static struct hda_verb alc888_3st_hp_2ch_init[] = {
7953         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7954         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7955         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7956         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7957         { }
7958 };
7959
7960 static struct hda_verb alc888_3st_hp_6ch_init[] = {
7961         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7962         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7963         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7964         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7965         { }
7966 };
7967
7968 static struct hda_channel_mode alc888_3st_hp_modes[2] = {
7969         { 2, alc888_3st_hp_2ch_init },
7970         { 6, alc888_3st_hp_6ch_init },
7971 };
7972
7973 /* toggle front-jack and RCA according to the hp-jack state */
7974 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
7975 {
7976         unsigned int present;
7977
7978         present = snd_hda_codec_read(codec, 0x1b, 0,
7979                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7980         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7981                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7982         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7983                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7984 }
7985
7986 /* toggle RCA according to the front-jack state */
7987 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
7988 {
7989         unsigned int present;
7990
7991         present = snd_hda_codec_read(codec, 0x14, 0,
7992                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7993         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7994                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7995 }
7996
7997 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
7998                                              unsigned int res)
7999 {
8000         if ((res >> 26) == ALC880_HP_EVENT)
8001                 alc888_lenovo_ms7195_front_automute(codec);
8002         if ((res >> 26) == ALC880_FRONT_EVENT)
8003                 alc888_lenovo_ms7195_rca_automute(codec);
8004 }
8005
8006 static struct hda_verb alc883_medion_md2_verbs[] = {
8007         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8008         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8009
8010         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8011
8012         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8013         { } /* end */
8014 };
8015
8016 /* toggle speaker-output according to the hp-jack state */
8017 static void alc883_medion_md2_automute(struct hda_codec *codec)
8018 {
8019         unsigned int present;
8020
8021         present = snd_hda_codec_read(codec, 0x14, 0,
8022                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8023         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8024                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8025 }
8026
8027 static void alc883_medion_md2_unsol_event(struct hda_codec *codec,
8028                                           unsigned int res)
8029 {
8030         if ((res >> 26) == ALC880_HP_EVENT)
8031                 alc883_medion_md2_automute(codec);
8032 }
8033
8034 /* toggle speaker-output according to the hp-jack state */
8035 static void alc883_tagra_automute(struct hda_codec *codec)
8036 {
8037         unsigned int present;
8038         unsigned char bits;
8039
8040         present = snd_hda_codec_read(codec, 0x14, 0,
8041                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8042         bits = present ? HDA_AMP_MUTE : 0;
8043         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
8044                                  HDA_AMP_MUTE, bits);
8045         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
8046                                   present ? 1 : 3);
8047 }
8048
8049 static void alc883_tagra_unsol_event(struct hda_codec *codec, unsigned int res)
8050 {
8051         if ((res >> 26) == ALC880_HP_EVENT)
8052                 alc883_tagra_automute(codec);
8053 }
8054
8055 /* toggle speaker-output according to the hp-jack state */
8056 static void alc883_clevo_m720_hp_automute(struct hda_codec *codec)
8057 {
8058         unsigned int present;
8059         unsigned char bits;
8060
8061         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
8062                 & AC_PINSENSE_PRESENCE;
8063         bits = present ? HDA_AMP_MUTE : 0;
8064         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8065                                  HDA_AMP_MUTE, bits);
8066 }
8067
8068 static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
8069 {
8070         unsigned int present;
8071
8072         present = snd_hda_codec_read(codec, 0x18, 0,
8073                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8074         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
8075                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8076 }
8077
8078 static void alc883_clevo_m720_automute(struct hda_codec *codec)
8079 {
8080         alc883_clevo_m720_hp_automute(codec);
8081         alc883_clevo_m720_mic_automute(codec);
8082 }
8083
8084 static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
8085                                            unsigned int res)
8086 {
8087         switch (res >> 26) {
8088         case ALC880_HP_EVENT:
8089                 alc883_clevo_m720_hp_automute(codec);
8090                 break;
8091         case ALC880_MIC_EVENT:
8092                 alc883_clevo_m720_mic_automute(codec);
8093                 break;
8094         }
8095 }
8096
8097 /* toggle speaker-output according to the hp-jack state */
8098 static void alc883_2ch_fujitsu_pi2515_automute(struct hda_codec *codec)
8099 {
8100         unsigned int present;
8101         unsigned char bits;
8102
8103         present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
8104                 & AC_PINSENSE_PRESENCE;
8105         bits = present ? HDA_AMP_MUTE : 0;
8106         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8107                                  HDA_AMP_MUTE, bits);
8108 }
8109
8110 static void alc883_2ch_fujitsu_pi2515_unsol_event(struct hda_codec *codec,
8111                                                   unsigned int res)
8112 {
8113         if ((res >> 26) == ALC880_HP_EVENT)
8114                 alc883_2ch_fujitsu_pi2515_automute(codec);
8115 }
8116
8117 static void alc883_haier_w66_automute(struct hda_codec *codec)
8118 {
8119         unsigned int present;
8120         unsigned char bits;
8121
8122         present = snd_hda_codec_read(codec, 0x1b, 0,
8123                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8124         bits = present ? 0x80 : 0;
8125         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8126                                  0x80, bits);
8127 }
8128
8129 static void alc883_haier_w66_unsol_event(struct hda_codec *codec,
8130                                          unsigned int res)
8131 {
8132         if ((res >> 26) == ALC880_HP_EVENT)
8133                 alc883_haier_w66_automute(codec);
8134 }
8135
8136 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
8137 {
8138         unsigned int present;
8139         unsigned char bits;
8140
8141         present = snd_hda_codec_read(codec, 0x14, 0,
8142                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8143         bits = present ? HDA_AMP_MUTE : 0;
8144         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8145                                  HDA_AMP_MUTE, bits);
8146 }
8147
8148 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
8149 {
8150         unsigned int present;
8151         unsigned char bits;
8152
8153         present = snd_hda_codec_read(codec, 0x1b, 0,
8154                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8155         bits = present ? HDA_AMP_MUTE : 0;
8156         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8157                                  HDA_AMP_MUTE, bits);
8158         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8159                                  HDA_AMP_MUTE, bits);
8160 }
8161
8162 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
8163                                            unsigned int res)
8164 {
8165         if ((res >> 26) == ALC880_HP_EVENT)
8166                 alc883_lenovo_101e_all_automute(codec);
8167         if ((res >> 26) == ALC880_FRONT_EVENT)
8168                 alc883_lenovo_101e_ispeaker_automute(codec);
8169 }
8170
8171 /* toggle speaker-output according to the hp-jack state */
8172 static void alc883_acer_aspire_automute(struct hda_codec *codec)
8173 {
8174         unsigned int present;
8175
8176         present = snd_hda_codec_read(codec, 0x14, 0,
8177                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8178         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8179                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8180         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8181                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8182 }
8183
8184 static void alc883_acer_aspire_unsol_event(struct hda_codec *codec,
8185                                            unsigned int res)
8186 {
8187         if ((res >> 26) == ALC880_HP_EVENT)
8188                 alc883_acer_aspire_automute(codec);
8189 }
8190
8191 static struct hda_verb alc883_acer_eapd_verbs[] = {
8192         /* HP Pin: output 0 (0x0c) */
8193         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8194         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8195         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8196         /* Front Pin: output 0 (0x0c) */
8197         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8198         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8199         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8200         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
8201         /* eanable EAPD on medion laptop */
8202         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
8203         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
8204         /* enable unsolicited event */
8205         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8206         { }
8207 };
8208
8209 static void alc888_6st_dell_front_automute(struct hda_codec *codec)
8210 {
8211         unsigned int present;
8212
8213         present = snd_hda_codec_read(codec, 0x1b, 0,
8214                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8215         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8216                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8217         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8218                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8219         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8220                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8221         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8222                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8223 }
8224
8225 static void alc888_6st_dell_unsol_event(struct hda_codec *codec,
8226                                              unsigned int res)
8227 {
8228         switch (res >> 26) {
8229         case ALC880_HP_EVENT:
8230                 printk("hp_event\n");
8231                 alc888_6st_dell_front_automute(codec);
8232                 break;
8233         }
8234 }
8235
8236 static void alc888_lenovo_sky_front_automute(struct hda_codec *codec)
8237 {
8238         unsigned int mute;
8239         unsigned int present;
8240
8241         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
8242         present = snd_hda_codec_read(codec, 0x1b, 0,
8243                                      AC_VERB_GET_PIN_SENSE, 0);
8244         present = (present & 0x80000000) != 0;
8245         if (present) {
8246                 /* mute internal speaker */
8247                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8248                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8249                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8250                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8251                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8252                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8253                 snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8254                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8255                 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
8256                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8257         } else {
8258                 /* unmute internal speaker if necessary */
8259                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
8260                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8261                                          HDA_AMP_MUTE, mute);
8262                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8263                                          HDA_AMP_MUTE, mute);
8264                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8265                                          HDA_AMP_MUTE, mute);
8266                 snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8267                                          HDA_AMP_MUTE, mute);
8268                 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
8269                                          HDA_AMP_MUTE, mute);
8270         }
8271 }
8272
8273 static void alc883_lenovo_sky_unsol_event(struct hda_codec *codec,
8274                                              unsigned int res)
8275 {
8276         if ((res >> 26) == ALC880_HP_EVENT)
8277                 alc888_lenovo_sky_front_automute(codec);
8278 }
8279
8280 /*
8281  * generic initialization of ADC, input mixers and output mixers
8282  */
8283 static struct hda_verb alc883_auto_init_verbs[] = {
8284         /*
8285          * Unmute ADC0-2 and set the default input to mic-in
8286          */
8287         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8288         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8289         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8290         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8291
8292         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8293          * mixer widget
8294          * Note: PASD motherboards uses the Line In 2 as the input for
8295          * front panel mic (mic 2)
8296          */
8297         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8298         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8299         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8300         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8301         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8302         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8303
8304         /*
8305          * Set up output mixers (0x0c - 0x0f)
8306          */
8307         /* set vol=0 to output mixers */
8308         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8309         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8310         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8311         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8312         /* set up input amps for analog loopback */
8313         /* Amp Indices: DAC = 0, mixer = 1 */
8314         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8315         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8316         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8317         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8318         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8319         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8320         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8321         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8322         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8323         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8324
8325         /* FIXME: use matrix-type input source selection */
8326         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8327         /* Input mixer1 */
8328         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8329         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8330         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8331         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8332         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8333         /* Input mixer2 */
8334         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8335         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8336         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8337         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8338         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8339
8340         { }
8341 };
8342
8343 static struct hda_verb alc888_asus_m90v_verbs[] = {
8344         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8345         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8346         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8347         /* enable unsolicited event */
8348         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8349         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8350         { } /* end */
8351 };
8352
8353 static void alc883_nb_mic_automute(struct hda_codec *codec)
8354 {
8355         unsigned int present;
8356
8357         present = snd_hda_codec_read(codec, 0x18, 0,
8358                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8359         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8360                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
8361         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8362                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
8363 }
8364
8365 static void alc883_M90V_speaker_automute(struct hda_codec *codec)
8366 {
8367         unsigned int present;
8368         unsigned char bits;
8369
8370         present = snd_hda_codec_read(codec, 0x1b, 0,
8371                                      AC_VERB_GET_PIN_SENSE, 0)
8372                 & AC_PINSENSE_PRESENCE;
8373         bits = present ? 0 : PIN_OUT;
8374         snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8375                             bits);
8376         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8377                             bits);
8378         snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8379                             bits);
8380 }
8381
8382 static void alc883_mode2_unsol_event(struct hda_codec *codec,
8383                                            unsigned int res)
8384 {
8385         switch (res >> 26) {
8386         case ALC880_HP_EVENT:
8387                 alc883_M90V_speaker_automute(codec);
8388                 break;
8389         case ALC880_MIC_EVENT:
8390                 alc883_nb_mic_automute(codec);
8391                 break;
8392         }
8393 }
8394
8395 static void alc883_mode2_inithook(struct hda_codec *codec)
8396 {
8397         alc883_M90V_speaker_automute(codec);
8398         alc883_nb_mic_automute(codec);
8399 }
8400
8401 static struct hda_verb alc888_asus_eee1601_verbs[] = {
8402         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8403         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8404         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8405         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8406         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8407         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
8408         {0x20, AC_VERB_SET_PROC_COEF,  0x0838},
8409         /* enable unsolicited event */
8410         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8411         { } /* end */
8412 };
8413
8414 static void alc883_eee1601_speaker_automute(struct hda_codec *codec)
8415 {
8416         unsigned int present;
8417         unsigned char bits;
8418
8419         present = snd_hda_codec_read(codec, 0x14, 0,
8420                                      AC_VERB_GET_PIN_SENSE, 0)
8421                 & AC_PINSENSE_PRESENCE;
8422         bits = present ? 0 : PIN_OUT;
8423         snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8424                             bits);
8425 }
8426
8427 static void alc883_eee1601_unsol_event(struct hda_codec *codec,
8428                                            unsigned int res)
8429 {
8430         switch (res >> 26) {
8431         case ALC880_HP_EVENT:
8432                 alc883_eee1601_speaker_automute(codec);
8433                 break;
8434         }
8435 }
8436
8437 static void alc883_eee1601_inithook(struct hda_codec *codec)
8438 {
8439         alc883_eee1601_speaker_automute(codec);
8440 }
8441
8442 #ifdef CONFIG_SND_HDA_POWER_SAVE
8443 #define alc883_loopbacks        alc880_loopbacks
8444 #endif
8445
8446 /* pcm configuration: identiacal with ALC880 */
8447 #define alc883_pcm_analog_playback      alc880_pcm_analog_playback
8448 #define alc883_pcm_analog_capture       alc880_pcm_analog_capture
8449 #define alc883_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
8450 #define alc883_pcm_digital_playback     alc880_pcm_digital_playback
8451 #define alc883_pcm_digital_capture      alc880_pcm_digital_capture
8452
8453 /*
8454  * configuration and preset
8455  */
8456 static const char *alc883_models[ALC883_MODEL_LAST] = {
8457         [ALC883_3ST_2ch_DIG]    = "3stack-dig",
8458         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
8459         [ALC883_3ST_6ch]        = "3stack-6ch",
8460         [ALC883_6ST_DIG]        = "6stack-dig",
8461         [ALC883_TARGA_DIG]      = "targa-dig",
8462         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
8463         [ALC883_ACER]           = "acer",
8464         [ALC883_ACER_ASPIRE]    = "acer-aspire",
8465         [ALC888_ACER_ASPIRE_4930G]      = "acer-aspire-4930g",
8466         [ALC883_MEDION]         = "medion",
8467         [ALC883_MEDION_MD2]     = "medion-md2",
8468         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
8469         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
8470         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
8471         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
8472         [ALC888_LENOVO_SKY] = "lenovo-sky",
8473         [ALC883_HAIER_W66]      = "haier-w66",
8474         [ALC888_3ST_HP]         = "3stack-hp",
8475         [ALC888_6ST_DELL]       = "6stack-dell",
8476         [ALC883_MITAC]          = "mitac",
8477         [ALC883_CLEVO_M720]     = "clevo-m720",
8478         [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
8479         [ALC888_FUJITSU_XA3530] = "fujitsu-xa3530",
8480         [ALC883_3ST_6ch_INTEL]  = "3stack-6ch-intel",
8481         [ALC1200_ASUS_P5Q]      = "asus-p5q",
8482         [ALC883_AUTO]           = "auto",
8483 };
8484
8485 static struct snd_pci_quirk alc883_cfg_tbl[] = {
8486         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG),
8487         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
8488         SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_ACER_ASPIRE),
8489         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
8490         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
8491         SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_ACER_ASPIRE),
8492         SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
8493                 ALC888_ACER_ASPIRE_4930G),
8494         SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
8495                 ALC888_ACER_ASPIRE_4930G),
8496         SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
8497                 ALC888_ACER_ASPIRE_4930G),
8498         SND_PCI_QUIRK(0x1025, 0, "Acer laptop", ALC883_ACER), /* default Acer */
8499         SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
8500         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
8501         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
8502         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
8503         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
8504         SND_PCI_QUIRK(0x103c, 0x2a66, "HP Acacia", ALC888_3ST_HP),
8505         SND_PCI_QUIRK(0x1043, 0x1873, "Asus M90V", ALC888_ASUS_M90V),
8506         SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
8507         SND_PCI_QUIRK(0x1043, 0x82fe, "Asus P5Q-EM HDMI", ALC1200_ASUS_P5Q),
8508         SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_ASUS_EEE1601),
8509         SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG),
8510         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
8511         SND_PCI_QUIRK(0x1071, 0x8227, "Mitac 82801H", ALC883_MITAC),
8512         SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
8513         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
8514         SND_PCI_QUIRK(0x10f1, 0x2350, "TYAN-S2350", ALC888_6ST_DELL),
8515         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
8516         SND_PCI_QUIRK(0x1458, 0xa002, "MSI", ALC883_6ST_DIG),
8517         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
8518         SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
8519         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
8520         SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC883_TARGA_2ch_DIG),
8521         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
8522         SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
8523         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
8524         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
8525         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
8526         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
8527         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
8528         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
8529         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
8530         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
8531         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
8532         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
8533         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
8534         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
8535         SND_PCI_QUIRK(0x1462, 0x7260, "MSI 7260", ALC883_TARGA_DIG),
8536         SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG),
8537         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
8538         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
8539         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
8540         SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
8541         SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
8542         SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
8543         SND_PCI_QUIRK(0x1558, 0, "Clevo laptop", ALC883_LAPTOP_EAPD),
8544         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
8545         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
8546         SND_PCI_QUIRK(0x1734, 0x1108, "Fujitsu AMILO Pi2515", ALC883_FUJITSU_PI2515),
8547         SND_PCI_QUIRK(0x1734, 0x113d, "Fujitsu AMILO Xa3530",
8548                 ALC888_FUJITSU_XA3530),
8549         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
8550         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8551         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8552         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8553         SND_PCI_QUIRK(0x17aa, 0x101d, "Lenovo Sky", ALC888_LENOVO_SKY),
8554         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
8555         SND_PCI_QUIRK(0x17c0, 0x4085, "MEDION MD96630", ALC888_LENOVO_MS7195_DIG),
8556         SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
8557         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
8558         SND_PCI_QUIRK(0x8086, 0x0001, "DG33BUC", ALC883_3ST_6ch_INTEL),
8559         SND_PCI_QUIRK(0x8086, 0x0002, "DG33FBC", ALC883_3ST_6ch_INTEL),
8560         SND_PCI_QUIRK(0x8086, 0x2503, "82801H", ALC883_MITAC),
8561         SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC883_3ST_6ch_INTEL),
8562         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
8563         {}
8564 };
8565
8566 static struct alc_config_preset alc883_presets[] = {
8567         [ALC883_3ST_2ch_DIG] = {
8568                 .mixers = { alc883_3ST_2ch_mixer },
8569                 .init_verbs = { alc883_init_verbs },
8570                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8571                 .dac_nids = alc883_dac_nids,
8572                 .dig_out_nid = ALC883_DIGOUT_NID,
8573                 .dig_in_nid = ALC883_DIGIN_NID,
8574                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8575                 .channel_mode = alc883_3ST_2ch_modes,
8576                 .input_mux = &alc883_capture_source,
8577         },
8578         [ALC883_3ST_6ch_DIG] = {
8579                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8580                 .init_verbs = { alc883_init_verbs },
8581                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8582                 .dac_nids = alc883_dac_nids,
8583                 .dig_out_nid = ALC883_DIGOUT_NID,
8584                 .dig_in_nid = ALC883_DIGIN_NID,
8585                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8586                 .channel_mode = alc883_3ST_6ch_modes,
8587                 .need_dac_fix = 1,
8588                 .input_mux = &alc883_capture_source,
8589         },
8590         [ALC883_3ST_6ch] = {
8591                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8592                 .init_verbs = { alc883_init_verbs },
8593                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8594                 .dac_nids = alc883_dac_nids,
8595                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8596                 .channel_mode = alc883_3ST_6ch_modes,
8597                 .need_dac_fix = 1,
8598                 .input_mux = &alc883_capture_source,
8599         },
8600         [ALC883_3ST_6ch_INTEL] = {
8601                 .mixers = { alc883_3ST_6ch_intel_mixer, alc883_chmode_mixer },
8602                 .init_verbs = { alc883_init_verbs },
8603                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8604                 .dac_nids = alc883_dac_nids,
8605                 .dig_out_nid = ALC883_DIGOUT_NID,
8606                 .dig_in_nid = ALC883_DIGIN_NID,
8607                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_intel_modes),
8608                 .channel_mode = alc883_3ST_6ch_intel_modes,
8609                 .need_dac_fix = 1,
8610                 .input_mux = &alc883_3stack_6ch_intel,
8611         },
8612         [ALC883_6ST_DIG] = {
8613                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8614                 .init_verbs = { alc883_init_verbs },
8615                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8616                 .dac_nids = alc883_dac_nids,
8617                 .dig_out_nid = ALC883_DIGOUT_NID,
8618                 .dig_in_nid = ALC883_DIGIN_NID,
8619                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8620                 .channel_mode = alc883_sixstack_modes,
8621                 .input_mux = &alc883_capture_source,
8622         },
8623         [ALC883_TARGA_DIG] = {
8624                 .mixers = { alc883_tagra_mixer, alc883_chmode_mixer },
8625                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8626                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8627                 .dac_nids = alc883_dac_nids,
8628                 .dig_out_nid = ALC883_DIGOUT_NID,
8629                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8630                 .channel_mode = alc883_3ST_6ch_modes,
8631                 .need_dac_fix = 1,
8632                 .input_mux = &alc883_capture_source,
8633                 .unsol_event = alc883_tagra_unsol_event,
8634                 .init_hook = alc883_tagra_automute,
8635         },
8636         [ALC883_TARGA_2ch_DIG] = {
8637                 .mixers = { alc883_tagra_2ch_mixer},
8638                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8639                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8640                 .dac_nids = alc883_dac_nids,
8641                 .adc_nids = alc883_adc_nids_alt,
8642                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8643                 .dig_out_nid = ALC883_DIGOUT_NID,
8644                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8645                 .channel_mode = alc883_3ST_2ch_modes,
8646                 .input_mux = &alc883_capture_source,
8647                 .unsol_event = alc883_tagra_unsol_event,
8648                 .init_hook = alc883_tagra_automute,
8649         },
8650         [ALC883_ACER] = {
8651                 .mixers = { alc883_base_mixer },
8652                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
8653                  * and the headphone jack.  Turn this on and rely on the
8654                  * standard mute methods whenever the user wants to turn
8655                  * these outputs off.
8656                  */
8657                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
8658                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8659                 .dac_nids = alc883_dac_nids,
8660                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8661                 .channel_mode = alc883_3ST_2ch_modes,
8662                 .input_mux = &alc883_capture_source,
8663         },
8664         [ALC883_ACER_ASPIRE] = {
8665                 .mixers = { alc883_acer_aspire_mixer },
8666                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
8667                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8668                 .dac_nids = alc883_dac_nids,
8669                 .dig_out_nid = ALC883_DIGOUT_NID,
8670                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8671                 .channel_mode = alc883_3ST_2ch_modes,
8672                 .input_mux = &alc883_capture_source,
8673                 .unsol_event = alc883_acer_aspire_unsol_event,
8674                 .init_hook = alc883_acer_aspire_automute,
8675         },
8676         [ALC888_ACER_ASPIRE_4930G] = {
8677                 .mixers = { alc888_base_mixer,
8678                                 alc883_chmode_mixer },
8679                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
8680                                 alc888_acer_aspire_4930g_verbs },
8681                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8682                 .dac_nids = alc883_dac_nids,
8683                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
8684                 .adc_nids = alc883_adc_nids_rev,
8685                 .capsrc_nids = alc883_capsrc_nids_rev,
8686                 .dig_out_nid = ALC883_DIGOUT_NID,
8687                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8688                 .channel_mode = alc883_3ST_6ch_modes,
8689                 .need_dac_fix = 1,
8690                 .num_mux_defs =
8691                         ARRAY_SIZE(alc888_2_capture_sources),
8692                 .input_mux = alc888_2_capture_sources,
8693                 .unsol_event = alc888_acer_aspire_4930g_unsol_event,
8694                 .init_hook = alc888_acer_aspire_4930g_automute,
8695         },
8696         [ALC883_MEDION] = {
8697                 .mixers = { alc883_fivestack_mixer,
8698                             alc883_chmode_mixer },
8699                 .init_verbs = { alc883_init_verbs,
8700                                 alc883_medion_eapd_verbs },
8701                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8702                 .dac_nids = alc883_dac_nids,
8703                 .adc_nids = alc883_adc_nids_alt,
8704                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8705                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8706                 .channel_mode = alc883_sixstack_modes,
8707                 .input_mux = &alc883_capture_source,
8708         },
8709         [ALC883_MEDION_MD2] = {
8710                 .mixers = { alc883_medion_md2_mixer},
8711                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
8712                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8713                 .dac_nids = alc883_dac_nids,
8714                 .dig_out_nid = ALC883_DIGOUT_NID,
8715                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8716                 .channel_mode = alc883_3ST_2ch_modes,
8717                 .input_mux = &alc883_capture_source,
8718                 .unsol_event = alc883_medion_md2_unsol_event,
8719                 .init_hook = alc883_medion_md2_automute,
8720         },
8721         [ALC883_LAPTOP_EAPD] = {
8722                 .mixers = { alc883_base_mixer },
8723                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
8724                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8725                 .dac_nids = alc883_dac_nids,
8726                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8727                 .channel_mode = alc883_3ST_2ch_modes,
8728                 .input_mux = &alc883_capture_source,
8729         },
8730         [ALC883_CLEVO_M720] = {
8731                 .mixers = { alc883_clevo_m720_mixer },
8732                 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
8733                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8734                 .dac_nids = alc883_dac_nids,
8735                 .dig_out_nid = ALC883_DIGOUT_NID,
8736                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8737                 .channel_mode = alc883_3ST_2ch_modes,
8738                 .input_mux = &alc883_capture_source,
8739                 .unsol_event = alc883_clevo_m720_unsol_event,
8740                 .init_hook = alc883_clevo_m720_automute,
8741         },
8742         [ALC883_LENOVO_101E_2ch] = {
8743                 .mixers = { alc883_lenovo_101e_2ch_mixer},
8744                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
8745                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8746                 .dac_nids = alc883_dac_nids,
8747                 .adc_nids = alc883_adc_nids_alt,
8748                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8749                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8750                 .channel_mode = alc883_3ST_2ch_modes,
8751                 .input_mux = &alc883_lenovo_101e_capture_source,
8752                 .unsol_event = alc883_lenovo_101e_unsol_event,
8753                 .init_hook = alc883_lenovo_101e_all_automute,
8754         },
8755         [ALC883_LENOVO_NB0763] = {
8756                 .mixers = { alc883_lenovo_nb0763_mixer },
8757                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
8758                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8759                 .dac_nids = alc883_dac_nids,
8760                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8761                 .channel_mode = alc883_3ST_2ch_modes,
8762                 .need_dac_fix = 1,
8763                 .input_mux = &alc883_lenovo_nb0763_capture_source,
8764                 .unsol_event = alc883_medion_md2_unsol_event,
8765                 .init_hook = alc883_medion_md2_automute,
8766         },
8767         [ALC888_LENOVO_MS7195_DIG] = {
8768                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8769                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
8770                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8771                 .dac_nids = alc883_dac_nids,
8772                 .dig_out_nid = ALC883_DIGOUT_NID,
8773                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8774                 .channel_mode = alc883_3ST_6ch_modes,
8775                 .need_dac_fix = 1,
8776                 .input_mux = &alc883_capture_source,
8777                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
8778                 .init_hook = alc888_lenovo_ms7195_front_automute,
8779         },
8780         [ALC883_HAIER_W66] = {
8781                 .mixers = { alc883_tagra_2ch_mixer},
8782                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
8783                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8784                 .dac_nids = alc883_dac_nids,
8785                 .dig_out_nid = ALC883_DIGOUT_NID,
8786                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8787                 .channel_mode = alc883_3ST_2ch_modes,
8788                 .input_mux = &alc883_capture_source,
8789                 .unsol_event = alc883_haier_w66_unsol_event,
8790                 .init_hook = alc883_haier_w66_automute,
8791         },
8792         [ALC888_3ST_HP] = {
8793                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8794                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
8795                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8796                 .dac_nids = alc883_dac_nids,
8797                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
8798                 .channel_mode = alc888_3st_hp_modes,
8799                 .need_dac_fix = 1,
8800                 .input_mux = &alc883_capture_source,
8801         },
8802         [ALC888_6ST_DELL] = {
8803                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8804                 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
8805                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8806                 .dac_nids = alc883_dac_nids,
8807                 .dig_out_nid = ALC883_DIGOUT_NID,
8808                 .dig_in_nid = ALC883_DIGIN_NID,
8809                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8810                 .channel_mode = alc883_sixstack_modes,
8811                 .input_mux = &alc883_capture_source,
8812                 .unsol_event = alc888_6st_dell_unsol_event,
8813                 .init_hook = alc888_6st_dell_front_automute,
8814         },
8815         [ALC883_MITAC] = {
8816                 .mixers = { alc883_mitac_mixer },
8817                 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
8818                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8819                 .dac_nids = alc883_dac_nids,
8820                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8821                 .channel_mode = alc883_3ST_2ch_modes,
8822                 .input_mux = &alc883_capture_source,
8823                 .unsol_event = alc883_mitac_unsol_event,
8824                 .init_hook = alc883_mitac_automute,
8825         },
8826         [ALC883_FUJITSU_PI2515] = {
8827                 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
8828                 .init_verbs = { alc883_init_verbs,
8829                                 alc883_2ch_fujitsu_pi2515_verbs},
8830                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8831                 .dac_nids = alc883_dac_nids,
8832                 .dig_out_nid = ALC883_DIGOUT_NID,
8833                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8834                 .channel_mode = alc883_3ST_2ch_modes,
8835                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
8836                 .unsol_event = alc883_2ch_fujitsu_pi2515_unsol_event,
8837                 .init_hook = alc883_2ch_fujitsu_pi2515_automute,
8838         },
8839         [ALC888_FUJITSU_XA3530] = {
8840                 .mixers = { alc888_base_mixer, alc883_chmode_mixer },
8841                 .init_verbs = { alc883_init_verbs,
8842                         alc888_fujitsu_xa3530_verbs },
8843                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8844                 .dac_nids = alc883_dac_nids,
8845                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
8846                 .adc_nids = alc883_adc_nids_rev,
8847                 .capsrc_nids = alc883_capsrc_nids_rev,
8848                 .dig_out_nid = ALC883_DIGOUT_NID,
8849                 .num_channel_mode = ARRAY_SIZE(alc888_4ST_8ch_intel_modes),
8850                 .channel_mode = alc888_4ST_8ch_intel_modes,
8851                 .num_mux_defs =
8852                         ARRAY_SIZE(alc888_2_capture_sources),
8853                 .input_mux = alc888_2_capture_sources,
8854                 .unsol_event = alc888_fujitsu_xa3530_unsol_event,
8855                 .init_hook = alc888_fujitsu_xa3530_automute,
8856         },
8857         [ALC888_LENOVO_SKY] = {
8858                 .mixers = { alc888_lenovo_sky_mixer, alc883_chmode_mixer },
8859                 .init_verbs = { alc883_init_verbs, alc888_lenovo_sky_verbs},
8860                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8861                 .dac_nids = alc883_dac_nids,
8862                 .dig_out_nid = ALC883_DIGOUT_NID,
8863                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8864                 .channel_mode = alc883_sixstack_modes,
8865                 .need_dac_fix = 1,
8866                 .input_mux = &alc883_lenovo_sky_capture_source,
8867                 .unsol_event = alc883_lenovo_sky_unsol_event,
8868                 .init_hook = alc888_lenovo_sky_front_automute,
8869         },
8870         [ALC888_ASUS_M90V] = {
8871                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8872                 .init_verbs = { alc883_init_verbs, alc888_asus_m90v_verbs },
8873                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8874                 .dac_nids = alc883_dac_nids,
8875                 .dig_out_nid = ALC883_DIGOUT_NID,
8876                 .dig_in_nid = ALC883_DIGIN_NID,
8877                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8878                 .channel_mode = alc883_3ST_6ch_modes,
8879                 .need_dac_fix = 1,
8880                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
8881                 .unsol_event = alc883_mode2_unsol_event,
8882                 .init_hook = alc883_mode2_inithook,
8883         },
8884         [ALC888_ASUS_EEE1601] = {
8885                 .mixers = { alc883_asus_eee1601_mixer },
8886                 .cap_mixer = alc883_asus_eee1601_cap_mixer,
8887                 .init_verbs = { alc883_init_verbs, alc888_asus_eee1601_verbs },
8888                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8889                 .dac_nids = alc883_dac_nids,
8890                 .dig_out_nid = ALC883_DIGOUT_NID,
8891                 .dig_in_nid = ALC883_DIGIN_NID,
8892                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8893                 .channel_mode = alc883_3ST_2ch_modes,
8894                 .need_dac_fix = 1,
8895                 .input_mux = &alc883_asus_eee1601_capture_source,
8896                 .unsol_event = alc883_eee1601_unsol_event,
8897                 .init_hook = alc883_eee1601_inithook,
8898         },
8899         [ALC1200_ASUS_P5Q] = {
8900                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8901                 .init_verbs = { alc883_init_verbs },
8902                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8903                 .dac_nids = alc883_dac_nids,
8904                 .dig_out_nid = ALC1200_DIGOUT_NID,
8905                 .dig_in_nid = ALC883_DIGIN_NID,
8906                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8907                 .channel_mode = alc883_sixstack_modes,
8908                 .input_mux = &alc883_capture_source,
8909         },
8910 };
8911
8912
8913 /*
8914  * BIOS auto configuration
8915  */
8916 static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
8917                                               hda_nid_t nid, int pin_type,
8918                                               int dac_idx)
8919 {
8920         /* set as output */
8921         struct alc_spec *spec = codec->spec;
8922         int idx;
8923
8924         alc_set_pin_output(codec, nid, pin_type);
8925         if (spec->multiout.dac_nids[dac_idx] == 0x25)
8926                 idx = 4;
8927         else
8928                 idx = spec->multiout.dac_nids[dac_idx] - 2;
8929         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
8930
8931 }
8932
8933 static void alc883_auto_init_multi_out(struct hda_codec *codec)
8934 {
8935         struct alc_spec *spec = codec->spec;
8936         int i;
8937
8938         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
8939         for (i = 0; i <= HDA_SIDE; i++) {
8940                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
8941                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
8942                 if (nid)
8943                         alc883_auto_set_output_and_unmute(codec, nid, pin_type,
8944                                                           i);
8945         }
8946 }
8947
8948 static void alc883_auto_init_hp_out(struct hda_codec *codec)
8949 {
8950         struct alc_spec *spec = codec->spec;
8951         hda_nid_t pin;
8952
8953         pin = spec->autocfg.hp_pins[0];
8954         if (pin) /* connect to front */
8955                 /* use dac 0 */
8956                 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
8957         pin = spec->autocfg.speaker_pins[0];
8958         if (pin)
8959                 alc883_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
8960 }
8961
8962 #define alc883_is_input_pin(nid)        alc880_is_input_pin(nid)
8963 #define ALC883_PIN_CD_NID               ALC880_PIN_CD_NID
8964
8965 static void alc883_auto_init_analog_input(struct hda_codec *codec)
8966 {
8967         struct alc_spec *spec = codec->spec;
8968         int i;
8969
8970         for (i = 0; i < AUTO_PIN_LAST; i++) {
8971                 hda_nid_t nid = spec->autocfg.input_pins[i];
8972                 if (alc883_is_input_pin(nid)) {
8973                         snd_hda_codec_write(codec, nid, 0,
8974                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
8975                                             (i <= AUTO_PIN_FRONT_MIC ?
8976                                              PIN_VREF80 : PIN_IN));
8977                         if (nid != ALC883_PIN_CD_NID)
8978                                 snd_hda_codec_write(codec, nid, 0,
8979                                                     AC_VERB_SET_AMP_GAIN_MUTE,
8980                                                     AMP_OUT_MUTE);
8981                 }
8982         }
8983 }
8984
8985 #define alc883_auto_init_input_src      alc882_auto_init_input_src
8986
8987 /* almost identical with ALC880 parser... */
8988 static int alc883_parse_auto_config(struct hda_codec *codec)
8989 {
8990         struct alc_spec *spec = codec->spec;
8991         int err = alc880_parse_auto_config(codec);
8992         struct auto_pin_cfg *cfg = &spec->autocfg;
8993         int i;
8994
8995         if (err < 0)
8996                 return err;
8997         else if (!err)
8998                 return 0; /* no config found */
8999
9000         err = alc_auto_add_mic_boost(codec);
9001         if (err < 0)
9002                 return err;
9003
9004         /* hack - override the init verbs */
9005         spec->init_verbs[0] = alc883_auto_init_verbs;
9006
9007         /* setup input_mux for ALC889 */
9008         if (codec->vendor_id == 0x10ec0889) {
9009                 /* digital-mic input pin is excluded in alc880_auto_create..()
9010                  * because it's under 0x18
9011                  */
9012                 if (cfg->input_pins[AUTO_PIN_MIC] == 0x12 ||
9013                     cfg->input_pins[AUTO_PIN_FRONT_MIC] == 0x12) {
9014                         struct hda_input_mux *imux = &spec->private_imux[0];
9015                         for (i = 1; i < 3; i++)
9016                                 memcpy(&spec->private_imux[i],
9017                                        &spec->private_imux[0],
9018                                        sizeof(spec->private_imux[0]));
9019                         imux->items[imux->num_items].label = "Int DMic";
9020                         imux->items[imux->num_items].index = 0x0b;
9021                         imux->num_items++;
9022                         spec->num_mux_defs = 3;
9023                         spec->input_mux = spec->private_imux;
9024                 }
9025         }
9026
9027         return 1; /* config found */
9028 }
9029
9030 /* additional initialization for auto-configuration model */
9031 static void alc883_auto_init(struct hda_codec *codec)
9032 {
9033         struct alc_spec *spec = codec->spec;
9034         alc883_auto_init_multi_out(codec);
9035         alc883_auto_init_hp_out(codec);
9036         alc883_auto_init_analog_input(codec);
9037         alc883_auto_init_input_src(codec);
9038         if (spec->unsol_event)
9039                 alc_inithook(codec);
9040 }
9041
9042 static int patch_alc883(struct hda_codec *codec)
9043 {
9044         struct alc_spec *spec;
9045         int err, board_config;
9046
9047         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
9048         if (spec == NULL)
9049                 return -ENOMEM;
9050
9051         codec->spec = spec;
9052
9053         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
9054
9055         board_config = snd_hda_check_board_config(codec, ALC883_MODEL_LAST,
9056                                                   alc883_models,
9057                                                   alc883_cfg_tbl);
9058         if (board_config < 0) {
9059                 printk(KERN_INFO "hda_codec: Unknown model for ALC883, "
9060                        "trying auto-probe from BIOS...\n");
9061                 board_config = ALC883_AUTO;
9062         }
9063
9064         if (board_config == ALC883_AUTO) {
9065                 /* automatic parse from the BIOS config */
9066                 err = alc883_parse_auto_config(codec);
9067                 if (err < 0) {
9068                         alc_free(codec);
9069                         return err;
9070                 } else if (!err) {
9071                         printk(KERN_INFO
9072                                "hda_codec: Cannot set up configuration "
9073                                "from BIOS.  Using base mode...\n");
9074                         board_config = ALC883_3ST_2ch_DIG;
9075                 }
9076         }
9077
9078         if (board_config != ALC883_AUTO)
9079                 setup_preset(spec, &alc883_presets[board_config]);
9080
9081         switch (codec->vendor_id) {
9082         case 0x10ec0888:
9083                 if (codec->revision_id == 0x100101) {
9084                         spec->stream_name_analog = "ALC1200 Analog";
9085                         spec->stream_name_digital = "ALC1200 Digital";
9086                 } else {
9087                         spec->stream_name_analog = "ALC888 Analog";
9088                         spec->stream_name_digital = "ALC888 Digital";
9089                 }
9090                 if (!spec->num_adc_nids) {
9091                         spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
9092                         spec->adc_nids = alc883_adc_nids;
9093                 }
9094                 if (!spec->capsrc_nids)
9095                         spec->capsrc_nids = alc883_capsrc_nids;
9096                 spec->capture_style = CAPT_MIX; /* matrix-style capture */
9097                 break;
9098         case 0x10ec0889:
9099                 spec->stream_name_analog = "ALC889 Analog";
9100                 spec->stream_name_digital = "ALC889 Digital";
9101                 if (!spec->num_adc_nids) {
9102                         spec->num_adc_nids = ARRAY_SIZE(alc889_adc_nids);
9103                         spec->adc_nids = alc889_adc_nids;
9104                 }
9105                 if (!spec->capsrc_nids)
9106                         spec->capsrc_nids = alc889_capsrc_nids;
9107                 spec->capture_style = CAPT_1MUX_MIX; /* 1mux/Nmix-style
9108                                                         capture */
9109                 break;
9110         default:
9111                 spec->stream_name_analog = "ALC883 Analog";
9112                 spec->stream_name_digital = "ALC883 Digital";
9113                 if (!spec->num_adc_nids) {
9114                         spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
9115                         spec->adc_nids = alc883_adc_nids;
9116                 }
9117                 if (!spec->capsrc_nids)
9118                         spec->capsrc_nids = alc883_capsrc_nids;
9119                 spec->capture_style = CAPT_MIX; /* matrix-style capture */
9120                 break;
9121         }
9122
9123         spec->stream_analog_playback = &alc883_pcm_analog_playback;
9124         spec->stream_analog_capture = &alc883_pcm_analog_capture;
9125         spec->stream_analog_alt_capture = &alc883_pcm_analog_alt_capture;
9126
9127         spec->stream_digital_playback = &alc883_pcm_digital_playback;
9128         spec->stream_digital_capture = &alc883_pcm_digital_capture;
9129
9130         if (!spec->cap_mixer)
9131                 set_capture_mixer(spec);
9132
9133         spec->vmaster_nid = 0x0c;
9134
9135         codec->patch_ops = alc_patch_ops;
9136         if (board_config == ALC883_AUTO)
9137                 spec->init_hook = alc883_auto_init;
9138
9139 #ifdef CONFIG_SND_HDA_POWER_SAVE
9140         if (!spec->loopback.amplist)
9141                 spec->loopback.amplist = alc883_loopbacks;
9142 #endif
9143         codec->proc_widget_hook = print_realtek_coef;
9144
9145         return 0;
9146 }
9147
9148 /*
9149  * ALC262 support
9150  */
9151
9152 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
9153 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
9154
9155 #define alc262_dac_nids         alc260_dac_nids
9156 #define alc262_adc_nids         alc882_adc_nids
9157 #define alc262_adc_nids_alt     alc882_adc_nids_alt
9158 #define alc262_capsrc_nids      alc882_capsrc_nids
9159 #define alc262_capsrc_nids_alt  alc882_capsrc_nids_alt
9160
9161 #define alc262_modes            alc260_modes
9162 #define alc262_capture_source   alc882_capture_source
9163
9164 static hda_nid_t alc262_dmic_adc_nids[1] = {
9165         /* ADC0 */
9166         0x09
9167 };
9168
9169 static hda_nid_t alc262_dmic_capsrc_nids[1] = { 0x22 };
9170
9171 static struct snd_kcontrol_new alc262_base_mixer[] = {
9172         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9173         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9174         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9175         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9176         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9177         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9178         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9179         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9180         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9181         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9182         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9183         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9184         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9185            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
9186         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
9187         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9188         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
9189         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
9190         { } /* end */
9191 };
9192
9193 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
9194         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9195         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9196         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9197         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9198         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9199         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9200         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9201         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9202         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9203         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9204         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9205         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9206         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9207            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
9208         /*HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),*/
9209         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9210         { } /* end */
9211 };
9212
9213 /* update HP, line and mono-out pins according to the master switch */
9214 static void alc262_hp_master_update(struct hda_codec *codec)
9215 {
9216         struct alc_spec *spec = codec->spec;
9217         int val = spec->master_sw;
9218
9219         /* HP & line-out */
9220         snd_hda_codec_write_cache(codec, 0x1b, 0,
9221                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9222                                   val ? PIN_HP : 0);
9223         snd_hda_codec_write_cache(codec, 0x15, 0,
9224                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9225                                   val ? PIN_HP : 0);
9226         /* mono (speaker) depending on the HP jack sense */
9227         val = val && !spec->jack_present;
9228         snd_hda_codec_write_cache(codec, 0x16, 0,
9229                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9230                                   val ? PIN_OUT : 0);
9231 }
9232
9233 static void alc262_hp_bpc_automute(struct hda_codec *codec)
9234 {
9235         struct alc_spec *spec = codec->spec;
9236         unsigned int presence;
9237         presence = snd_hda_codec_read(codec, 0x1b, 0,
9238                                       AC_VERB_GET_PIN_SENSE, 0);
9239         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
9240         alc262_hp_master_update(codec);
9241 }
9242
9243 static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res)
9244 {
9245         if ((res >> 26) != ALC880_HP_EVENT)
9246                 return;
9247         alc262_hp_bpc_automute(codec);
9248 }
9249
9250 static void alc262_hp_wildwest_automute(struct hda_codec *codec)
9251 {
9252         struct alc_spec *spec = codec->spec;
9253         unsigned int presence;
9254         presence = snd_hda_codec_read(codec, 0x15, 0,
9255                                       AC_VERB_GET_PIN_SENSE, 0);
9256         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
9257         alc262_hp_master_update(codec);
9258 }
9259
9260 static void alc262_hp_wildwest_unsol_event(struct hda_codec *codec,
9261                                            unsigned int res)
9262 {
9263         if ((res >> 26) != ALC880_HP_EVENT)
9264                 return;
9265         alc262_hp_wildwest_automute(codec);
9266 }
9267
9268 static int alc262_hp_master_sw_get(struct snd_kcontrol *kcontrol,
9269                                    struct snd_ctl_elem_value *ucontrol)
9270 {
9271         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9272         struct alc_spec *spec = codec->spec;
9273         *ucontrol->value.integer.value = spec->master_sw;
9274         return 0;
9275 }
9276
9277 static int alc262_hp_master_sw_put(struct snd_kcontrol *kcontrol,
9278                                    struct snd_ctl_elem_value *ucontrol)
9279 {
9280         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9281         struct alc_spec *spec = codec->spec;
9282         int val = !!*ucontrol->value.integer.value;
9283
9284         if (val == spec->master_sw)
9285                 return 0;
9286         spec->master_sw = val;
9287         alc262_hp_master_update(codec);
9288         return 1;
9289 }
9290
9291 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
9292         {
9293                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9294                 .name = "Master Playback Switch",
9295                 .info = snd_ctl_boolean_mono_info,
9296                 .get = alc262_hp_master_sw_get,
9297                 .put = alc262_hp_master_sw_put,
9298         },
9299         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9300         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9301         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9302         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
9303                               HDA_OUTPUT),
9304         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
9305                             HDA_OUTPUT),
9306         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9307         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9308         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9309         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9310         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9311         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9312         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9313         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9314         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9315         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9316         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9317         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
9318         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
9319         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
9320         { } /* end */
9321 };
9322
9323 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
9324         {
9325                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9326                 .name = "Master Playback Switch",
9327                 .info = snd_ctl_boolean_mono_info,
9328                 .get = alc262_hp_master_sw_get,
9329                 .put = alc262_hp_master_sw_put,
9330         },
9331         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9332         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9333         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9334         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9335         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
9336                               HDA_OUTPUT),
9337         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
9338                             HDA_OUTPUT),
9339         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
9340         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
9341         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
9342         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
9343         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
9344         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9345         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9346         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9347         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
9348         { } /* end */
9349 };
9350
9351 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
9352         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9353         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9354         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
9355         { } /* end */
9356 };
9357
9358 /* mute/unmute internal speaker according to the hp jack and mute state */
9359 static void alc262_hp_t5735_automute(struct hda_codec *codec, int force)
9360 {
9361         struct alc_spec *spec = codec->spec;
9362
9363         if (force || !spec->sense_updated) {
9364                 unsigned int present;
9365                 present = snd_hda_codec_read(codec, 0x15, 0,
9366                                              AC_VERB_GET_PIN_SENSE, 0);
9367                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
9368                 spec->sense_updated = 1;
9369         }
9370         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0, HDA_AMP_MUTE,
9371                                  spec->jack_present ? HDA_AMP_MUTE : 0);
9372 }
9373
9374 static void alc262_hp_t5735_unsol_event(struct hda_codec *codec,
9375                                         unsigned int res)
9376 {
9377         if ((res >> 26) != ALC880_HP_EVENT)
9378                 return;
9379         alc262_hp_t5735_automute(codec, 1);
9380 }
9381
9382 static void alc262_hp_t5735_init_hook(struct hda_codec *codec)
9383 {
9384         alc262_hp_t5735_automute(codec, 1);
9385 }
9386
9387 static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
9388         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9389         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9390         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9391         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9392         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9393         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9394         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9395         { } /* end */
9396 };
9397
9398 static struct hda_verb alc262_hp_t5735_verbs[] = {
9399         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9400         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9401
9402         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9403         { }
9404 };
9405
9406 static struct snd_kcontrol_new alc262_hp_rp5700_mixer[] = {
9407         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9408         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9409         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
9410         HDA_CODEC_MUTE("Speaker Playback Switch", 0x16, 0x0, HDA_OUTPUT),
9411         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
9412         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
9413         { } /* end */
9414 };
9415
9416 static struct hda_verb alc262_hp_rp5700_verbs[] = {
9417         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9418         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9419         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9420         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9421         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9422         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9423         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9424         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9425         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
9426         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
9427         {}
9428 };
9429
9430 static struct hda_input_mux alc262_hp_rp5700_capture_source = {
9431         .num_items = 1,
9432         .items = {
9433                 { "Line", 0x1 },
9434         },
9435 };
9436
9437 /* bind hp and internal speaker mute (with plug check) */
9438 static int alc262_sony_master_sw_put(struct snd_kcontrol *kcontrol,
9439                                      struct snd_ctl_elem_value *ucontrol)
9440 {
9441         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9442         long *valp = ucontrol->value.integer.value;
9443         int change;
9444
9445         /* change hp mute */
9446         change = snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
9447                                           HDA_AMP_MUTE,
9448                                           valp[0] ? 0 : HDA_AMP_MUTE);
9449         change |= snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
9450                                            HDA_AMP_MUTE,
9451                                            valp[1] ? 0 : HDA_AMP_MUTE);
9452         if (change) {
9453                 /* change speaker according to HP jack state */
9454                 struct alc_spec *spec = codec->spec;
9455                 unsigned int mute;
9456                 if (spec->jack_present)
9457                         mute = HDA_AMP_MUTE;
9458                 else
9459                         mute = snd_hda_codec_amp_read(codec, 0x15, 0,
9460                                                       HDA_OUTPUT, 0);
9461                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9462                                          HDA_AMP_MUTE, mute);
9463         }
9464         return change;
9465 }
9466
9467 static struct snd_kcontrol_new alc262_sony_mixer[] = {
9468         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9469         {
9470                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9471                 .name = "Master Playback Switch",
9472                 .info = snd_hda_mixer_amp_switch_info,
9473                 .get = snd_hda_mixer_amp_switch_get,
9474                 .put = alc262_sony_master_sw_put,
9475                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
9476         },
9477         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9478         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9479         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9480         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9481         { } /* end */
9482 };
9483
9484 static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
9485         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9486         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9487         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9488         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9489         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9490         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9491         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9492         { } /* end */
9493 };
9494
9495 #define alc262_capture_mixer            alc882_capture_mixer
9496 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
9497
9498 /*
9499  * generic initialization of ADC, input mixers and output mixers
9500  */
9501 static struct hda_verb alc262_init_verbs[] = {
9502         /*
9503          * Unmute ADC0-2 and set the default input to mic-in
9504          */
9505         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9506         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9507         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9508         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9509         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9510         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9511
9512         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9513          * mixer widget
9514          * Note: PASD motherboards uses the Line In 2 as the input for
9515          * front panel mic (mic 2)
9516          */
9517         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9518         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9519         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9520         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9521         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9522         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9523
9524         /*
9525          * Set up output mixers (0x0c - 0x0e)
9526          */
9527         /* set vol=0 to output mixers */
9528         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9529         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9530         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9531         /* set up input amps for analog loopback */
9532         /* Amp Indices: DAC = 0, mixer = 1 */
9533         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9534         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9535         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9536         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9537         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9538         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9539
9540         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9541         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9542         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9543         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9544         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9545         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9546
9547         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9548         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9549         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9550         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9551         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9552
9553         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
9554         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
9555
9556         /* FIXME: use matrix-type input source selection */
9557         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9558         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9559         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9560         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9561         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9562         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9563         /* Input mixer2 */
9564         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9565         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9566         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9567         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9568         /* Input mixer3 */
9569         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9570         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9571         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9572         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9573
9574         { }
9575 };
9576
9577 static struct hda_verb alc262_eapd_verbs[] = {
9578         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
9579         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
9580         { }
9581 };
9582
9583 static struct hda_verb alc262_hippo_unsol_verbs[] = {
9584         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9585         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9586         {}
9587 };
9588
9589 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
9590         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9591         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9592         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9593
9594         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9595         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9596         {}
9597 };
9598
9599 static struct hda_verb alc262_sony_unsol_verbs[] = {
9600         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9601         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9602         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
9603
9604         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9605         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9606         {}
9607 };
9608
9609 static struct hda_input_mux alc262_dmic_capture_source = {
9610         .num_items = 2,
9611         .items = {
9612                 { "Int DMic", 0x9 },
9613                 { "Mic", 0x0 },
9614         },
9615 };
9616
9617 static struct snd_kcontrol_new alc262_toshiba_s06_mixer[] = {
9618         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9619         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9620         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9621         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9622         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9623         { } /* end */
9624 };
9625
9626 static struct hda_verb alc262_toshiba_s06_verbs[] = {
9627         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9628         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9629         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9630         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9631         {0x22, AC_VERB_SET_CONNECT_SEL, 0x09},
9632         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9633         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
9634         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9635         {}
9636 };
9637
9638 static void alc262_dmic_automute(struct hda_codec *codec)
9639 {
9640         unsigned int present;
9641
9642         present = snd_hda_codec_read(codec, 0x18, 0,
9643                                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9644         snd_hda_codec_write(codec, 0x22, 0,
9645                                 AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x09);
9646 }
9647
9648 /* toggle speaker-output according to the hp-jack state */
9649 static void alc262_toshiba_s06_speaker_automute(struct hda_codec *codec)
9650 {
9651         unsigned int present;
9652         unsigned char bits;
9653
9654         present = snd_hda_codec_read(codec, 0x15, 0,
9655                                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9656         bits = present ? 0 : PIN_OUT;
9657         snd_hda_codec_write(codec, 0x14, 0,
9658                                         AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
9659 }
9660
9661
9662
9663 /* unsolicited event for HP jack sensing */
9664 static void alc262_toshiba_s06_unsol_event(struct hda_codec *codec,
9665                                        unsigned int res)
9666 {
9667         if ((res >> 26) == ALC880_HP_EVENT)
9668                 alc262_toshiba_s06_speaker_automute(codec);
9669         if ((res >> 26) == ALC880_MIC_EVENT)
9670                 alc262_dmic_automute(codec);
9671
9672 }
9673
9674 static void alc262_toshiba_s06_init_hook(struct hda_codec *codec)
9675 {
9676         alc262_toshiba_s06_speaker_automute(codec);
9677         alc262_dmic_automute(codec);
9678 }
9679
9680 /* mute/unmute internal speaker according to the hp jack and mute state */
9681 static void alc262_hippo_automute(struct hda_codec *codec)
9682 {
9683         struct alc_spec *spec = codec->spec;
9684         unsigned int mute;
9685         unsigned int present;
9686
9687         /* need to execute and sync at first */
9688         snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
9689         present = snd_hda_codec_read(codec, 0x15, 0,
9690                                      AC_VERB_GET_PIN_SENSE, 0);
9691         spec->jack_present = (present & 0x80000000) != 0;
9692         if (spec->jack_present) {
9693                 /* mute internal speaker */
9694                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9695                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9696         } else {
9697                 /* unmute internal speaker if necessary */
9698                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
9699                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9700                                          HDA_AMP_MUTE, mute);
9701         }
9702 }
9703
9704 /* unsolicited event for HP jack sensing */
9705 static void alc262_hippo_unsol_event(struct hda_codec *codec,
9706                                        unsigned int res)
9707 {
9708         if ((res >> 26) != ALC880_HP_EVENT)
9709                 return;
9710         alc262_hippo_automute(codec);
9711 }
9712
9713 static void alc262_hippo1_automute(struct hda_codec *codec)
9714 {
9715         unsigned int mute;
9716         unsigned int present;
9717
9718         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9719         present = snd_hda_codec_read(codec, 0x1b, 0,
9720                                      AC_VERB_GET_PIN_SENSE, 0);
9721         present = (present & 0x80000000) != 0;
9722         if (present) {
9723                 /* mute internal speaker */
9724                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9725                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9726         } else {
9727                 /* unmute internal speaker if necessary */
9728                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
9729                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9730                                          HDA_AMP_MUTE, mute);
9731         }
9732 }
9733
9734 /* unsolicited event for HP jack sensing */
9735 static void alc262_hippo1_unsol_event(struct hda_codec *codec,
9736                                        unsigned int res)
9737 {
9738         if ((res >> 26) != ALC880_HP_EVENT)
9739                 return;
9740         alc262_hippo1_automute(codec);
9741 }
9742
9743 /*
9744  * nec model
9745  *  0x15 = headphone
9746  *  0x16 = internal speaker
9747  *  0x18 = external mic
9748  */
9749
9750 static struct snd_kcontrol_new alc262_nec_mixer[] = {
9751         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
9752         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 0, 0x0, HDA_OUTPUT),
9753
9754         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9755         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9756         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9757
9758         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9759         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9760         { } /* end */
9761 };
9762
9763 static struct hda_verb alc262_nec_verbs[] = {
9764         /* Unmute Speaker */
9765         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9766
9767         /* Headphone */
9768         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9769         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9770
9771         /* External mic to headphone */
9772         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9773         /* External mic to speaker */
9774         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9775         {}
9776 };
9777
9778 /*
9779  * fujitsu model
9780  *  0x14 = headphone/spdif-out, 0x15 = internal speaker,
9781  *  0x1b = port replicator headphone out
9782  */
9783
9784 #define ALC_HP_EVENT    0x37
9785
9786 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
9787         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9788         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9789         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9790         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9791         {}
9792 };
9793
9794 static struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
9795         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9796         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9797         {}
9798 };
9799
9800 static struct hda_input_mux alc262_fujitsu_capture_source = {
9801         .num_items = 3,
9802         .items = {
9803                 { "Mic", 0x0 },
9804                 { "Int Mic", 0x1 },
9805                 { "CD", 0x4 },
9806         },
9807 };
9808
9809 static struct hda_input_mux alc262_HP_capture_source = {
9810         .num_items = 5,
9811         .items = {
9812                 { "Mic", 0x0 },
9813                 { "Front Mic", 0x1 },
9814                 { "Line", 0x2 },
9815                 { "CD", 0x4 },
9816                 { "AUX IN", 0x6 },
9817         },
9818 };
9819
9820 static struct hda_input_mux alc262_HP_D7000_capture_source = {
9821         .num_items = 4,
9822         .items = {
9823                 { "Mic", 0x0 },
9824                 { "Front Mic", 0x2 },
9825                 { "Line", 0x1 },
9826                 { "CD", 0x4 },
9827         },
9828 };
9829
9830 /* mute/unmute internal speaker according to the hp jacks and mute state */
9831 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
9832 {
9833         struct alc_spec *spec = codec->spec;
9834         unsigned int mute;
9835
9836         if (force || !spec->sense_updated) {
9837                 unsigned int present;
9838                 /* need to execute and sync at first */
9839                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
9840                 /* check laptop HP jack */
9841                 present = snd_hda_codec_read(codec, 0x14, 0,
9842                                              AC_VERB_GET_PIN_SENSE, 0);
9843                 /* need to execute and sync at first */
9844                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9845                 /* check docking HP jack */
9846                 present |= snd_hda_codec_read(codec, 0x1b, 0,
9847                                               AC_VERB_GET_PIN_SENSE, 0);
9848                 if (present & AC_PINSENSE_PRESENCE)
9849                         spec->jack_present = 1;
9850                 else
9851                         spec->jack_present = 0;
9852                 spec->sense_updated = 1;
9853         }
9854         /* unmute internal speaker only if both HPs are unplugged and
9855          * master switch is on
9856          */
9857         if (spec->jack_present)
9858                 mute = HDA_AMP_MUTE;
9859         else
9860                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
9861         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9862                                  HDA_AMP_MUTE, mute);
9863 }
9864
9865 /* unsolicited event for HP jack sensing */
9866 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
9867                                        unsigned int res)
9868 {
9869         if ((res >> 26) != ALC_HP_EVENT)
9870                 return;
9871         alc262_fujitsu_automute(codec, 1);
9872 }
9873
9874 static void alc262_fujitsu_init_hook(struct hda_codec *codec)
9875 {
9876         alc262_fujitsu_automute(codec, 1);
9877 }
9878
9879 /* bind volumes of both NID 0x0c and 0x0d */
9880 static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
9881         .ops = &snd_hda_bind_vol,
9882         .values = {
9883                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
9884                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
9885                 0
9886         },
9887 };
9888
9889 /* mute/unmute internal speaker according to the hp jack and mute state */
9890 static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
9891 {
9892         struct alc_spec *spec = codec->spec;
9893         unsigned int mute;
9894
9895         if (force || !spec->sense_updated) {
9896                 unsigned int present_int_hp;
9897                 /* need to execute and sync at first */
9898                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9899                 present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
9900                                         AC_VERB_GET_PIN_SENSE, 0);
9901                 spec->jack_present = (present_int_hp & 0x80000000) != 0;
9902                 spec->sense_updated = 1;
9903         }
9904         if (spec->jack_present) {
9905                 /* mute internal speaker */
9906                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9907                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9908                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9909                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9910         } else {
9911                 /* unmute internal speaker if necessary */
9912                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
9913                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9914                                          HDA_AMP_MUTE, mute);
9915                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9916                                          HDA_AMP_MUTE, mute);
9917         }
9918 }
9919
9920 /* unsolicited event for HP jack sensing */
9921 static void alc262_lenovo_3000_unsol_event(struct hda_codec *codec,
9922                                        unsigned int res)
9923 {
9924         if ((res >> 26) != ALC_HP_EVENT)
9925                 return;
9926         alc262_lenovo_3000_automute(codec, 1);
9927 }
9928
9929 /* bind hp and internal speaker mute (with plug check) */
9930 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
9931                                          struct snd_ctl_elem_value *ucontrol)
9932 {
9933         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9934         long *valp = ucontrol->value.integer.value;
9935         int change;
9936
9937         change = snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9938                                                  HDA_AMP_MUTE,
9939                                                  valp ? 0 : HDA_AMP_MUTE);
9940         change |= snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
9941                                                  HDA_AMP_MUTE,
9942                                                  valp ? 0 : HDA_AMP_MUTE);
9943
9944         if (change)
9945                 alc262_fujitsu_automute(codec, 0);
9946         return change;
9947 }
9948
9949 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
9950         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9951         {
9952                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9953                 .name = "Master Playback Switch",
9954                 .info = snd_hda_mixer_amp_switch_info,
9955                 .get = snd_hda_mixer_amp_switch_get,
9956                 .put = alc262_fujitsu_master_sw_put,
9957                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
9958         },
9959         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9960         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9961         HDA_CODEC_VOLUME("PC Speaker Volume", 0x0b, 0x05, HDA_INPUT),
9962         HDA_CODEC_MUTE("PC Speaker Switch", 0x0b, 0x05, HDA_INPUT),
9963         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9964         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9965         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9966         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
9967         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9968         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9969         { } /* end */
9970 };
9971
9972 /* bind hp and internal speaker mute (with plug check) */
9973 static int alc262_lenovo_3000_master_sw_put(struct snd_kcontrol *kcontrol,
9974                                          struct snd_ctl_elem_value *ucontrol)
9975 {
9976         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9977         long *valp = ucontrol->value.integer.value;
9978         int change;
9979
9980         change = snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
9981                                                  HDA_AMP_MUTE,
9982                                                  valp ? 0 : HDA_AMP_MUTE);
9983
9984         if (change)
9985                 alc262_lenovo_3000_automute(codec, 0);
9986         return change;
9987 }
9988
9989 static struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
9990         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9991         {
9992                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9993                 .name = "Master Playback Switch",
9994                 .info = snd_hda_mixer_amp_switch_info,
9995                 .get = snd_hda_mixer_amp_switch_get,
9996                 .put = alc262_lenovo_3000_master_sw_put,
9997                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
9998         },
9999         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10000         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10001         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10002         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10003         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10004         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
10005         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10006         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10007         { } /* end */
10008 };
10009
10010 static struct snd_kcontrol_new alc262_toshiba_rx1_mixer[] = {
10011         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
10012         {
10013                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10014                 .name = "Master Playback Switch",
10015                 .info = snd_hda_mixer_amp_switch_info,
10016                 .get = snd_hda_mixer_amp_switch_get,
10017                 .put = alc262_sony_master_sw_put,
10018                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
10019         },
10020         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10021         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10022         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10023         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10024         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10025         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10026         { } /* end */
10027 };
10028
10029 /* additional init verbs for Benq laptops */
10030 static struct hda_verb alc262_EAPD_verbs[] = {
10031         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
10032         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
10033         {}
10034 };
10035
10036 static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
10037         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10038         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10039
10040         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
10041         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
10042         {}
10043 };
10044
10045 /* Samsung Q1 Ultra Vista model setup */
10046 static struct snd_kcontrol_new alc262_ultra_mixer[] = {
10047         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10048         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
10049         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10050         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10051         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
10052         HDA_CODEC_VOLUME("Headphone Mic Boost", 0x15, 0, HDA_INPUT),
10053         { } /* end */
10054 };
10055
10056 static struct hda_verb alc262_ultra_verbs[] = {
10057         /* output mixer */
10058         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10059         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10060         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10061         /* speaker */
10062         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10063         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10064         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10065         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
10066         /* HP */
10067         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10068         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10069         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10070         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10071         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10072         /* internal mic */
10073         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10074         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10075         /* ADC, choose mic */
10076         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10077         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10078         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10079         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10080         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10081         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10082         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10083         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10084         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
10085         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(8)},
10086         {}
10087 };
10088
10089 /* mute/unmute internal speaker according to the hp jack and mute state */
10090 static void alc262_ultra_automute(struct hda_codec *codec)
10091 {
10092         struct alc_spec *spec = codec->spec;
10093         unsigned int mute;
10094
10095         mute = 0;
10096         /* auto-mute only when HP is used as HP */
10097         if (!spec->cur_mux[0]) {
10098                 unsigned int present;
10099                 /* need to execute and sync at first */
10100                 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
10101                 present = snd_hda_codec_read(codec, 0x15, 0,
10102                                              AC_VERB_GET_PIN_SENSE, 0);
10103                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
10104                 if (spec->jack_present)
10105                         mute = HDA_AMP_MUTE;
10106         }
10107         /* mute/unmute internal speaker */
10108         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10109                                  HDA_AMP_MUTE, mute);
10110         /* mute/unmute HP */
10111         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10112                                  HDA_AMP_MUTE, mute ? 0 : HDA_AMP_MUTE);
10113 }
10114
10115 /* unsolicited event for HP jack sensing */
10116 static void alc262_ultra_unsol_event(struct hda_codec *codec,
10117                                        unsigned int res)
10118 {
10119         if ((res >> 26) != ALC880_HP_EVENT)
10120                 return;
10121         alc262_ultra_automute(codec);
10122 }
10123
10124 static struct hda_input_mux alc262_ultra_capture_source = {
10125         .num_items = 2,
10126         .items = {
10127                 { "Mic", 0x1 },
10128                 { "Headphone", 0x7 },
10129         },
10130 };
10131
10132 static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
10133                                      struct snd_ctl_elem_value *ucontrol)
10134 {
10135         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10136         struct alc_spec *spec = codec->spec;
10137         int ret;
10138
10139         ret = alc_mux_enum_put(kcontrol, ucontrol);
10140         if (!ret)
10141                 return 0;
10142         /* reprogram the HP pin as mic or HP according to the input source */
10143         snd_hda_codec_write_cache(codec, 0x15, 0,
10144                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
10145                                   spec->cur_mux[0] ? PIN_VREF80 : PIN_HP);
10146         alc262_ultra_automute(codec); /* mute/unmute HP */
10147         return ret;
10148 }
10149
10150 static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
10151         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
10152         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
10153         {
10154                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10155                 .name = "Capture Source",
10156                 .info = alc_mux_enum_info,
10157                 .get = alc_mux_enum_get,
10158                 .put = alc262_ultra_mux_enum_put,
10159         },
10160         { } /* end */
10161 };
10162
10163 /* add playback controls from the parsed DAC table */
10164 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
10165                                              const struct auto_pin_cfg *cfg)
10166 {
10167         hda_nid_t nid;
10168         int err;
10169
10170         spec->multiout.num_dacs = 1;    /* only use one dac */
10171         spec->multiout.dac_nids = spec->private_dac_nids;
10172         spec->multiout.dac_nids[0] = 2;
10173
10174         nid = cfg->line_out_pins[0];
10175         if (nid) {
10176                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
10177                                   "Front Playback Volume",
10178                                   HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT));
10179                 if (err < 0)
10180                         return err;
10181                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10182                                   "Front Playback Switch",
10183                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
10184                 if (err < 0)
10185                         return err;
10186         }
10187
10188         nid = cfg->speaker_pins[0];
10189         if (nid) {
10190                 if (nid == 0x16) {
10191                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10192                                           "Speaker Playback Volume",
10193                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
10194                                                               HDA_OUTPUT));
10195                         if (err < 0)
10196                                 return err;
10197                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10198                                           "Speaker Playback Switch",
10199                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10200                                                               HDA_OUTPUT));
10201                         if (err < 0)
10202                                 return err;
10203                 } else {
10204                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10205                                           "Speaker Playback Switch",
10206                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10207                                                               HDA_OUTPUT));
10208                         if (err < 0)
10209                                 return err;
10210                 }
10211         }
10212         nid = cfg->hp_pins[0];
10213         if (nid) {
10214                 /* spec->multiout.hp_nid = 2; */
10215                 if (nid == 0x16) {
10216                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10217                                           "Headphone Playback Volume",
10218                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
10219                                                               HDA_OUTPUT));
10220                         if (err < 0)
10221                                 return err;
10222                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10223                                           "Headphone Playback Switch",
10224                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10225                                                               HDA_OUTPUT));
10226                         if (err < 0)
10227                                 return err;
10228                 } else {
10229                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10230                                           "Headphone Playback Switch",
10231                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10232                                                               HDA_OUTPUT));
10233                         if (err < 0)
10234                                 return err;
10235                 }
10236         }
10237         return 0;
10238 }
10239
10240 /* identical with ALC880 */
10241 #define alc262_auto_create_analog_input_ctls \
10242         alc880_auto_create_analog_input_ctls
10243
10244 /*
10245  * generic initialization of ADC, input mixers and output mixers
10246  */
10247 static struct hda_verb alc262_volume_init_verbs[] = {
10248         /*
10249          * Unmute ADC0-2 and set the default input to mic-in
10250          */
10251         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10252         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10253         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10254         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10255         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10256         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10257
10258         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10259          * mixer widget
10260          * Note: PASD motherboards uses the Line In 2 as the input for
10261          * front panel mic (mic 2)
10262          */
10263         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10264         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10265         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10266         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10267         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10268         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10269
10270         /*
10271          * Set up output mixers (0x0c - 0x0f)
10272          */
10273         /* set vol=0 to output mixers */
10274         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10275         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10276         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10277
10278         /* set up input amps for analog loopback */
10279         /* Amp Indices: DAC = 0, mixer = 1 */
10280         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10281         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10282         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10283         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10284         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10285         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10286
10287         /* FIXME: use matrix-type input source selection */
10288         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10289         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10290         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10291         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10292         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10293         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10294         /* Input mixer2 */
10295         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10296         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10297         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10298         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10299         /* Input mixer3 */
10300         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10301         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10302         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10303         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10304
10305         { }
10306 };
10307
10308 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
10309         /*
10310          * Unmute ADC0-2 and set the default input to mic-in
10311          */
10312         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10313         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10314         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10315         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10316         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10317         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10318
10319         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10320          * mixer widget
10321          * Note: PASD motherboards uses the Line In 2 as the input for
10322          * front panel mic (mic 2)
10323          */
10324         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10325         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10326         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10327         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10328         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10329         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10330         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10331         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10332
10333         /*
10334          * Set up output mixers (0x0c - 0x0e)
10335          */
10336         /* set vol=0 to output mixers */
10337         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10338         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10339         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10340
10341         /* set up input amps for analog loopback */
10342         /* Amp Indices: DAC = 0, mixer = 1 */
10343         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10344         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10345         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10346         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10347         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10348         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10349
10350         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10351         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10352         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10353
10354         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10355         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10356
10357         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10358         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10359
10360         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10361         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10362         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10363         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10364         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10365
10366         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10367         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10368         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10369         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10370         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10371         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10372
10373
10374         /* FIXME: use matrix-type input source selection */
10375         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10376         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10377         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10378         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10379         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10380         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10381         /* Input mixer2 */
10382         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10383         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10384         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10385         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10386         /* Input mixer3 */
10387         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10388         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10389         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10390         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10391
10392         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10393
10394         { }
10395 };
10396
10397 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
10398         /*
10399          * Unmute ADC0-2 and set the default input to mic-in
10400          */
10401         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10402         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10403         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10404         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10405         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10406         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10407
10408         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10409          * mixer widget
10410          * Note: PASD motherboards uses the Line In 2 as the input for front
10411          * panel mic (mic 2)
10412          */
10413         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10414         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10415         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10416         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10417         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10418         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10419         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10420         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10421         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
10422         /*
10423          * Set up output mixers (0x0c - 0x0e)
10424          */
10425         /* set vol=0 to output mixers */
10426         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10427         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10428         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10429
10430         /* set up input amps for analog loopback */
10431         /* Amp Indices: DAC = 0, mixer = 1 */
10432         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10433         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10434         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10435         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10436         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10437         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10438
10439
10440         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
10441         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
10442         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
10443         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
10444         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
10445         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
10446         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
10447
10448         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10449         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10450
10451         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10452         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
10453
10454         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
10455         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10456         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10457         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10458         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10459         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10460
10461         /* FIXME: use matrix-type input source selection */
10462         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10463         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10464         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
10465         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
10466         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
10467         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
10468         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
10469         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
10470         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
10471         /* Input mixer2 */
10472         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10473         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10474         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10475         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10476         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10477         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
10478         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
10479         /* Input mixer3 */
10480         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10481         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10482         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10483         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10484         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10485         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
10486         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
10487
10488         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10489
10490         { }
10491 };
10492
10493 static struct hda_verb alc262_toshiba_rx1_unsol_verbs[] = {
10494
10495         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Front Speaker */
10496         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10497         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
10498
10499         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* MIC jack */
10500         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
10501         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
10502         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
10503
10504         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP  jack */
10505         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10506         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10507         {}
10508 };
10509
10510
10511 #ifdef CONFIG_SND_HDA_POWER_SAVE
10512 #define alc262_loopbacks        alc880_loopbacks
10513 #endif
10514
10515 /* pcm configuration: identiacal with ALC880 */
10516 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
10517 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
10518 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
10519 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
10520
10521 /*
10522  * BIOS auto configuration
10523  */
10524 static int alc262_parse_auto_config(struct hda_codec *codec)
10525 {
10526         struct alc_spec *spec = codec->spec;
10527         int err;
10528         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
10529
10530         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
10531                                            alc262_ignore);
10532         if (err < 0)
10533                 return err;
10534         if (!spec->autocfg.line_outs) {
10535                 if (spec->autocfg.dig_out_pin || spec->autocfg.dig_in_pin) {
10536                         spec->multiout.max_channels = 2;
10537                         spec->no_analog = 1;
10538                         goto dig_only;
10539                 }
10540                 return 0; /* can't find valid BIOS pin config */
10541         }
10542         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
10543         if (err < 0)
10544                 return err;
10545         err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg);
10546         if (err < 0)
10547                 return err;
10548
10549         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
10550
10551  dig_only:
10552         if (spec->autocfg.dig_out_pin) {
10553                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
10554                 spec->dig_out_type = spec->autocfg.dig_out_type;
10555         }
10556         if (spec->autocfg.dig_in_pin)
10557                 spec->dig_in_nid = ALC262_DIGIN_NID;
10558
10559         if (spec->kctls.list)
10560                 add_mixer(spec, spec->kctls.list);
10561
10562         add_verb(spec, alc262_volume_init_verbs);
10563         spec->num_mux_defs = 1;
10564         spec->input_mux = &spec->private_imux[0];
10565
10566         err = alc_auto_add_mic_boost(codec);
10567         if (err < 0)
10568                 return err;
10569
10570         store_pin_configs(codec);
10571         return 1;
10572 }
10573
10574 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
10575 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
10576 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
10577 #define alc262_auto_init_input_src      alc882_auto_init_input_src
10578
10579
10580 /* init callback for auto-configuration model -- overriding the default init */
10581 static void alc262_auto_init(struct hda_codec *codec)
10582 {
10583         struct alc_spec *spec = codec->spec;
10584         alc262_auto_init_multi_out(codec);
10585         alc262_auto_init_hp_out(codec);
10586         alc262_auto_init_analog_input(codec);
10587         alc262_auto_init_input_src(codec);
10588         if (spec->unsol_event)
10589                 alc_inithook(codec);
10590 }
10591
10592 /*
10593  * configuration and preset
10594  */
10595 static const char *alc262_models[ALC262_MODEL_LAST] = {
10596         [ALC262_BASIC]          = "basic",
10597         [ALC262_HIPPO]          = "hippo",
10598         [ALC262_HIPPO_1]        = "hippo_1",
10599         [ALC262_FUJITSU]        = "fujitsu",
10600         [ALC262_HP_BPC]         = "hp-bpc",
10601         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
10602         [ALC262_HP_TC_T5735]    = "hp-tc-t5735",
10603         [ALC262_HP_RP5700]      = "hp-rp5700",
10604         [ALC262_BENQ_ED8]       = "benq",
10605         [ALC262_BENQ_T31]       = "benq-t31",
10606         [ALC262_SONY_ASSAMD]    = "sony-assamd",
10607         [ALC262_TOSHIBA_S06]    = "toshiba-s06",
10608         [ALC262_TOSHIBA_RX1]    = "toshiba-rx1",
10609         [ALC262_ULTRA]          = "ultra",
10610         [ALC262_LENOVO_3000]    = "lenovo-3000",
10611         [ALC262_NEC]            = "nec",
10612         [ALC262_AUTO]           = "auto",
10613 };
10614
10615 static struct snd_pci_quirk alc262_cfg_tbl[] = {
10616         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
10617         SND_PCI_QUIRK(0x1033, 0x8895, "NEC Versa S9100", ALC262_NEC),
10618         SND_PCI_QUIRK(0x103c, 0x12fe, "HP xw9400", ALC262_HP_BPC),
10619         SND_PCI_QUIRK(0x103c, 0x12ff, "HP xw4550", ALC262_HP_BPC),
10620         SND_PCI_QUIRK(0x103c, 0x1306, "HP xw8600", ALC262_HP_BPC),
10621         SND_PCI_QUIRK(0x103c, 0x1307, "HP xw6600", ALC262_HP_BPC),
10622         SND_PCI_QUIRK(0x103c, 0x1308, "HP xw4600", ALC262_HP_BPC),
10623         SND_PCI_QUIRK(0x103c, 0x1309, "HP xw4*00", ALC262_HP_BPC),
10624         SND_PCI_QUIRK(0x103c, 0x130a, "HP xw6*00", ALC262_HP_BPC),
10625         SND_PCI_QUIRK(0x103c, 0x130b, "HP xw8*00", ALC262_HP_BPC),
10626         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
10627         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
10628         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
10629         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
10630         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
10631         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
10632         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
10633         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
10634         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
10635         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
10636         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
10637         SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
10638                       ALC262_HP_TC_T5735),
10639         SND_PCI_QUIRK(0x103c, 0x2817, "HP RP5700", ALC262_HP_RP5700),
10640         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10641         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
10642         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10643         SND_PCI_QUIRK(0x104d, 0x900e, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10644         SND_PCI_QUIRK(0x104d, 0x9015, "Sony 0x9015", ALC262_SONY_ASSAMD),
10645         SND_PCI_QUIRK(0x104d, 0x9033, "Sony VAIO VGN-SR19XN",
10646                       ALC262_SONY_ASSAMD),
10647         SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
10648                       ALC262_TOSHIBA_RX1),
10649         SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06),
10650         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
10651         SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
10652         SND_PCI_QUIRK(0x144d, 0xc032, "Samsung Q1 Ultra", ALC262_ULTRA),
10653         SND_PCI_QUIRK(0x144d, 0xc039, "Samsung Q1U EL", ALC262_ULTRA),
10654         SND_PCI_QUIRK(0x144d, 0xc510, "Samsung Q45", ALC262_HIPPO),
10655         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
10656         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
10657         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
10658         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
10659         {}
10660 };
10661
10662 static struct alc_config_preset alc262_presets[] = {
10663         [ALC262_BASIC] = {
10664                 .mixers = { alc262_base_mixer },
10665                 .init_verbs = { alc262_init_verbs },
10666                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10667                 .dac_nids = alc262_dac_nids,
10668                 .hp_nid = 0x03,
10669                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10670                 .channel_mode = alc262_modes,
10671                 .input_mux = &alc262_capture_source,
10672         },
10673         [ALC262_HIPPO] = {
10674                 .mixers = { alc262_base_mixer },
10675                 .init_verbs = { alc262_init_verbs, alc262_hippo_unsol_verbs},
10676                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10677                 .dac_nids = alc262_dac_nids,
10678                 .hp_nid = 0x03,
10679                 .dig_out_nid = ALC262_DIGOUT_NID,
10680                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10681                 .channel_mode = alc262_modes,
10682                 .input_mux = &alc262_capture_source,
10683                 .unsol_event = alc262_hippo_unsol_event,
10684                 .init_hook = alc262_hippo_automute,
10685         },
10686         [ALC262_HIPPO_1] = {
10687                 .mixers = { alc262_hippo1_mixer },
10688                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
10689                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10690                 .dac_nids = alc262_dac_nids,
10691                 .hp_nid = 0x02,
10692                 .dig_out_nid = ALC262_DIGOUT_NID,
10693                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10694                 .channel_mode = alc262_modes,
10695                 .input_mux = &alc262_capture_source,
10696                 .unsol_event = alc262_hippo1_unsol_event,
10697                 .init_hook = alc262_hippo1_automute,
10698         },
10699         [ALC262_FUJITSU] = {
10700                 .mixers = { alc262_fujitsu_mixer },
10701                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
10702                                 alc262_fujitsu_unsol_verbs },
10703                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10704                 .dac_nids = alc262_dac_nids,
10705                 .hp_nid = 0x03,
10706                 .dig_out_nid = ALC262_DIGOUT_NID,
10707                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10708                 .channel_mode = alc262_modes,
10709                 .input_mux = &alc262_fujitsu_capture_source,
10710                 .unsol_event = alc262_fujitsu_unsol_event,
10711                 .init_hook = alc262_fujitsu_init_hook,
10712         },
10713         [ALC262_HP_BPC] = {
10714                 .mixers = { alc262_HP_BPC_mixer },
10715                 .init_verbs = { alc262_HP_BPC_init_verbs },
10716                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10717                 .dac_nids = alc262_dac_nids,
10718                 .hp_nid = 0x03,
10719                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10720                 .channel_mode = alc262_modes,
10721                 .input_mux = &alc262_HP_capture_source,
10722                 .unsol_event = alc262_hp_bpc_unsol_event,
10723                 .init_hook = alc262_hp_bpc_automute,
10724         },
10725         [ALC262_HP_BPC_D7000_WF] = {
10726                 .mixers = { alc262_HP_BPC_WildWest_mixer },
10727                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
10728                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10729                 .dac_nids = alc262_dac_nids,
10730                 .hp_nid = 0x03,
10731                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10732                 .channel_mode = alc262_modes,
10733                 .input_mux = &alc262_HP_D7000_capture_source,
10734                 .unsol_event = alc262_hp_wildwest_unsol_event,
10735                 .init_hook = alc262_hp_wildwest_automute,
10736         },
10737         [ALC262_HP_BPC_D7000_WL] = {
10738                 .mixers = { alc262_HP_BPC_WildWest_mixer,
10739                             alc262_HP_BPC_WildWest_option_mixer },
10740                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
10741                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10742                 .dac_nids = alc262_dac_nids,
10743                 .hp_nid = 0x03,
10744                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10745                 .channel_mode = alc262_modes,
10746                 .input_mux = &alc262_HP_D7000_capture_source,
10747                 .unsol_event = alc262_hp_wildwest_unsol_event,
10748                 .init_hook = alc262_hp_wildwest_automute,
10749         },
10750         [ALC262_HP_TC_T5735] = {
10751                 .mixers = { alc262_hp_t5735_mixer },
10752                 .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
10753                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10754                 .dac_nids = alc262_dac_nids,
10755                 .hp_nid = 0x03,
10756                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10757                 .channel_mode = alc262_modes,
10758                 .input_mux = &alc262_capture_source,
10759                 .unsol_event = alc262_hp_t5735_unsol_event,
10760                 .init_hook = alc262_hp_t5735_init_hook,
10761         },
10762         [ALC262_HP_RP5700] = {
10763                 .mixers = { alc262_hp_rp5700_mixer },
10764                 .init_verbs = { alc262_init_verbs, alc262_hp_rp5700_verbs },
10765                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10766                 .dac_nids = alc262_dac_nids,
10767                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10768                 .channel_mode = alc262_modes,
10769                 .input_mux = &alc262_hp_rp5700_capture_source,
10770         },
10771         [ALC262_BENQ_ED8] = {
10772                 .mixers = { alc262_base_mixer },
10773                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
10774                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10775                 .dac_nids = alc262_dac_nids,
10776                 .hp_nid = 0x03,
10777                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10778                 .channel_mode = alc262_modes,
10779                 .input_mux = &alc262_capture_source,
10780         },
10781         [ALC262_SONY_ASSAMD] = {
10782                 .mixers = { alc262_sony_mixer },
10783                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
10784                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10785                 .dac_nids = alc262_dac_nids,
10786                 .hp_nid = 0x02,
10787                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10788                 .channel_mode = alc262_modes,
10789                 .input_mux = &alc262_capture_source,
10790                 .unsol_event = alc262_hippo_unsol_event,
10791                 .init_hook = alc262_hippo_automute,
10792         },
10793         [ALC262_BENQ_T31] = {
10794                 .mixers = { alc262_benq_t31_mixer },
10795                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs, alc262_hippo_unsol_verbs },
10796                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10797                 .dac_nids = alc262_dac_nids,
10798                 .hp_nid = 0x03,
10799                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10800                 .channel_mode = alc262_modes,
10801                 .input_mux = &alc262_capture_source,
10802                 .unsol_event = alc262_hippo_unsol_event,
10803                 .init_hook = alc262_hippo_automute,
10804         },
10805         [ALC262_ULTRA] = {
10806                 .mixers = { alc262_ultra_mixer },
10807                 .cap_mixer = alc262_ultra_capture_mixer,
10808                 .init_verbs = { alc262_ultra_verbs },
10809                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10810                 .dac_nids = alc262_dac_nids,
10811                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10812                 .channel_mode = alc262_modes,
10813                 .input_mux = &alc262_ultra_capture_source,
10814                 .adc_nids = alc262_adc_nids, /* ADC0 */
10815                 .capsrc_nids = alc262_capsrc_nids,
10816                 .num_adc_nids = 1, /* single ADC */
10817                 .unsol_event = alc262_ultra_unsol_event,
10818                 .init_hook = alc262_ultra_automute,
10819         },
10820         [ALC262_LENOVO_3000] = {
10821                 .mixers = { alc262_lenovo_3000_mixer },
10822                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
10823                                 alc262_lenovo_3000_unsol_verbs },
10824                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10825                 .dac_nids = alc262_dac_nids,
10826                 .hp_nid = 0x03,
10827                 .dig_out_nid = ALC262_DIGOUT_NID,
10828                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10829                 .channel_mode = alc262_modes,
10830                 .input_mux = &alc262_fujitsu_capture_source,
10831                 .unsol_event = alc262_lenovo_3000_unsol_event,
10832         },
10833         [ALC262_NEC] = {
10834                 .mixers = { alc262_nec_mixer },
10835                 .init_verbs = { alc262_nec_verbs },
10836                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10837                 .dac_nids = alc262_dac_nids,
10838                 .hp_nid = 0x03,
10839                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10840                 .channel_mode = alc262_modes,
10841                 .input_mux = &alc262_capture_source,
10842         },
10843         [ALC262_TOSHIBA_S06] = {
10844                 .mixers = { alc262_toshiba_s06_mixer },
10845                 .init_verbs = { alc262_init_verbs, alc262_toshiba_s06_verbs,
10846                                                         alc262_eapd_verbs },
10847                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10848                 .capsrc_nids = alc262_dmic_capsrc_nids,
10849                 .dac_nids = alc262_dac_nids,
10850                 .adc_nids = alc262_dmic_adc_nids, /* ADC0 */
10851                 .dig_out_nid = ALC262_DIGOUT_NID,
10852                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10853                 .channel_mode = alc262_modes,
10854                 .input_mux = &alc262_dmic_capture_source,
10855                 .unsol_event = alc262_toshiba_s06_unsol_event,
10856                 .init_hook = alc262_toshiba_s06_init_hook,
10857         },
10858         [ALC262_TOSHIBA_RX1] = {
10859                 .mixers = { alc262_toshiba_rx1_mixer },
10860                 .init_verbs = { alc262_init_verbs, alc262_toshiba_rx1_unsol_verbs },
10861                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10862                 .dac_nids = alc262_dac_nids,
10863                 .hp_nid = 0x03,
10864                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10865                 .channel_mode = alc262_modes,
10866                 .input_mux = &alc262_capture_source,
10867                 .unsol_event = alc262_hippo_unsol_event,
10868                 .init_hook = alc262_hippo_automute,
10869         },
10870 };
10871
10872 static int patch_alc262(struct hda_codec *codec)
10873 {
10874         struct alc_spec *spec;
10875         int board_config;
10876         int err;
10877
10878         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
10879         if (spec == NULL)
10880                 return -ENOMEM;
10881
10882         codec->spec = spec;
10883 #if 0
10884         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
10885          * under-run
10886          */
10887         {
10888         int tmp;
10889         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
10890         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
10891         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
10892         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
10893         }
10894 #endif
10895
10896         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
10897
10898         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
10899                                                   alc262_models,
10900                                                   alc262_cfg_tbl);
10901
10902         if (board_config < 0) {
10903                 printk(KERN_INFO "hda_codec: Unknown model for ALC262, "
10904                        "trying auto-probe from BIOS...\n");
10905                 board_config = ALC262_AUTO;
10906         }
10907
10908         if (board_config == ALC262_AUTO) {
10909                 /* automatic parse from the BIOS config */
10910                 err = alc262_parse_auto_config(codec);
10911                 if (err < 0) {
10912                         alc_free(codec);
10913                         return err;
10914                 } else if (!err) {
10915                         printk(KERN_INFO
10916                                "hda_codec: Cannot set up configuration "
10917                                "from BIOS.  Using base mode...\n");
10918                         board_config = ALC262_BASIC;
10919                 }
10920         }
10921
10922         if (board_config != ALC262_AUTO)
10923                 setup_preset(spec, &alc262_presets[board_config]);
10924
10925         spec->stream_name_analog = "ALC262 Analog";
10926         spec->stream_analog_playback = &alc262_pcm_analog_playback;
10927         spec->stream_analog_capture = &alc262_pcm_analog_capture;
10928
10929         spec->stream_name_digital = "ALC262 Digital";
10930         spec->stream_digital_playback = &alc262_pcm_digital_playback;
10931         spec->stream_digital_capture = &alc262_pcm_digital_capture;
10932
10933         spec->capture_style = CAPT_MIX;
10934         if (!spec->adc_nids && spec->input_mux) {
10935                 /* check whether NID 0x07 is valid */
10936                 unsigned int wcap = get_wcaps(codec, 0x07);
10937
10938                 /* get type */
10939                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
10940                 if (wcap != AC_WID_AUD_IN) {
10941                         spec->adc_nids = alc262_adc_nids_alt;
10942                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
10943                         spec->capsrc_nids = alc262_capsrc_nids_alt;
10944                 } else {
10945                         spec->adc_nids = alc262_adc_nids;
10946                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
10947                         spec->capsrc_nids = alc262_capsrc_nids;
10948                 }
10949         }
10950         if (!spec->cap_mixer && !spec->no_analog)
10951                 set_capture_mixer(spec);
10952
10953         spec->vmaster_nid = 0x0c;
10954
10955         codec->patch_ops = alc_patch_ops;
10956         if (board_config == ALC262_AUTO)
10957                 spec->init_hook = alc262_auto_init;
10958 #ifdef CONFIG_SND_HDA_POWER_SAVE
10959         if (!spec->loopback.amplist)
10960                 spec->loopback.amplist = alc262_loopbacks;
10961 #endif
10962         codec->proc_widget_hook = print_realtek_coef;
10963
10964         return 0;
10965 }
10966
10967 /*
10968  *  ALC268 channel source setting (2 channel)
10969  */
10970 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
10971 #define alc268_modes            alc260_modes
10972
10973 static hda_nid_t alc268_dac_nids[2] = {
10974         /* front, hp */
10975         0x02, 0x03
10976 };
10977
10978 static hda_nid_t alc268_adc_nids[2] = {
10979         /* ADC0-1 */
10980         0x08, 0x07
10981 };
10982
10983 static hda_nid_t alc268_adc_nids_alt[1] = {
10984         /* ADC0 */
10985         0x08
10986 };
10987
10988 static hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
10989
10990 static struct snd_kcontrol_new alc268_base_mixer[] = {
10991         /* output mixer control */
10992         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
10993         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10994         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
10995         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10996         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10997         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10998         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
10999         { }
11000 };
11001
11002 /* bind Beep switches of both NID 0x0f and 0x10 */
11003 static struct hda_bind_ctls alc268_bind_beep_sw = {
11004         .ops = &snd_hda_bind_sw,
11005         .values = {
11006                 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
11007                 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
11008                 0
11009         },
11010 };
11011
11012 static struct snd_kcontrol_new alc268_beep_mixer[] = {
11013         HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
11014         HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
11015         { }
11016 };
11017
11018 static struct hda_verb alc268_eapd_verbs[] = {
11019         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
11020         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
11021         { }
11022 };
11023
11024 /* Toshiba specific */
11025 #define alc268_toshiba_automute alc262_hippo_automute
11026
11027 static struct hda_verb alc268_toshiba_verbs[] = {
11028         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11029         { } /* end */
11030 };
11031
11032 static struct hda_input_mux alc268_acer_lc_capture_source = {
11033         .num_items = 2,
11034         .items = {
11035                 { "i-Mic", 0x6 },
11036                 { "E-Mic", 0x0 },
11037         },
11038 };
11039
11040 /* Acer specific */
11041 /* bind volumes of both NID 0x02 and 0x03 */
11042 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
11043         .ops = &snd_hda_bind_vol,
11044         .values = {
11045                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
11046                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
11047                 0
11048         },
11049 };
11050
11051 /* mute/unmute internal speaker according to the hp jack and mute state */
11052 static void alc268_acer_automute(struct hda_codec *codec, int force)
11053 {
11054         struct alc_spec *spec = codec->spec;
11055         unsigned int mute;
11056
11057         if (force || !spec->sense_updated) {
11058                 unsigned int present;
11059                 present = snd_hda_codec_read(codec, 0x14, 0,
11060                                          AC_VERB_GET_PIN_SENSE, 0);
11061                 spec->jack_present = (present & 0x80000000) != 0;
11062                 spec->sense_updated = 1;
11063         }
11064         if (spec->jack_present)
11065                 mute = HDA_AMP_MUTE; /* mute internal speaker */
11066         else /* unmute internal speaker if necessary */
11067                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
11068         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
11069                                  HDA_AMP_MUTE, mute);
11070 }
11071
11072
11073 /* bind hp and internal speaker mute (with plug check) */
11074 static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
11075                                      struct snd_ctl_elem_value *ucontrol)
11076 {
11077         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
11078         long *valp = ucontrol->value.integer.value;
11079         int change;
11080
11081         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
11082                                           HDA_AMP_MUTE,
11083                                           valp[0] ? 0 : HDA_AMP_MUTE);
11084         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
11085                                            HDA_AMP_MUTE,
11086                                            valp[1] ? 0 : HDA_AMP_MUTE);
11087         if (change)
11088                 alc268_acer_automute(codec, 0);
11089         return change;
11090 }
11091
11092 static struct snd_kcontrol_new alc268_acer_aspire_one_mixer[] = {
11093         /* output mixer control */
11094         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11095         {
11096                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11097                 .name = "Master Playback Switch",
11098                 .info = snd_hda_mixer_amp_switch_info,
11099                 .get = snd_hda_mixer_amp_switch_get,
11100                 .put = alc268_acer_master_sw_put,
11101                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11102         },
11103         HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x18, 0, HDA_INPUT),
11104         { }
11105 };
11106
11107 static struct snd_kcontrol_new alc268_acer_mixer[] = {
11108         /* output mixer control */
11109         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11110         {
11111                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11112                 .name = "Master Playback Switch",
11113                 .info = snd_hda_mixer_amp_switch_info,
11114                 .get = snd_hda_mixer_amp_switch_get,
11115                 .put = alc268_acer_master_sw_put,
11116                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11117         },
11118         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11119         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11120         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11121         { }
11122 };
11123
11124 static struct snd_kcontrol_new alc268_acer_dmic_mixer[] = {
11125         /* output mixer control */
11126         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11127         {
11128                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11129                 .name = "Master Playback Switch",
11130                 .info = snd_hda_mixer_amp_switch_info,
11131                 .get = snd_hda_mixer_amp_switch_get,
11132                 .put = alc268_acer_master_sw_put,
11133                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11134         },
11135         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11136         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11137         { }
11138 };
11139
11140 static struct hda_verb alc268_acer_aspire_one_verbs[] = {
11141         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11142         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11143         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11144         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11145         {0x23, AC_VERB_SET_CONNECT_SEL, 0x06},
11146         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, 0xa017},
11147         { }
11148 };
11149
11150 static struct hda_verb alc268_acer_verbs[] = {
11151         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
11152         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11153         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11154         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11155         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11156         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11157         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11158         { }
11159 };
11160
11161 /* unsolicited event for HP jack sensing */
11162 static void alc268_toshiba_unsol_event(struct hda_codec *codec,
11163                                        unsigned int res)
11164 {
11165         if ((res >> 26) != ALC880_HP_EVENT)
11166                 return;
11167         alc268_toshiba_automute(codec);
11168 }
11169
11170 static void alc268_acer_unsol_event(struct hda_codec *codec,
11171                                        unsigned int res)
11172 {
11173         if ((res >> 26) != ALC880_HP_EVENT)
11174                 return;
11175         alc268_acer_automute(codec, 1);
11176 }
11177
11178 static void alc268_acer_init_hook(struct hda_codec *codec)
11179 {
11180         alc268_acer_automute(codec, 1);
11181 }
11182
11183 /* toggle speaker-output according to the hp-jack state */
11184 static void alc268_aspire_one_speaker_automute(struct hda_codec *codec)
11185 {
11186         unsigned int present;
11187         unsigned char bits;
11188
11189         present = snd_hda_codec_read(codec, 0x15, 0,
11190                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11191         bits = present ? AMP_IN_MUTE(0) : 0;
11192         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 0,
11193                                 AMP_IN_MUTE(0), bits);
11194         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 1,
11195                                 AMP_IN_MUTE(0), bits);
11196 }
11197
11198
11199 static void alc268_acer_mic_automute(struct hda_codec *codec)
11200 {
11201         unsigned int present;
11202
11203         present = snd_hda_codec_read(codec, 0x18, 0,
11204                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11205         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_CONNECT_SEL,
11206                             present ? 0x0 : 0x6);
11207 }
11208
11209 static void alc268_acer_lc_unsol_event(struct hda_codec *codec,
11210                                     unsigned int res)
11211 {
11212         if ((res >> 26) == ALC880_HP_EVENT)
11213                 alc268_aspire_one_speaker_automute(codec);
11214         if ((res >> 26) == ALC880_MIC_EVENT)
11215                 alc268_acer_mic_automute(codec);
11216 }
11217
11218 static void alc268_acer_lc_init_hook(struct hda_codec *codec)
11219 {
11220         alc268_aspire_one_speaker_automute(codec);
11221         alc268_acer_mic_automute(codec);
11222 }
11223
11224 static struct snd_kcontrol_new alc268_dell_mixer[] = {
11225         /* output mixer control */
11226         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11227         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11228         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11229         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11230         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11231         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11232         { }
11233 };
11234
11235 static struct hda_verb alc268_dell_verbs[] = {
11236         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11237         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11238         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11239         { }
11240 };
11241
11242 /* mute/unmute internal speaker according to the hp jack and mute state */
11243 static void alc268_dell_automute(struct hda_codec *codec)
11244 {
11245         unsigned int present;
11246         unsigned int mute;
11247
11248         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0);
11249         if (present & 0x80000000)
11250                 mute = HDA_AMP_MUTE;
11251         else
11252                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
11253         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
11254                                  HDA_AMP_MUTE, mute);
11255 }
11256
11257 static void alc268_dell_unsol_event(struct hda_codec *codec,
11258                                     unsigned int res)
11259 {
11260         if ((res >> 26) != ALC880_HP_EVENT)
11261                 return;
11262         alc268_dell_automute(codec);
11263 }
11264
11265 #define alc268_dell_init_hook   alc268_dell_automute
11266
11267 static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
11268         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
11269         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11270         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
11271         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11272         HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11273         HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
11274         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
11275         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
11276         { }
11277 };
11278
11279 static struct hda_verb alc267_quanta_il1_verbs[] = {
11280         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11281         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
11282         { }
11283 };
11284
11285 static void alc267_quanta_il1_hp_automute(struct hda_codec *codec)
11286 {
11287         unsigned int present;
11288
11289         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
11290                 & AC_PINSENSE_PRESENCE;
11291         snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
11292                             present ? 0 : PIN_OUT);
11293 }
11294
11295 static void alc267_quanta_il1_mic_automute(struct hda_codec *codec)
11296 {
11297         unsigned int present;
11298
11299         present = snd_hda_codec_read(codec, 0x18, 0,
11300                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11301         snd_hda_codec_write(codec, 0x23, 0,
11302                             AC_VERB_SET_CONNECT_SEL,
11303                             present ? 0x00 : 0x01);
11304 }
11305
11306 static void alc267_quanta_il1_automute(struct hda_codec *codec)
11307 {
11308         alc267_quanta_il1_hp_automute(codec);
11309         alc267_quanta_il1_mic_automute(codec);
11310 }
11311
11312 static void alc267_quanta_il1_unsol_event(struct hda_codec *codec,
11313                                            unsigned int res)
11314 {
11315         switch (res >> 26) {
11316         case ALC880_HP_EVENT:
11317                 alc267_quanta_il1_hp_automute(codec);
11318                 break;
11319         case ALC880_MIC_EVENT:
11320                 alc267_quanta_il1_mic_automute(codec);
11321                 break;
11322         }
11323 }
11324
11325 /*
11326  * generic initialization of ADC, input mixers and output mixers
11327  */
11328 static struct hda_verb alc268_base_init_verbs[] = {
11329         /* Unmute DAC0-1 and set vol = 0 */
11330         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11331         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11332
11333         /*
11334          * Set up output mixers (0x0c - 0x0e)
11335          */
11336         /* set vol=0 to output mixers */
11337         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11338         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
11339
11340         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11341         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11342
11343         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
11344         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
11345         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
11346         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11347         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11348         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11349         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11350         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11351
11352         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11353         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11354         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11355         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11356         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11357
11358         /* set PCBEEP vol = 0, mute connections */
11359         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11360         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11361         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11362
11363         /* Unmute Selector 23h,24h and set the default input to mic-in */
11364
11365         {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
11366         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11367         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
11368         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11369
11370         { }
11371 };
11372
11373 /*
11374  * generic initialization of ADC, input mixers and output mixers
11375  */
11376 static struct hda_verb alc268_volume_init_verbs[] = {
11377         /* set output DAC */
11378         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11379         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11380
11381         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11382         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11383         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11384         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11385         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11386
11387         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11388         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11389         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11390
11391         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11392         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11393
11394         /* set PCBEEP vol = 0, mute connections */
11395         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11396         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11397         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11398
11399         { }
11400 };
11401
11402 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
11403         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11404         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
11405         {
11406                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11407                 /* The multiple "Capture Source" controls confuse alsamixer
11408                  * So call somewhat different..
11409                  */
11410                 /* .name = "Capture Source", */
11411                 .name = "Input Source",
11412                 .count = 1,
11413                 .info = alc_mux_enum_info,
11414                 .get = alc_mux_enum_get,
11415                 .put = alc_mux_enum_put,
11416         },
11417         { } /* end */
11418 };
11419
11420 static struct snd_kcontrol_new alc268_capture_mixer[] = {
11421         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11422         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
11423         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
11424         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
11425         {
11426                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11427                 /* The multiple "Capture Source" controls confuse alsamixer
11428                  * So call somewhat different..
11429                  */
11430                 /* .name = "Capture Source", */
11431                 .name = "Input Source",
11432                 .count = 2,
11433                 .info = alc_mux_enum_info,
11434                 .get = alc_mux_enum_get,
11435                 .put = alc_mux_enum_put,
11436         },
11437         { } /* end */
11438 };
11439
11440 static struct hda_input_mux alc268_capture_source = {
11441         .num_items = 4,
11442         .items = {
11443                 { "Mic", 0x0 },
11444                 { "Front Mic", 0x1 },
11445                 { "Line", 0x2 },
11446                 { "CD", 0x3 },
11447         },
11448 };
11449
11450 static struct hda_input_mux alc268_acer_capture_source = {
11451         .num_items = 3,
11452         .items = {
11453                 { "Mic", 0x0 },
11454                 { "Internal Mic", 0x1 },
11455                 { "Line", 0x2 },
11456         },
11457 };
11458
11459 static struct hda_input_mux alc268_acer_dmic_capture_source = {
11460         .num_items = 3,
11461         .items = {
11462                 { "Mic", 0x0 },
11463                 { "Internal Mic", 0x6 },
11464                 { "Line", 0x2 },
11465         },
11466 };
11467
11468 #ifdef CONFIG_SND_DEBUG
11469 static struct snd_kcontrol_new alc268_test_mixer[] = {
11470         /* Volume widgets */
11471         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11472         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11473         HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
11474         HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
11475         HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
11476         HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
11477         HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
11478         HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
11479         HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
11480         HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
11481         HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
11482         HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
11483         HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
11484         /* The below appears problematic on some hardwares */
11485         /*HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),*/
11486         HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11487         HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
11488         HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
11489         HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),
11490
11491         /* Modes for retasking pin widgets */
11492         ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
11493         ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
11494         ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
11495         ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),
11496
11497         /* Controls for GPIO pins, assuming they are configured as outputs */
11498         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
11499         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
11500         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
11501         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
11502
11503         /* Switches to allow the digital SPDIF output pin to be enabled.
11504          * The ALC268 does not have an SPDIF input.
11505          */
11506         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),
11507
11508         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
11509          * this output to turn on an external amplifier.
11510          */
11511         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
11512         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
11513
11514         { } /* end */
11515 };
11516 #endif
11517
11518 /* create input playback/capture controls for the given pin */
11519 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
11520                                     const char *ctlname, int idx)
11521 {
11522         char name[32];
11523         int err;
11524
11525         sprintf(name, "%s Playback Volume", ctlname);
11526         if (nid == 0x14) {
11527                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11528                                   HDA_COMPOSE_AMP_VAL(0x02, 3, idx,
11529                                                       HDA_OUTPUT));
11530                 if (err < 0)
11531                         return err;
11532         } else if (nid == 0x15) {
11533                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11534                                   HDA_COMPOSE_AMP_VAL(0x03, 3, idx,
11535                                                       HDA_OUTPUT));
11536                 if (err < 0)
11537                         return err;
11538         } else
11539                 return -1;
11540         sprintf(name, "%s Playback Switch", ctlname);
11541         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
11542                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
11543         if (err < 0)
11544                 return err;
11545         return 0;
11546 }
11547
11548 /* add playback controls from the parsed DAC table */
11549 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
11550                                              const struct auto_pin_cfg *cfg)
11551 {
11552         hda_nid_t nid;
11553         int err;
11554
11555         spec->multiout.num_dacs = 2;    /* only use one dac */
11556         spec->multiout.dac_nids = spec->private_dac_nids;
11557         spec->multiout.dac_nids[0] = 2;
11558         spec->multiout.dac_nids[1] = 3;
11559
11560         nid = cfg->line_out_pins[0];
11561         if (nid)
11562                 alc268_new_analog_output(spec, nid, "Front", 0);
11563
11564         nid = cfg->speaker_pins[0];
11565         if (nid == 0x1d) {
11566                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
11567                                   "Speaker Playback Volume",
11568                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
11569                 if (err < 0)
11570                         return err;
11571         }
11572         nid = cfg->hp_pins[0];
11573         if (nid)
11574                 alc268_new_analog_output(spec, nid, "Headphone", 0);
11575
11576         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
11577         if (nid == 0x16) {
11578                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11579                                   "Mono Playback Switch",
11580                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_INPUT));
11581                 if (err < 0)
11582                         return err;
11583         }
11584         return 0;
11585 }
11586
11587 /* create playback/capture controls for input pins */
11588 static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
11589                                                 const struct auto_pin_cfg *cfg)
11590 {
11591         struct hda_input_mux *imux = &spec->private_imux[0];
11592         int i, idx1;
11593
11594         for (i = 0; i < AUTO_PIN_LAST; i++) {
11595                 switch(cfg->input_pins[i]) {
11596                 case 0x18:
11597                         idx1 = 0;       /* Mic 1 */
11598                         break;
11599                 case 0x19:
11600                         idx1 = 1;       /* Mic 2 */
11601                         break;
11602                 case 0x1a:
11603                         idx1 = 2;       /* Line In */
11604                         break;
11605                 case 0x1c:
11606                         idx1 = 3;       /* CD */
11607                         break;
11608                 case 0x12:
11609                 case 0x13:
11610                         idx1 = 6;       /* digital mics */
11611                         break;
11612                 default:
11613                         continue;
11614                 }
11615                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
11616                 imux->items[imux->num_items].index = idx1;
11617                 imux->num_items++;
11618         }
11619         return 0;
11620 }
11621
11622 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
11623 {
11624         struct alc_spec *spec = codec->spec;
11625         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
11626         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
11627         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
11628         unsigned int    dac_vol1, dac_vol2;
11629
11630         if (speaker_nid) {
11631                 snd_hda_codec_write(codec, speaker_nid, 0,
11632                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
11633                 snd_hda_codec_write(codec, 0x0f, 0,
11634                                     AC_VERB_SET_AMP_GAIN_MUTE,
11635                                     AMP_IN_UNMUTE(1));
11636                 snd_hda_codec_write(codec, 0x10, 0,
11637                                     AC_VERB_SET_AMP_GAIN_MUTE,
11638                                     AMP_IN_UNMUTE(1));
11639         } else {
11640                 snd_hda_codec_write(codec, 0x0f, 0,
11641                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
11642                 snd_hda_codec_write(codec, 0x10, 0,
11643                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
11644         }
11645
11646         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
11647         if (line_nid == 0x14)
11648                 dac_vol2 = AMP_OUT_ZERO;
11649         else if (line_nid == 0x15)
11650                 dac_vol1 = AMP_OUT_ZERO;
11651         if (hp_nid == 0x14)
11652                 dac_vol2 = AMP_OUT_ZERO;
11653         else if (hp_nid == 0x15)
11654                 dac_vol1 = AMP_OUT_ZERO;
11655         if (line_nid != 0x16 || hp_nid != 0x16 ||
11656             spec->autocfg.line_out_pins[1] != 0x16 ||
11657             spec->autocfg.line_out_pins[2] != 0x16)
11658                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
11659
11660         snd_hda_codec_write(codec, 0x02, 0,
11661                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
11662         snd_hda_codec_write(codec, 0x03, 0,
11663                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
11664 }
11665
11666 /* pcm configuration: identiacal with ALC880 */
11667 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
11668 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
11669 #define alc268_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
11670 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
11671
11672 /*
11673  * BIOS auto configuration
11674  */
11675 static int alc268_parse_auto_config(struct hda_codec *codec)
11676 {
11677         struct alc_spec *spec = codec->spec;
11678         int err;
11679         static hda_nid_t alc268_ignore[] = { 0 };
11680
11681         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11682                                            alc268_ignore);
11683         if (err < 0)
11684                 return err;
11685         if (!spec->autocfg.line_outs)
11686                 return 0; /* can't find valid BIOS pin config */
11687
11688         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
11689         if (err < 0)
11690                 return err;
11691         err = alc268_auto_create_analog_input_ctls(spec, &spec->autocfg);
11692         if (err < 0)
11693                 return err;
11694
11695         spec->multiout.max_channels = 2;
11696
11697         /* digital only support output */
11698         if (spec->autocfg.dig_out_pin)
11699                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
11700
11701         if (spec->kctls.list)
11702                 add_mixer(spec, spec->kctls.list);
11703
11704         if (spec->autocfg.speaker_pins[0] != 0x1d)
11705                 add_mixer(spec, alc268_beep_mixer);
11706
11707         add_verb(spec, alc268_volume_init_verbs);
11708         spec->num_mux_defs = 1;
11709         spec->input_mux = &spec->private_imux[0];
11710
11711         err = alc_auto_add_mic_boost(codec);
11712         if (err < 0)
11713                 return err;
11714
11715         store_pin_configs(codec);
11716         return 1;
11717 }
11718
11719 #define alc268_auto_init_multi_out      alc882_auto_init_multi_out
11720 #define alc268_auto_init_hp_out         alc882_auto_init_hp_out
11721 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
11722
11723 /* init callback for auto-configuration model -- overriding the default init */
11724 static void alc268_auto_init(struct hda_codec *codec)
11725 {
11726         struct alc_spec *spec = codec->spec;
11727         alc268_auto_init_multi_out(codec);
11728         alc268_auto_init_hp_out(codec);
11729         alc268_auto_init_mono_speaker_out(codec);
11730         alc268_auto_init_analog_input(codec);
11731         if (spec->unsol_event)
11732                 alc_inithook(codec);
11733 }
11734
11735 /*
11736  * configuration and preset
11737  */
11738 static const char *alc268_models[ALC268_MODEL_LAST] = {
11739         [ALC267_QUANTA_IL1]     = "quanta-il1",
11740         [ALC268_3ST]            = "3stack",
11741         [ALC268_TOSHIBA]        = "toshiba",
11742         [ALC268_ACER]           = "acer",
11743         [ALC268_ACER_DMIC]      = "acer-dmic",
11744         [ALC268_ACER_ASPIRE_ONE]        = "acer-aspire",
11745         [ALC268_DELL]           = "dell",
11746         [ALC268_ZEPTO]          = "zepto",
11747 #ifdef CONFIG_SND_DEBUG
11748         [ALC268_TEST]           = "test",
11749 #endif
11750         [ALC268_AUTO]           = "auto",
11751 };
11752
11753 static struct snd_pci_quirk alc268_cfg_tbl[] = {
11754         SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
11755         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
11756         SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
11757         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
11758         SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER),
11759         SND_PCI_QUIRK(0x1025, 0x015b, "Acer Aspire One",
11760                                                 ALC268_ACER_ASPIRE_ONE),
11761         SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
11762         SND_PCI_QUIRK(0x1028, 0x02b0, "Dell Inspiron Mini9", ALC268_DELL),
11763         SND_PCI_QUIRK(0x103c, 0x30cc, "TOSHIBA", ALC268_TOSHIBA),
11764         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
11765         SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA),
11766         SND_PCI_QUIRK(0x1179, 0xff50, "TOSHIBA A305", ALC268_TOSHIBA),
11767         SND_PCI_QUIRK(0x1179, 0xff64, "TOSHIBA L305", ALC268_TOSHIBA),
11768         SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
11769         SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
11770         SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
11771         SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
11772         {}
11773 };
11774
11775 static struct alc_config_preset alc268_presets[] = {
11776         [ALC267_QUANTA_IL1] = {
11777                 .mixers = { alc267_quanta_il1_mixer },
11778                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11779                                 alc267_quanta_il1_verbs },
11780                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11781                 .dac_nids = alc268_dac_nids,
11782                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11783                 .adc_nids = alc268_adc_nids_alt,
11784                 .hp_nid = 0x03,
11785                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11786                 .channel_mode = alc268_modes,
11787                 .input_mux = &alc268_capture_source,
11788                 .unsol_event = alc267_quanta_il1_unsol_event,
11789                 .init_hook = alc267_quanta_il1_automute,
11790         },
11791         [ALC268_3ST] = {
11792                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11793                             alc268_beep_mixer },
11794                 .init_verbs = { alc268_base_init_verbs },
11795                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11796                 .dac_nids = alc268_dac_nids,
11797                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11798                 .adc_nids = alc268_adc_nids_alt,
11799                 .capsrc_nids = alc268_capsrc_nids,
11800                 .hp_nid = 0x03,
11801                 .dig_out_nid = ALC268_DIGOUT_NID,
11802                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11803                 .channel_mode = alc268_modes,
11804                 .input_mux = &alc268_capture_source,
11805         },
11806         [ALC268_TOSHIBA] = {
11807                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11808                             alc268_beep_mixer },
11809                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11810                                 alc268_toshiba_verbs },
11811                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11812                 .dac_nids = alc268_dac_nids,
11813                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11814                 .adc_nids = alc268_adc_nids_alt,
11815                 .capsrc_nids = alc268_capsrc_nids,
11816                 .hp_nid = 0x03,
11817                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11818                 .channel_mode = alc268_modes,
11819                 .input_mux = &alc268_capture_source,
11820                 .unsol_event = alc268_toshiba_unsol_event,
11821                 .init_hook = alc268_toshiba_automute,
11822         },
11823         [ALC268_ACER] = {
11824                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
11825                             alc268_beep_mixer },
11826                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11827                                 alc268_acer_verbs },
11828                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11829                 .dac_nids = alc268_dac_nids,
11830                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11831                 .adc_nids = alc268_adc_nids_alt,
11832                 .capsrc_nids = alc268_capsrc_nids,
11833                 .hp_nid = 0x02,
11834                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11835                 .channel_mode = alc268_modes,
11836                 .input_mux = &alc268_acer_capture_source,
11837                 .unsol_event = alc268_acer_unsol_event,
11838                 .init_hook = alc268_acer_init_hook,
11839         },
11840         [ALC268_ACER_DMIC] = {
11841                 .mixers = { alc268_acer_dmic_mixer, alc268_capture_alt_mixer,
11842                             alc268_beep_mixer },
11843                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11844                                 alc268_acer_verbs },
11845                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11846                 .dac_nids = alc268_dac_nids,
11847                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11848                 .adc_nids = alc268_adc_nids_alt,
11849                 .capsrc_nids = alc268_capsrc_nids,
11850                 .hp_nid = 0x02,
11851                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11852                 .channel_mode = alc268_modes,
11853                 .input_mux = &alc268_acer_dmic_capture_source,
11854                 .unsol_event = alc268_acer_unsol_event,
11855                 .init_hook = alc268_acer_init_hook,
11856         },
11857         [ALC268_ACER_ASPIRE_ONE] = {
11858                 .mixers = { alc268_acer_aspire_one_mixer,
11859                                 alc268_capture_alt_mixer },
11860                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11861                                 alc268_acer_aspire_one_verbs },
11862                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11863                 .dac_nids = alc268_dac_nids,
11864                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11865                 .adc_nids = alc268_adc_nids_alt,
11866                 .capsrc_nids = alc268_capsrc_nids,
11867                 .hp_nid = 0x03,
11868                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11869                 .channel_mode = alc268_modes,
11870                 .input_mux = &alc268_acer_lc_capture_source,
11871                 .unsol_event = alc268_acer_lc_unsol_event,
11872                 .init_hook = alc268_acer_lc_init_hook,
11873         },
11874         [ALC268_DELL] = {
11875                 .mixers = { alc268_dell_mixer, alc268_beep_mixer },
11876                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11877                                 alc268_dell_verbs },
11878                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11879                 .dac_nids = alc268_dac_nids,
11880                 .hp_nid = 0x02,
11881                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11882                 .channel_mode = alc268_modes,
11883                 .unsol_event = alc268_dell_unsol_event,
11884                 .init_hook = alc268_dell_init_hook,
11885                 .input_mux = &alc268_capture_source,
11886         },
11887         [ALC268_ZEPTO] = {
11888                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11889                             alc268_beep_mixer },
11890                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11891                                 alc268_toshiba_verbs },
11892                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11893                 .dac_nids = alc268_dac_nids,
11894                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11895                 .adc_nids = alc268_adc_nids_alt,
11896                 .capsrc_nids = alc268_capsrc_nids,
11897                 .hp_nid = 0x03,
11898                 .dig_out_nid = ALC268_DIGOUT_NID,
11899                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11900                 .channel_mode = alc268_modes,
11901                 .input_mux = &alc268_capture_source,
11902                 .unsol_event = alc268_toshiba_unsol_event,
11903                 .init_hook = alc268_toshiba_automute
11904         },
11905 #ifdef CONFIG_SND_DEBUG
11906         [ALC268_TEST] = {
11907                 .mixers = { alc268_test_mixer, alc268_capture_mixer },
11908                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11909                                 alc268_volume_init_verbs },
11910                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11911                 .dac_nids = alc268_dac_nids,
11912                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11913                 .adc_nids = alc268_adc_nids_alt,
11914                 .capsrc_nids = alc268_capsrc_nids,
11915                 .hp_nid = 0x03,
11916                 .dig_out_nid = ALC268_DIGOUT_NID,
11917                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11918                 .channel_mode = alc268_modes,
11919                 .input_mux = &alc268_capture_source,
11920         },
11921 #endif
11922 };
11923
11924 static int patch_alc268(struct hda_codec *codec)
11925 {
11926         struct alc_spec *spec;
11927         int board_config;
11928         int err;
11929
11930         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
11931         if (spec == NULL)
11932                 return -ENOMEM;
11933
11934         codec->spec = spec;
11935
11936         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
11937                                                   alc268_models,
11938                                                   alc268_cfg_tbl);
11939
11940         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
11941                 printk(KERN_INFO "hda_codec: Unknown model for ALC268, "
11942                        "trying auto-probe from BIOS...\n");
11943                 board_config = ALC268_AUTO;
11944         }
11945
11946         if (board_config == ALC268_AUTO) {
11947                 /* automatic parse from the BIOS config */
11948                 err = alc268_parse_auto_config(codec);
11949                 if (err < 0) {
11950                         alc_free(codec);
11951                         return err;
11952                 } else if (!err) {
11953                         printk(KERN_INFO
11954                                "hda_codec: Cannot set up configuration "
11955                                "from BIOS.  Using base mode...\n");
11956                         board_config = ALC268_3ST;
11957                 }
11958         }
11959
11960         if (board_config != ALC268_AUTO)
11961                 setup_preset(spec, &alc268_presets[board_config]);
11962
11963         if (codec->vendor_id == 0x10ec0267) {
11964                 spec->stream_name_analog = "ALC267 Analog";
11965                 spec->stream_name_digital = "ALC267 Digital";
11966         } else {
11967                 spec->stream_name_analog = "ALC268 Analog";
11968                 spec->stream_name_digital = "ALC268 Digital";
11969         }
11970
11971         spec->stream_analog_playback = &alc268_pcm_analog_playback;
11972         spec->stream_analog_capture = &alc268_pcm_analog_capture;
11973         spec->stream_analog_alt_capture = &alc268_pcm_analog_alt_capture;
11974
11975         spec->stream_digital_playback = &alc268_pcm_digital_playback;
11976
11977         if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
11978                 /* override the amp caps for beep generator */
11979                 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
11980                                           (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
11981                                           (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
11982                                           (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
11983                                           (0 << AC_AMPCAP_MUTE_SHIFT));
11984
11985         if (!spec->adc_nids && spec->input_mux) {
11986                 /* check whether NID 0x07 is valid */
11987                 unsigned int wcap = get_wcaps(codec, 0x07);
11988                 int i;
11989
11990                 /* get type */
11991                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
11992                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
11993                         spec->adc_nids = alc268_adc_nids_alt;
11994                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
11995                         add_mixer(spec, alc268_capture_alt_mixer);
11996                 } else {
11997                         spec->adc_nids = alc268_adc_nids;
11998                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
11999                         add_mixer(spec, alc268_capture_mixer);
12000                 }
12001                 spec->capsrc_nids = alc268_capsrc_nids;
12002                 /* set default input source */
12003                 for (i = 0; i < spec->num_adc_nids; i++)
12004                         snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
12005                                 0, AC_VERB_SET_CONNECT_SEL,
12006                                 spec->input_mux->items[0].index);
12007         }
12008
12009         spec->vmaster_nid = 0x02;
12010
12011         codec->patch_ops = alc_patch_ops;
12012         if (board_config == ALC268_AUTO)
12013                 spec->init_hook = alc268_auto_init;
12014
12015         codec->proc_widget_hook = print_realtek_coef;
12016
12017         return 0;
12018 }
12019
12020 /*
12021  *  ALC269 channel source setting (2 channel)
12022  */
12023 #define ALC269_DIGOUT_NID       ALC880_DIGOUT_NID
12024
12025 #define alc269_dac_nids         alc260_dac_nids
12026
12027 static hda_nid_t alc269_adc_nids[1] = {
12028         /* ADC1 */
12029         0x08,
12030 };
12031
12032 static hda_nid_t alc269_capsrc_nids[1] = {
12033         0x23,
12034 };
12035
12036 /* NOTE: ADC2 (0x07) is connected from a recording *MIXER* (0x24),
12037  *       not a mux!
12038  */
12039
12040 static struct hda_input_mux alc269_eeepc_dmic_capture_source = {
12041         .num_items = 2,
12042         .items = {
12043                 { "i-Mic", 0x5 },
12044                 { "e-Mic", 0x0 },
12045         },
12046 };
12047
12048 static struct hda_input_mux alc269_eeepc_amic_capture_source = {
12049         .num_items = 2,
12050         .items = {
12051                 { "i-Mic", 0x1 },
12052                 { "e-Mic", 0x0 },
12053         },
12054 };
12055
12056 #define alc269_modes            alc260_modes
12057 #define alc269_capture_source   alc880_lg_lw_capture_source
12058
12059 static struct snd_kcontrol_new alc269_base_mixer[] = {
12060         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12061         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12062         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12063         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12064         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12065         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12066         HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x4, HDA_INPUT),
12067         HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x4, HDA_INPUT),
12068         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12069         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12070         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12071         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
12072         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12073         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
12074         { } /* end */
12075 };
12076
12077 static struct snd_kcontrol_new alc269_quanta_fl1_mixer[] = {
12078         /* output mixer control */
12079         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12080         {
12081                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12082                 .name = "Master Playback Switch",
12083                 .info = snd_hda_mixer_amp_switch_info,
12084                 .get = snd_hda_mixer_amp_switch_get,
12085                 .put = alc268_acer_master_sw_put,
12086                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12087         },
12088         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12089         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12090         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12091         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12092         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12093         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12094         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x04, HDA_INPUT),
12095         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x04, HDA_INPUT),
12096         { }
12097 };
12098
12099 static struct snd_kcontrol_new alc269_lifebook_mixer[] = {
12100         /* output mixer control */
12101         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12102         {
12103                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12104                 .name = "Master Playback Switch",
12105                 .info = snd_hda_mixer_amp_switch_info,
12106                 .get = snd_hda_mixer_amp_switch_get,
12107                 .put = alc268_acer_master_sw_put,
12108                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12109         },
12110         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12111         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12112         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12113         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12114         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12115         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12116         HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x0b, 0x03, HDA_INPUT),
12117         HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x0b, 0x03, HDA_INPUT),
12118         HDA_CODEC_VOLUME("Dock Mic Boost", 0x1b, 0, HDA_INPUT),
12119         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x04, HDA_INPUT),
12120         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x04, HDA_INPUT),
12121         { }
12122 };
12123
12124 /* bind volumes of both NID 0x0c and 0x0d */
12125 static struct hda_bind_ctls alc269_epc_bind_vol = {
12126         .ops = &snd_hda_bind_vol,
12127         .values = {
12128                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
12129                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
12130                 0
12131         },
12132 };
12133
12134 static struct snd_kcontrol_new alc269_eeepc_mixer[] = {
12135         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12136         HDA_BIND_VOL("LineOut Playback Volume", &alc269_epc_bind_vol),
12137         HDA_CODEC_MUTE("LineOut Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12138         { } /* end */
12139 };
12140
12141 /* capture mixer elements */
12142 static struct snd_kcontrol_new alc269_epc_capture_mixer[] = {
12143         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12144         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12145         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12146         { } /* end */
12147 };
12148
12149 /* FSC amilo */
12150 static struct snd_kcontrol_new alc269_fujitsu_mixer[] = {
12151         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12152         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12153         HDA_BIND_VOL("PCM Playback Volume", &alc269_epc_bind_vol),
12154         { } /* end */
12155 };
12156
12157 /* beep control */
12158 static struct snd_kcontrol_new alc269_beep_mixer[] = {
12159         HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x4, HDA_INPUT),
12160         HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x4, HDA_INPUT),
12161         { } /* end */
12162 };
12163
12164 static struct hda_verb alc269_quanta_fl1_verbs[] = {
12165         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12166         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12167         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12168         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12169         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12170         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12171         { }
12172 };
12173
12174 static struct hda_verb alc269_lifebook_verbs[] = {
12175         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12176         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
12177         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12178         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12179         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12180         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12181         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12182         {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12183         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12184         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12185         { }
12186 };
12187
12188 /* toggle speaker-output according to the hp-jack state */
12189 static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec)
12190 {
12191         unsigned int present;
12192         unsigned char bits;
12193
12194         present = snd_hda_codec_read(codec, 0x15, 0,
12195                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12196         bits = present ? AMP_IN_MUTE(0) : 0;
12197         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12198                         AMP_IN_MUTE(0), bits);
12199         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12200                         AMP_IN_MUTE(0), bits);
12201
12202         snd_hda_codec_write(codec, 0x20, 0,
12203                         AC_VERB_SET_COEF_INDEX, 0x0c);
12204         snd_hda_codec_write(codec, 0x20, 0,
12205                         AC_VERB_SET_PROC_COEF, 0x680);
12206
12207         snd_hda_codec_write(codec, 0x20, 0,
12208                         AC_VERB_SET_COEF_INDEX, 0x0c);
12209         snd_hda_codec_write(codec, 0x20, 0,
12210                         AC_VERB_SET_PROC_COEF, 0x480);
12211 }
12212
12213 /* toggle speaker-output according to the hp-jacks state */
12214 static void alc269_lifebook_speaker_automute(struct hda_codec *codec)
12215 {
12216         unsigned int present;
12217         unsigned char bits;
12218
12219         /* Check laptop headphone socket */
12220         present = snd_hda_codec_read(codec, 0x15, 0,
12221                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12222
12223         /* Check port replicator headphone socket */
12224         present |= snd_hda_codec_read(codec, 0x1a, 0,
12225                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12226
12227         bits = present ? AMP_IN_MUTE(0) : 0;
12228         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12229                         AMP_IN_MUTE(0), bits);
12230         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12231                         AMP_IN_MUTE(0), bits);
12232
12233         snd_hda_codec_write(codec, 0x20, 0,
12234                         AC_VERB_SET_COEF_INDEX, 0x0c);
12235         snd_hda_codec_write(codec, 0x20, 0,
12236                         AC_VERB_SET_PROC_COEF, 0x680);
12237
12238         snd_hda_codec_write(codec, 0x20, 0,
12239                         AC_VERB_SET_COEF_INDEX, 0x0c);
12240         snd_hda_codec_write(codec, 0x20, 0,
12241                         AC_VERB_SET_PROC_COEF, 0x480);
12242 }
12243
12244 static void alc269_quanta_fl1_mic_automute(struct hda_codec *codec)
12245 {
12246         unsigned int present;
12247
12248         present = snd_hda_codec_read(codec, 0x18, 0,
12249                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12250         snd_hda_codec_write(codec, 0x23, 0,
12251                             AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x1);
12252 }
12253
12254 static void alc269_lifebook_mic_autoswitch(struct hda_codec *codec)
12255 {
12256         unsigned int present_laptop;
12257         unsigned int present_dock;
12258
12259         present_laptop = snd_hda_codec_read(codec, 0x18, 0,
12260                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12261
12262         present_dock = snd_hda_codec_read(codec, 0x1b, 0,
12263                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12264
12265         /* Laptop mic port overrides dock mic port, design decision */
12266         if (present_dock)
12267                 snd_hda_codec_write(codec, 0x23, 0,
12268                                 AC_VERB_SET_CONNECT_SEL, 0x3);
12269         if (present_laptop)
12270                 snd_hda_codec_write(codec, 0x23, 0,
12271                                 AC_VERB_SET_CONNECT_SEL, 0x0);
12272         if (!present_dock && !present_laptop)
12273                 snd_hda_codec_write(codec, 0x23, 0,
12274                                 AC_VERB_SET_CONNECT_SEL, 0x1);
12275 }
12276
12277 static void alc269_quanta_fl1_unsol_event(struct hda_codec *codec,
12278                                     unsigned int res)
12279 {
12280         if ((res >> 26) == ALC880_HP_EVENT)
12281                 alc269_quanta_fl1_speaker_automute(codec);
12282         if ((res >> 26) == ALC880_MIC_EVENT)
12283                 alc269_quanta_fl1_mic_automute(codec);
12284 }
12285
12286 static void alc269_lifebook_unsol_event(struct hda_codec *codec,
12287                                         unsigned int res)
12288 {
12289         if ((res >> 26) == ALC880_HP_EVENT)
12290                 alc269_lifebook_speaker_automute(codec);
12291         if ((res >> 26) == ALC880_MIC_EVENT)
12292                 alc269_lifebook_mic_autoswitch(codec);
12293 }
12294
12295 static void alc269_quanta_fl1_init_hook(struct hda_codec *codec)
12296 {
12297         alc269_quanta_fl1_speaker_automute(codec);
12298         alc269_quanta_fl1_mic_automute(codec);
12299 }
12300
12301 static void alc269_lifebook_init_hook(struct hda_codec *codec)
12302 {
12303         alc269_lifebook_speaker_automute(codec);
12304         alc269_lifebook_mic_autoswitch(codec);
12305 }
12306
12307 static struct hda_verb alc269_eeepc_dmic_init_verbs[] = {
12308         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12309         {0x23, AC_VERB_SET_CONNECT_SEL, 0x05},
12310         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
12311         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
12312         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12313         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12314         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12315         {}
12316 };
12317
12318 static struct hda_verb alc269_eeepc_amic_init_verbs[] = {
12319         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12320         {0x23, AC_VERB_SET_CONNECT_SEL, 0x01},
12321         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
12322         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x701b | (0x00 << 8))},
12323         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12324         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12325         {}
12326 };
12327
12328 /* toggle speaker-output according to the hp-jack state */
12329 static void alc269_speaker_automute(struct hda_codec *codec)
12330 {
12331         unsigned int present;
12332         unsigned char bits;
12333
12334         present = snd_hda_codec_read(codec, 0x15, 0,
12335                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12336         bits = present ? AMP_IN_MUTE(0) : 0;
12337         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12338                                 AMP_IN_MUTE(0), bits);
12339         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12340                                 AMP_IN_MUTE(0), bits);
12341 }
12342
12343 static void alc269_eeepc_dmic_automute(struct hda_codec *codec)
12344 {
12345         unsigned int present;
12346
12347         present = snd_hda_codec_read(codec, 0x18, 0,
12348                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12349         snd_hda_codec_write(codec, 0x23, 0,
12350                                 AC_VERB_SET_CONNECT_SEL,  (present ? 0 : 5));
12351 }
12352
12353 static void alc269_eeepc_amic_automute(struct hda_codec *codec)
12354 {
12355         unsigned int present;
12356
12357         present = snd_hda_codec_read(codec, 0x18, 0,
12358                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12359         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12360                                 0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
12361         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12362                                 0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
12363 }
12364
12365 /* unsolicited event for HP jack sensing */
12366 static void alc269_eeepc_dmic_unsol_event(struct hda_codec *codec,
12367                                      unsigned int res)
12368 {
12369         if ((res >> 26) == ALC880_HP_EVENT)
12370                 alc269_speaker_automute(codec);
12371
12372         if ((res >> 26) == ALC880_MIC_EVENT)
12373                 alc269_eeepc_dmic_automute(codec);
12374 }
12375
12376 static void alc269_eeepc_dmic_inithook(struct hda_codec *codec)
12377 {
12378         alc269_speaker_automute(codec);
12379         alc269_eeepc_dmic_automute(codec);
12380 }
12381
12382 /* unsolicited event for HP jack sensing */
12383 static void alc269_eeepc_amic_unsol_event(struct hda_codec *codec,
12384                                      unsigned int res)
12385 {
12386         if ((res >> 26) == ALC880_HP_EVENT)
12387                 alc269_speaker_automute(codec);
12388
12389         if ((res >> 26) == ALC880_MIC_EVENT)
12390                 alc269_eeepc_amic_automute(codec);
12391 }
12392
12393 static void alc269_eeepc_amic_inithook(struct hda_codec *codec)
12394 {
12395         alc269_speaker_automute(codec);
12396         alc269_eeepc_amic_automute(codec);
12397 }
12398
12399 /*
12400  * generic initialization of ADC, input mixers and output mixers
12401  */
12402 static struct hda_verb alc269_init_verbs[] = {
12403         /*
12404          * Unmute ADC0 and set the default input to mic-in
12405          */
12406         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12407
12408         /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the
12409          * analog-loopback mixer widget
12410          * Note: PASD motherboards uses the Line In 2 as the input for
12411          * front panel mic (mic 2)
12412          */
12413         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
12414         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12415         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12416         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12417         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12418         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
12419
12420         /*
12421          * Set up output mixers (0x0c - 0x0e)
12422          */
12423         /* set vol=0 to output mixers */
12424         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12425         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12426
12427         /* set up input amps for analog loopback */
12428         /* Amp Indices: DAC = 0, mixer = 1 */
12429         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12430         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12431         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12432         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12433         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12434         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12435
12436         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12437         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12438         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12439         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12440         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12441         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12442         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12443
12444         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12445         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12446         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12447         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12448         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12449         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12450         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12451
12452         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
12453         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
12454
12455         /* FIXME: use matrix-type input source selection */
12456         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
12457         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
12458         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12459         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12460         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12461         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12462
12463         /* set EAPD */
12464         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
12465         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
12466         { }
12467 };
12468
12469 /* add playback controls from the parsed DAC table */
12470 static int alc269_auto_create_multi_out_ctls(struct alc_spec *spec,
12471                                              const struct auto_pin_cfg *cfg)
12472 {
12473         hda_nid_t nid;
12474         int err;
12475
12476         spec->multiout.num_dacs = 1;    /* only use one dac */
12477         spec->multiout.dac_nids = spec->private_dac_nids;
12478         spec->multiout.dac_nids[0] = 2;
12479
12480         nid = cfg->line_out_pins[0];
12481         if (nid) {
12482                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
12483                                   "Front Playback Volume",
12484                                   HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT));
12485                 if (err < 0)
12486                         return err;
12487                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12488                                   "Front Playback Switch",
12489                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
12490                 if (err < 0)
12491                         return err;
12492         }
12493
12494         nid = cfg->speaker_pins[0];
12495         if (nid) {
12496                 if (!cfg->line_out_pins[0]) {
12497                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12498                                           "Speaker Playback Volume",
12499                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
12500                                                               HDA_OUTPUT));
12501                         if (err < 0)
12502                                 return err;
12503                 }
12504                 if (nid == 0x16) {
12505                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12506                                           "Speaker Playback Switch",
12507                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
12508                                                               HDA_OUTPUT));
12509                         if (err < 0)
12510                                 return err;
12511                 } else {
12512                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12513                                           "Speaker Playback Switch",
12514                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
12515                                                               HDA_OUTPUT));
12516                         if (err < 0)
12517                                 return err;
12518                 }
12519         }
12520         nid = cfg->hp_pins[0];
12521         if (nid) {
12522                 /* spec->multiout.hp_nid = 2; */
12523                 if (!cfg->line_out_pins[0] && !cfg->speaker_pins[0]) {
12524                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12525                                           "Headphone Playback Volume",
12526                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
12527                                                               HDA_OUTPUT));
12528                         if (err < 0)
12529                                 return err;
12530                 }
12531                 if (nid == 0x16) {
12532                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12533                                           "Headphone Playback Switch",
12534                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
12535                                                               HDA_OUTPUT));
12536                         if (err < 0)
12537                                 return err;
12538                 } else {
12539                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12540                                           "Headphone Playback Switch",
12541                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
12542                                                               HDA_OUTPUT));
12543                         if (err < 0)
12544                                 return err;
12545                 }
12546         }
12547         return 0;
12548 }
12549
12550 static int alc269_auto_create_analog_input_ctls(struct alc_spec *spec,
12551                                                 const struct auto_pin_cfg *cfg)
12552 {
12553         int err;
12554
12555         err = alc880_auto_create_analog_input_ctls(spec, cfg);
12556         if (err < 0)
12557                 return err;
12558         /* digital-mic input pin is excluded in alc880_auto_create..()
12559          * because it's under 0x18
12560          */
12561         if (cfg->input_pins[AUTO_PIN_MIC] == 0x12 ||
12562             cfg->input_pins[AUTO_PIN_FRONT_MIC] == 0x12) {
12563                 struct hda_input_mux *imux = &spec->private_imux[0];
12564                 imux->items[imux->num_items].label = "Int Mic";
12565                 imux->items[imux->num_items].index = 0x05;
12566                 imux->num_items++;
12567         }
12568         return 0;
12569 }
12570
12571 #ifdef CONFIG_SND_HDA_POWER_SAVE
12572 #define alc269_loopbacks        alc880_loopbacks
12573 #endif
12574
12575 /* pcm configuration: identiacal with ALC880 */
12576 #define alc269_pcm_analog_playback      alc880_pcm_analog_playback
12577 #define alc269_pcm_analog_capture       alc880_pcm_analog_capture
12578 #define alc269_pcm_digital_playback     alc880_pcm_digital_playback
12579 #define alc269_pcm_digital_capture      alc880_pcm_digital_capture
12580
12581 /*
12582  * BIOS auto configuration
12583  */
12584 static int alc269_parse_auto_config(struct hda_codec *codec)
12585 {
12586         struct alc_spec *spec = codec->spec;
12587         int i, err;
12588         static hda_nid_t alc269_ignore[] = { 0x1d, 0 };
12589
12590         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
12591                                            alc269_ignore);
12592         if (err < 0)
12593                 return err;
12594
12595         err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
12596         if (err < 0)
12597                 return err;
12598         err = alc269_auto_create_analog_input_ctls(spec, &spec->autocfg);
12599         if (err < 0)
12600                 return err;
12601
12602         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
12603
12604         if (spec->autocfg.dig_out_pin)
12605                 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;
12606
12607         if (spec->kctls.list)
12608                 add_mixer(spec, spec->kctls.list);
12609
12610         /* create a beep mixer control if the pin 0x1d isn't assigned */
12611         for (i = 0; i < ARRAY_SIZE(spec->autocfg.input_pins); i++)
12612                 if (spec->autocfg.input_pins[i] == 0x1d)
12613                         break;
12614         if (i >= ARRAY_SIZE(spec->autocfg.input_pins))
12615                 add_mixer(spec, alc269_beep_mixer);
12616
12617         add_verb(spec, alc269_init_verbs);
12618         spec->num_mux_defs = 1;
12619         spec->input_mux = &spec->private_imux[0];
12620         /* set default input source */
12621         snd_hda_codec_write_cache(codec, alc269_capsrc_nids[0],
12622                                   0, AC_VERB_SET_CONNECT_SEL,
12623                                   spec->input_mux->items[0].index);
12624
12625         err = alc_auto_add_mic_boost(codec);
12626         if (err < 0)
12627                 return err;
12628
12629         if (!spec->cap_mixer)
12630                 set_capture_mixer(spec);
12631
12632         store_pin_configs(codec);
12633         return 1;
12634 }
12635
12636 #define alc269_auto_init_multi_out      alc882_auto_init_multi_out
12637 #define alc269_auto_init_hp_out         alc882_auto_init_hp_out
12638 #define alc269_auto_init_analog_input   alc882_auto_init_analog_input
12639
12640
12641 /* init callback for auto-configuration model -- overriding the default init */
12642 static void alc269_auto_init(struct hda_codec *codec)
12643 {
12644         struct alc_spec *spec = codec->spec;
12645         alc269_auto_init_multi_out(codec);
12646         alc269_auto_init_hp_out(codec);
12647         alc269_auto_init_analog_input(codec);
12648         if (spec->unsol_event)
12649                 alc_inithook(codec);
12650 }
12651
12652 /*
12653  * configuration and preset
12654  */
12655 static const char *alc269_models[ALC269_MODEL_LAST] = {
12656         [ALC269_BASIC]                  = "basic",
12657         [ALC269_QUANTA_FL1]             = "quanta",
12658         [ALC269_ASUS_EEEPC_P703]        = "eeepc-p703",
12659         [ALC269_ASUS_EEEPC_P901]        = "eeepc-p901",
12660         [ALC269_FUJITSU]                = "fujitsu",
12661         [ALC269_LIFEBOOK]               = "lifebook"
12662 };
12663
12664 static struct snd_pci_quirk alc269_cfg_tbl[] = {
12665         SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_QUANTA_FL1),
12666         SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
12667                       ALC269_ASUS_EEEPC_P703),
12668         SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901",
12669                       ALC269_ASUS_EEEPC_P901),
12670         SND_PCI_QUIRK(0x1043, 0x834a, "ASUS Eeepc S101",
12671                       ALC269_ASUS_EEEPC_P901),
12672         SND_PCI_QUIRK(0x1734, 0x115d, "FSC Amilo", ALC269_FUJITSU),
12673         SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook ICH9M-based", ALC269_LIFEBOOK),
12674         {}
12675 };
12676
12677 static struct alc_config_preset alc269_presets[] = {
12678         [ALC269_BASIC] = {
12679                 .mixers = { alc269_base_mixer },
12680                 .init_verbs = { alc269_init_verbs },
12681                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12682                 .dac_nids = alc269_dac_nids,
12683                 .hp_nid = 0x03,
12684                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12685                 .channel_mode = alc269_modes,
12686                 .input_mux = &alc269_capture_source,
12687         },
12688         [ALC269_QUANTA_FL1] = {
12689                 .mixers = { alc269_quanta_fl1_mixer },
12690                 .init_verbs = { alc269_init_verbs, alc269_quanta_fl1_verbs },
12691                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12692                 .dac_nids = alc269_dac_nids,
12693                 .hp_nid = 0x03,
12694                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12695                 .channel_mode = alc269_modes,
12696                 .input_mux = &alc269_capture_source,
12697                 .unsol_event = alc269_quanta_fl1_unsol_event,
12698                 .init_hook = alc269_quanta_fl1_init_hook,
12699         },
12700         [ALC269_ASUS_EEEPC_P703] = {
12701                 .mixers = { alc269_eeepc_mixer },
12702                 .cap_mixer = alc269_epc_capture_mixer,
12703                 .init_verbs = { alc269_init_verbs,
12704                                 alc269_eeepc_amic_init_verbs },
12705                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12706                 .dac_nids = alc269_dac_nids,
12707                 .hp_nid = 0x03,
12708                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12709                 .channel_mode = alc269_modes,
12710                 .input_mux = &alc269_eeepc_amic_capture_source,
12711                 .unsol_event = alc269_eeepc_amic_unsol_event,
12712                 .init_hook = alc269_eeepc_amic_inithook,
12713         },
12714         [ALC269_ASUS_EEEPC_P901] = {
12715                 .mixers = { alc269_eeepc_mixer },
12716                 .cap_mixer = alc269_epc_capture_mixer,
12717                 .init_verbs = { alc269_init_verbs,
12718                                 alc269_eeepc_dmic_init_verbs },
12719                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12720                 .dac_nids = alc269_dac_nids,
12721                 .hp_nid = 0x03,
12722                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12723                 .channel_mode = alc269_modes,
12724                 .input_mux = &alc269_eeepc_dmic_capture_source,
12725                 .unsol_event = alc269_eeepc_dmic_unsol_event,
12726                 .init_hook = alc269_eeepc_dmic_inithook,
12727         },
12728         [ALC269_FUJITSU] = {
12729                 .mixers = { alc269_fujitsu_mixer, alc269_beep_mixer },
12730                 .cap_mixer = alc269_epc_capture_mixer,
12731                 .init_verbs = { alc269_init_verbs,
12732                                 alc269_eeepc_dmic_init_verbs },
12733                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12734                 .dac_nids = alc269_dac_nids,
12735                 .hp_nid = 0x03,
12736                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12737                 .channel_mode = alc269_modes,
12738                 .input_mux = &alc269_eeepc_dmic_capture_source,
12739                 .unsol_event = alc269_eeepc_dmic_unsol_event,
12740                 .init_hook = alc269_eeepc_dmic_inithook,
12741         },
12742         [ALC269_LIFEBOOK] = {
12743                 .mixers = { alc269_lifebook_mixer },
12744                 .init_verbs = { alc269_init_verbs, alc269_lifebook_verbs },
12745                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12746                 .dac_nids = alc269_dac_nids,
12747                 .hp_nid = 0x03,
12748                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12749                 .channel_mode = alc269_modes,
12750                 .input_mux = &alc269_capture_source,
12751                 .unsol_event = alc269_lifebook_unsol_event,
12752                 .init_hook = alc269_lifebook_init_hook,
12753         },
12754 };
12755
12756 static int patch_alc269(struct hda_codec *codec)
12757 {
12758         struct alc_spec *spec;
12759         int board_config;
12760         int err;
12761
12762         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
12763         if (spec == NULL)
12764                 return -ENOMEM;
12765
12766         codec->spec = spec;
12767
12768         alc_fix_pll_init(codec, 0x20, 0x04, 15);
12769
12770         board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
12771                                                   alc269_models,
12772                                                   alc269_cfg_tbl);
12773
12774         if (board_config < 0) {
12775                 printk(KERN_INFO "hda_codec: Unknown model for ALC269, "
12776                        "trying auto-probe from BIOS...\n");
12777                 board_config = ALC269_AUTO;
12778         }
12779
12780         if (board_config == ALC269_AUTO) {
12781                 /* automatic parse from the BIOS config */
12782                 err = alc269_parse_auto_config(codec);
12783                 if (err < 0) {
12784                         alc_free(codec);
12785                         return err;
12786                 } else if (!err) {
12787                         printk(KERN_INFO
12788                                "hda_codec: Cannot set up configuration "
12789                                "from BIOS.  Using base mode...\n");
12790                         board_config = ALC269_BASIC;
12791                 }
12792         }
12793
12794         if (board_config != ALC269_AUTO)
12795                 setup_preset(spec, &alc269_presets[board_config]);
12796
12797         spec->stream_name_analog = "ALC269 Analog";
12798         spec->stream_analog_playback = &alc269_pcm_analog_playback;
12799         spec->stream_analog_capture = &alc269_pcm_analog_capture;
12800
12801         spec->stream_name_digital = "ALC269 Digital";
12802         spec->stream_digital_playback = &alc269_pcm_digital_playback;
12803         spec->stream_digital_capture = &alc269_pcm_digital_capture;
12804
12805         spec->adc_nids = alc269_adc_nids;
12806         spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
12807         spec->capsrc_nids = alc269_capsrc_nids;
12808         if (!spec->cap_mixer)
12809                 set_capture_mixer(spec);
12810
12811         codec->patch_ops = alc_patch_ops;
12812         if (board_config == ALC269_AUTO)
12813                 spec->init_hook = alc269_auto_init;
12814 #ifdef CONFIG_SND_HDA_POWER_SAVE
12815         if (!spec->loopback.amplist)
12816                 spec->loopback.amplist = alc269_loopbacks;
12817 #endif
12818         codec->proc_widget_hook = print_realtek_coef;
12819
12820         return 0;
12821 }
12822
12823 /*
12824  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
12825  */
12826
12827 /*
12828  * set the path ways for 2 channel output
12829  * need to set the codec line out and mic 1 pin widgets to inputs
12830  */
12831 static struct hda_verb alc861_threestack_ch2_init[] = {
12832         /* set pin widget 1Ah (line in) for input */
12833         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12834         /* set pin widget 18h (mic1/2) for input, for mic also enable
12835          * the vref
12836          */
12837         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12838
12839         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
12840 #if 0
12841         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12842         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
12843 #endif
12844         { } /* end */
12845 };
12846 /*
12847  * 6ch mode
12848  * need to set the codec line out and mic 1 pin widgets to outputs
12849  */
12850 static struct hda_verb alc861_threestack_ch6_init[] = {
12851         /* set pin widget 1Ah (line in) for output (Back Surround)*/
12852         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12853         /* set pin widget 18h (mic1) for output (CLFE)*/
12854         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12855
12856         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
12857         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
12858
12859         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
12860 #if 0
12861         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12862         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
12863 #endif
12864         { } /* end */
12865 };
12866
12867 static struct hda_channel_mode alc861_threestack_modes[2] = {
12868         { 2, alc861_threestack_ch2_init },
12869         { 6, alc861_threestack_ch6_init },
12870 };
12871 /* Set mic1 as input and unmute the mixer */
12872 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
12873         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12874         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12875         { } /* end */
12876 };
12877 /* Set mic1 as output and mute mixer */
12878 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
12879         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12880         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12881         { } /* end */
12882 };
12883
12884 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
12885         { 2, alc861_uniwill_m31_ch2_init },
12886         { 4, alc861_uniwill_m31_ch4_init },
12887 };
12888
12889 /* Set mic1 and line-in as input and unmute the mixer */
12890 static struct hda_verb alc861_asus_ch2_init[] = {
12891         /* set pin widget 1Ah (line in) for input */
12892         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12893         /* set pin widget 18h (mic1/2) for input, for mic also enable
12894          * the vref
12895          */
12896         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12897
12898         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
12899 #if 0
12900         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12901         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
12902 #endif
12903         { } /* end */
12904 };
12905 /* Set mic1 nad line-in as output and mute mixer */
12906 static struct hda_verb alc861_asus_ch6_init[] = {
12907         /* set pin widget 1Ah (line in) for output (Back Surround)*/
12908         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12909         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
12910         /* set pin widget 18h (mic1) for output (CLFE)*/
12911         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12912         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
12913         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
12914         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
12915
12916         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
12917 #if 0
12918         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12919         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
12920 #endif
12921         { } /* end */
12922 };
12923
12924 static struct hda_channel_mode alc861_asus_modes[2] = {
12925         { 2, alc861_asus_ch2_init },
12926         { 6, alc861_asus_ch6_init },
12927 };
12928
12929 /* patch-ALC861 */
12930
12931 static struct snd_kcontrol_new alc861_base_mixer[] = {
12932         /* output mixer control */
12933         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12934         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12935         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12936         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12937         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
12938
12939         /*Input mixer control */
12940         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12941            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12942         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12943         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12944         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12945         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12946         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12947         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12948         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12949         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12950
12951         { } /* end */
12952 };
12953
12954 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
12955         /* output mixer control */
12956         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12957         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12958         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12959         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12960         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
12961
12962         /* Input mixer control */
12963         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12964            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12965         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12966         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12967         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12968         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12969         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12970         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12971         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12972         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12973
12974         {
12975                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12976                 .name = "Channel Mode",
12977                 .info = alc_ch_mode_info,
12978                 .get = alc_ch_mode_get,
12979                 .put = alc_ch_mode_put,
12980                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
12981         },
12982         { } /* end */
12983 };
12984
12985 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
12986         /* output mixer control */
12987         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12988         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12989         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12990
12991         { } /* end */
12992 };
12993
12994 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
12995         /* output mixer control */
12996         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12997         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12998         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12999         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13000         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
13001
13002         /* Input mixer control */
13003         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13004            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
13005         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13006         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13007         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13008         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13009         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13010         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13011         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13012         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
13013
13014         {
13015                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13016                 .name = "Channel Mode",
13017                 .info = alc_ch_mode_info,
13018                 .get = alc_ch_mode_get,
13019                 .put = alc_ch_mode_put,
13020                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
13021         },
13022         { } /* end */
13023 };
13024
13025 static struct snd_kcontrol_new alc861_asus_mixer[] = {
13026         /* output mixer control */
13027         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13028         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13029         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13030         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13031         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
13032
13033         /* Input mixer control */
13034         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13035         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
13036         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13037         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13038         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13039         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13040         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13041         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13042         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13043         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
13044
13045         {
13046                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13047                 .name = "Channel Mode",
13048                 .info = alc_ch_mode_info,
13049                 .get = alc_ch_mode_get,
13050                 .put = alc_ch_mode_put,
13051                 .private_value = ARRAY_SIZE(alc861_asus_modes),
13052         },
13053         { }
13054 };
13055
13056 /* additional mixer */
13057 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
13058         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13059         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13060         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x23, 0x0, HDA_OUTPUT),
13061         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x23, 0x0, HDA_OUTPUT),
13062         { }
13063 };
13064
13065 /*
13066  * generic initialization of ADC, input mixers and output mixers
13067  */
13068 static struct hda_verb alc861_base_init_verbs[] = {
13069         /*
13070          * Unmute ADC0 and set the default input to mic-in
13071          */
13072         /* port-A for surround (rear panel) */
13073         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13074         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
13075         /* port-B for mic-in (rear panel) with vref */
13076         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13077         /* port-C for line-in (rear panel) */
13078         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13079         /* port-D for Front */
13080         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13081         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13082         /* port-E for HP out (front panel) */
13083         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
13084         /* route front PCM to HP */
13085         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13086         /* port-F for mic-in (front panel) with vref */
13087         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13088         /* port-G for CLFE (rear panel) */
13089         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13090         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13091         /* port-H for side (rear panel) */
13092         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13093         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
13094         /* CD-in */
13095         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13096         /* route front mic to ADC1*/
13097         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13098         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13099
13100         /* Unmute DAC0~3 & spdif out*/
13101         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13102         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13103         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13104         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13105         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13106
13107         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13108         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13109         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13110         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13111         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13112
13113         /* Unmute Stereo Mixer 15 */
13114         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13115         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13116         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13117         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13118
13119         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13120         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13121         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13122         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13123         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13124         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13125         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13126         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13127         /* hp used DAC 3 (Front) */
13128         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13129         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13130
13131         { }
13132 };
13133
13134 static struct hda_verb alc861_threestack_init_verbs[] = {
13135         /*
13136          * Unmute ADC0 and set the default input to mic-in
13137          */
13138         /* port-A for surround (rear panel) */
13139         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13140         /* port-B for mic-in (rear panel) with vref */
13141         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13142         /* port-C for line-in (rear panel) */
13143         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13144         /* port-D for Front */
13145         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13146         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13147         /* port-E for HP out (front panel) */
13148         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
13149         /* route front PCM to HP */
13150         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13151         /* port-F for mic-in (front panel) with vref */
13152         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13153         /* port-G for CLFE (rear panel) */
13154         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13155         /* port-H for side (rear panel) */
13156         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13157         /* CD-in */
13158         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13159         /* route front mic to ADC1*/
13160         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13161         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13162         /* Unmute DAC0~3 & spdif out*/
13163         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13164         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13165         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13166         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13167         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13168
13169         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13170         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13171         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13172         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13173         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13174
13175         /* Unmute Stereo Mixer 15 */
13176         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13177         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13178         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13179         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13180
13181         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13182         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13183         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13184         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13185         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13186         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13187         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13188         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13189         /* hp used DAC 3 (Front) */
13190         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13191         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13192         { }
13193 };
13194
13195 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
13196         /*
13197          * Unmute ADC0 and set the default input to mic-in
13198          */
13199         /* port-A for surround (rear panel) */
13200         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13201         /* port-B for mic-in (rear panel) with vref */
13202         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13203         /* port-C for line-in (rear panel) */
13204         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13205         /* port-D for Front */
13206         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13207         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13208         /* port-E for HP out (front panel) */
13209         /* this has to be set to VREF80 */
13210         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13211         /* route front PCM to HP */
13212         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13213         /* port-F for mic-in (front panel) with vref */
13214         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13215         /* port-G for CLFE (rear panel) */
13216         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13217         /* port-H for side (rear panel) */
13218         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13219         /* CD-in */
13220         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13221         /* route front mic to ADC1*/
13222         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13223         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13224         /* Unmute DAC0~3 & spdif out*/
13225         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13226         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13227         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13228         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13229         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13230
13231         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13232         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13233         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13234         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13235         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13236
13237         /* Unmute Stereo Mixer 15 */
13238         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13239         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13240         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13241         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13242
13243         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13244         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13245         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13246         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13247         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13248         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13249         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13250         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13251         /* hp used DAC 3 (Front) */
13252         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13253         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13254         { }
13255 };
13256
13257 static struct hda_verb alc861_asus_init_verbs[] = {
13258         /*
13259          * Unmute ADC0 and set the default input to mic-in
13260          */
13261         /* port-A for surround (rear panel)
13262          * according to codec#0 this is the HP jack
13263          */
13264         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
13265         /* route front PCM to HP */
13266         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
13267         /* port-B for mic-in (rear panel) with vref */
13268         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13269         /* port-C for line-in (rear panel) */
13270         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13271         /* port-D for Front */
13272         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13273         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13274         /* port-E for HP out (front panel) */
13275         /* this has to be set to VREF80 */
13276         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13277         /* route front PCM to HP */
13278         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13279         /* port-F for mic-in (front panel) with vref */
13280         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13281         /* port-G for CLFE (rear panel) */
13282         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13283         /* port-H for side (rear panel) */
13284         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13285         /* CD-in */
13286         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13287         /* route front mic to ADC1*/
13288         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13289         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13290         /* Unmute DAC0~3 & spdif out*/
13291         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13292         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13293         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13294         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13295         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13296         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13297         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13298         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13299         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13300         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13301
13302         /* Unmute Stereo Mixer 15 */
13303         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13304         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13305         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13306         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13307
13308         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13309         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13310         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13311         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13312         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13313         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13314         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13315         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13316         /* hp used DAC 3 (Front) */
13317         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13318         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13319         { }
13320 };
13321
13322 /* additional init verbs for ASUS laptops */
13323 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
13324         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
13325         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
13326         { }
13327 };
13328
13329 /*
13330  * generic initialization of ADC, input mixers and output mixers
13331  */
13332 static struct hda_verb alc861_auto_init_verbs[] = {
13333         /*
13334          * Unmute ADC0 and set the default input to mic-in
13335          */
13336         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
13337         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13338
13339         /* Unmute DAC0~3 & spdif out*/
13340         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13341         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13342         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13343         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13344         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13345
13346         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13347         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13348         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13349         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13350         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13351
13352         /* Unmute Stereo Mixer 15 */
13353         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13354         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13355         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13356         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
13357
13358         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13359         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13360         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13361         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13362         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13363         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13364         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13365         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13366
13367         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13368         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13369         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13370         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13371         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13372         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13373         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13374         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13375
13376         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
13377
13378         { }
13379 };
13380
13381 static struct hda_verb alc861_toshiba_init_verbs[] = {
13382         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13383
13384         { }
13385 };
13386
13387 /* toggle speaker-output according to the hp-jack state */
13388 static void alc861_toshiba_automute(struct hda_codec *codec)
13389 {
13390         unsigned int present;
13391
13392         present = snd_hda_codec_read(codec, 0x0f, 0,
13393                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13394         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
13395                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
13396         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
13397                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
13398 }
13399
13400 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
13401                                        unsigned int res)
13402 {
13403         if ((res >> 26) == ALC880_HP_EVENT)
13404                 alc861_toshiba_automute(codec);
13405 }
13406
13407 /* pcm configuration: identiacal with ALC880 */
13408 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
13409 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
13410 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
13411 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
13412
13413
13414 #define ALC861_DIGOUT_NID       0x07
13415
13416 static struct hda_channel_mode alc861_8ch_modes[1] = {
13417         { 8, NULL }
13418 };
13419
13420 static hda_nid_t alc861_dac_nids[4] = {
13421         /* front, surround, clfe, side */
13422         0x03, 0x06, 0x05, 0x04
13423 };
13424
13425 static hda_nid_t alc660_dac_nids[3] = {
13426         /* front, clfe, surround */
13427         0x03, 0x05, 0x06
13428 };
13429
13430 static hda_nid_t alc861_adc_nids[1] = {
13431         /* ADC0-2 */
13432         0x08,
13433 };
13434
13435 static struct hda_input_mux alc861_capture_source = {
13436         .num_items = 5,
13437         .items = {
13438                 { "Mic", 0x0 },
13439                 { "Front Mic", 0x3 },
13440                 { "Line", 0x1 },
13441                 { "CD", 0x4 },
13442                 { "Mixer", 0x5 },
13443         },
13444 };
13445
13446 /* fill in the dac_nids table from the parsed pin configuration */
13447 static int alc861_auto_fill_dac_nids(struct alc_spec *spec,
13448                                      const struct auto_pin_cfg *cfg)
13449 {
13450         int i;
13451         hda_nid_t nid;
13452
13453         spec->multiout.dac_nids = spec->private_dac_nids;
13454         for (i = 0; i < cfg->line_outs; i++) {
13455                 nid = cfg->line_out_pins[i];
13456                 if (nid) {
13457                         if (i >= ARRAY_SIZE(alc861_dac_nids))
13458                                 continue;
13459                         spec->multiout.dac_nids[i] = alc861_dac_nids[i];
13460                 }
13461         }
13462         spec->multiout.num_dacs = cfg->line_outs;
13463         return 0;
13464 }
13465
13466 /* add playback controls from the parsed DAC table */
13467 static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
13468                                              const struct auto_pin_cfg *cfg)
13469 {
13470         char name[32];
13471         static const char *chname[4] = {
13472                 "Front", "Surround", NULL /*CLFE*/, "Side"
13473         };
13474         hda_nid_t nid;
13475         int i, idx, err;
13476
13477         for (i = 0; i < cfg->line_outs; i++) {
13478                 nid = spec->multiout.dac_nids[i];
13479                 if (!nid)
13480                         continue;
13481                 if (nid == 0x05) {
13482                         /* Center/LFE */
13483                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13484                                           "Center Playback Switch",
13485                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
13486                                                               HDA_OUTPUT));
13487                         if (err < 0)
13488                                 return err;
13489                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13490                                           "LFE Playback Switch",
13491                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
13492                                                               HDA_OUTPUT));
13493                         if (err < 0)
13494                                 return err;
13495                 } else {
13496                         for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1;
13497                              idx++)
13498                                 if (nid == alc861_dac_nids[idx])
13499                                         break;
13500                         sprintf(name, "%s Playback Switch", chname[idx]);
13501                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
13502                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
13503                                                               HDA_OUTPUT));
13504                         if (err < 0)
13505                                 return err;
13506                 }
13507         }
13508         return 0;
13509 }
13510
13511 static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
13512 {
13513         int err;
13514         hda_nid_t nid;
13515
13516         if (!pin)
13517                 return 0;
13518
13519         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
13520                 nid = 0x03;
13521                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13522                                   "Headphone Playback Switch",
13523                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
13524                 if (err < 0)
13525                         return err;
13526                 spec->multiout.hp_nid = nid;
13527         }
13528         return 0;
13529 }
13530
13531 /* create playback/capture controls for input pins */
13532 static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec,
13533                                                 const struct auto_pin_cfg *cfg)
13534 {
13535         struct hda_input_mux *imux = &spec->private_imux[0];
13536         int i, err, idx, idx1;
13537
13538         for (i = 0; i < AUTO_PIN_LAST; i++) {
13539                 switch (cfg->input_pins[i]) {
13540                 case 0x0c:
13541                         idx1 = 1;
13542                         idx = 2;        /* Line In */
13543                         break;
13544                 case 0x0f:
13545                         idx1 = 2;
13546                         idx = 2;        /* Line In */
13547                         break;
13548                 case 0x0d:
13549                         idx1 = 0;
13550                         idx = 1;        /* Mic In */
13551                         break;
13552                 case 0x10:
13553                         idx1 = 3;
13554                         idx = 1;        /* Mic In */
13555                         break;
13556                 case 0x11:
13557                         idx1 = 4;
13558                         idx = 0;        /* CD */
13559                         break;
13560                 default:
13561                         continue;
13562                 }
13563
13564                 err = new_analog_input(spec, cfg->input_pins[i],
13565                                        auto_pin_cfg_labels[i], idx, 0x15);
13566                 if (err < 0)
13567                         return err;
13568
13569                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
13570                 imux->items[imux->num_items].index = idx1;
13571                 imux->num_items++;
13572         }
13573         return 0;
13574 }
13575
13576 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
13577                                               hda_nid_t nid,
13578                                               int pin_type, int dac_idx)
13579 {
13580         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
13581                             pin_type);
13582         snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13583                             AMP_OUT_UNMUTE);
13584 }
13585
13586 static void alc861_auto_init_multi_out(struct hda_codec *codec)
13587 {
13588         struct alc_spec *spec = codec->spec;
13589         int i;
13590
13591         alc_subsystem_id(codec, 0x0e, 0x0f, 0x0b);
13592         for (i = 0; i < spec->autocfg.line_outs; i++) {
13593                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
13594                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
13595                 if (nid)
13596                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
13597                                                           spec->multiout.dac_nids[i]);
13598         }
13599 }
13600
13601 static void alc861_auto_init_hp_out(struct hda_codec *codec)
13602 {
13603         struct alc_spec *spec = codec->spec;
13604         hda_nid_t pin;
13605
13606         pin = spec->autocfg.hp_pins[0];
13607         if (pin) /* connect to front */
13608                 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
13609                                                   spec->multiout.dac_nids[0]);
13610         pin = spec->autocfg.speaker_pins[0];
13611         if (pin)
13612                 alc861_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
13613 }
13614
13615 static void alc861_auto_init_analog_input(struct hda_codec *codec)
13616 {
13617         struct alc_spec *spec = codec->spec;
13618         int i;
13619
13620         for (i = 0; i < AUTO_PIN_LAST; i++) {
13621                 hda_nid_t nid = spec->autocfg.input_pins[i];
13622                 if (nid >= 0x0c && nid <= 0x11) {
13623                         snd_hda_codec_write(codec, nid, 0,
13624                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
13625                                             i <= AUTO_PIN_FRONT_MIC ?
13626                                             PIN_VREF80 : PIN_IN);
13627                 }
13628         }
13629 }
13630
13631 /* parse the BIOS configuration and set up the alc_spec */
13632 /* return 1 if successful, 0 if the proper config is not found,
13633  * or a negative error code
13634  */
13635 static int alc861_parse_auto_config(struct hda_codec *codec)
13636 {
13637         struct alc_spec *spec = codec->spec;
13638         int err;
13639         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
13640
13641         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
13642                                            alc861_ignore);
13643         if (err < 0)
13644                 return err;
13645         if (!spec->autocfg.line_outs)
13646                 return 0; /* can't find valid BIOS pin config */
13647
13648         err = alc861_auto_fill_dac_nids(spec, &spec->autocfg);
13649         if (err < 0)
13650                 return err;
13651         err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg);
13652         if (err < 0)
13653                 return err;
13654         err = alc861_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
13655         if (err < 0)
13656                 return err;
13657         err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg);
13658         if (err < 0)
13659                 return err;
13660
13661         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
13662
13663         if (spec->autocfg.dig_out_pin)
13664                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
13665
13666         if (spec->kctls.list)
13667                 add_mixer(spec, spec->kctls.list);
13668
13669         add_verb(spec, alc861_auto_init_verbs);
13670
13671         spec->num_mux_defs = 1;
13672         spec->input_mux = &spec->private_imux[0];
13673
13674         spec->adc_nids = alc861_adc_nids;
13675         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
13676         set_capture_mixer(spec);
13677
13678         store_pin_configs(codec);
13679         return 1;
13680 }
13681
13682 /* additional initialization for auto-configuration model */
13683 static void alc861_auto_init(struct hda_codec *codec)
13684 {
13685         struct alc_spec *spec = codec->spec;
13686         alc861_auto_init_multi_out(codec);
13687         alc861_auto_init_hp_out(codec);
13688         alc861_auto_init_analog_input(codec);
13689         if (spec->unsol_event)
13690                 alc_inithook(codec);
13691 }
13692
13693 #ifdef CONFIG_SND_HDA_POWER_SAVE
13694 static struct hda_amp_list alc861_loopbacks[] = {
13695         { 0x15, HDA_INPUT, 0 },
13696         { 0x15, HDA_INPUT, 1 },
13697         { 0x15, HDA_INPUT, 2 },
13698         { 0x15, HDA_INPUT, 3 },
13699         { } /* end */
13700 };
13701 #endif
13702
13703
13704 /*
13705  * configuration and preset
13706  */
13707 static const char *alc861_models[ALC861_MODEL_LAST] = {
13708         [ALC861_3ST]            = "3stack",
13709         [ALC660_3ST]            = "3stack-660",
13710         [ALC861_3ST_DIG]        = "3stack-dig",
13711         [ALC861_6ST_DIG]        = "6stack-dig",
13712         [ALC861_UNIWILL_M31]    = "uniwill-m31",
13713         [ALC861_TOSHIBA]        = "toshiba",
13714         [ALC861_ASUS]           = "asus",
13715         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
13716         [ALC861_AUTO]           = "auto",
13717 };
13718
13719 static struct snd_pci_quirk alc861_cfg_tbl[] = {
13720         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
13721         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
13722         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
13723         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
13724         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
13725         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
13726         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
13727         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
13728          *        Any other models that need this preset?
13729          */
13730         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
13731         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
13732         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
13733         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
13734         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
13735         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
13736         /* FIXME: the below seems conflict */
13737         /* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
13738         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
13739         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
13740         {}
13741 };
13742
13743 static struct alc_config_preset alc861_presets[] = {
13744         [ALC861_3ST] = {
13745                 .mixers = { alc861_3ST_mixer },
13746                 .init_verbs = { alc861_threestack_init_verbs },
13747                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13748                 .dac_nids = alc861_dac_nids,
13749                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13750                 .channel_mode = alc861_threestack_modes,
13751                 .need_dac_fix = 1,
13752                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13753                 .adc_nids = alc861_adc_nids,
13754                 .input_mux = &alc861_capture_source,
13755         },
13756         [ALC861_3ST_DIG] = {
13757                 .mixers = { alc861_base_mixer },
13758                 .init_verbs = { alc861_threestack_init_verbs },
13759                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13760                 .dac_nids = alc861_dac_nids,
13761                 .dig_out_nid = ALC861_DIGOUT_NID,
13762                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13763                 .channel_mode = alc861_threestack_modes,
13764                 .need_dac_fix = 1,
13765                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13766                 .adc_nids = alc861_adc_nids,
13767                 .input_mux = &alc861_capture_source,
13768         },
13769         [ALC861_6ST_DIG] = {
13770                 .mixers = { alc861_base_mixer },
13771                 .init_verbs = { alc861_base_init_verbs },
13772                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13773                 .dac_nids = alc861_dac_nids,
13774                 .dig_out_nid = ALC861_DIGOUT_NID,
13775                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
13776                 .channel_mode = alc861_8ch_modes,
13777                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13778                 .adc_nids = alc861_adc_nids,
13779                 .input_mux = &alc861_capture_source,
13780         },
13781         [ALC660_3ST] = {
13782                 .mixers = { alc861_3ST_mixer },
13783                 .init_verbs = { alc861_threestack_init_verbs },
13784                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
13785                 .dac_nids = alc660_dac_nids,
13786                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13787                 .channel_mode = alc861_threestack_modes,
13788                 .need_dac_fix = 1,
13789                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13790                 .adc_nids = alc861_adc_nids,
13791                 .input_mux = &alc861_capture_source,
13792         },
13793         [ALC861_UNIWILL_M31] = {
13794                 .mixers = { alc861_uniwill_m31_mixer },
13795                 .init_verbs = { alc861_uniwill_m31_init_verbs },
13796                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13797                 .dac_nids = alc861_dac_nids,
13798                 .dig_out_nid = ALC861_DIGOUT_NID,
13799                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
13800                 .channel_mode = alc861_uniwill_m31_modes,
13801                 .need_dac_fix = 1,
13802                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13803                 .adc_nids = alc861_adc_nids,
13804                 .input_mux = &alc861_capture_source,
13805         },
13806         [ALC861_TOSHIBA] = {
13807                 .mixers = { alc861_toshiba_mixer },
13808                 .init_verbs = { alc861_base_init_verbs,
13809                                 alc861_toshiba_init_verbs },
13810                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13811                 .dac_nids = alc861_dac_nids,
13812                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
13813                 .channel_mode = alc883_3ST_2ch_modes,
13814                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13815                 .adc_nids = alc861_adc_nids,
13816                 .input_mux = &alc861_capture_source,
13817                 .unsol_event = alc861_toshiba_unsol_event,
13818                 .init_hook = alc861_toshiba_automute,
13819         },
13820         [ALC861_ASUS] = {
13821                 .mixers = { alc861_asus_mixer },
13822                 .init_verbs = { alc861_asus_init_verbs },
13823                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13824                 .dac_nids = alc861_dac_nids,
13825                 .dig_out_nid = ALC861_DIGOUT_NID,
13826                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
13827                 .channel_mode = alc861_asus_modes,
13828                 .need_dac_fix = 1,
13829                 .hp_nid = 0x06,
13830                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13831                 .adc_nids = alc861_adc_nids,
13832                 .input_mux = &alc861_capture_source,
13833         },
13834         [ALC861_ASUS_LAPTOP] = {
13835                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
13836                 .init_verbs = { alc861_asus_init_verbs,
13837                                 alc861_asus_laptop_init_verbs },
13838                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13839                 .dac_nids = alc861_dac_nids,
13840                 .dig_out_nid = ALC861_DIGOUT_NID,
13841                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
13842                 .channel_mode = alc883_3ST_2ch_modes,
13843                 .need_dac_fix = 1,
13844                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13845                 .adc_nids = alc861_adc_nids,
13846                 .input_mux = &alc861_capture_source,
13847         },
13848 };
13849
13850
13851 static int patch_alc861(struct hda_codec *codec)
13852 {
13853         struct alc_spec *spec;
13854         int board_config;
13855         int err;
13856
13857         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13858         if (spec == NULL)
13859                 return -ENOMEM;
13860
13861         codec->spec = spec;
13862
13863         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
13864                                                   alc861_models,
13865                                                   alc861_cfg_tbl);
13866
13867         if (board_config < 0) {
13868                 printk(KERN_INFO "hda_codec: Unknown model for ALC861, "
13869                        "trying auto-probe from BIOS...\n");
13870                 board_config = ALC861_AUTO;
13871         }
13872
13873         if (board_config == ALC861_AUTO) {
13874                 /* automatic parse from the BIOS config */
13875                 err = alc861_parse_auto_config(codec);
13876                 if (err < 0) {
13877                         alc_free(codec);
13878                         return err;
13879                 } else if (!err) {
13880                         printk(KERN_INFO
13881                                "hda_codec: Cannot set up configuration "
13882                                "from BIOS.  Using base mode...\n");
13883                    board_config = ALC861_3ST_DIG;
13884                 }
13885         }
13886
13887         if (board_config != ALC861_AUTO)
13888                 setup_preset(spec, &alc861_presets[board_config]);
13889
13890         spec->stream_name_analog = "ALC861 Analog";
13891         spec->stream_analog_playback = &alc861_pcm_analog_playback;
13892         spec->stream_analog_capture = &alc861_pcm_analog_capture;
13893
13894         spec->stream_name_digital = "ALC861 Digital";
13895         spec->stream_digital_playback = &alc861_pcm_digital_playback;
13896         spec->stream_digital_capture = &alc861_pcm_digital_capture;
13897
13898         spec->vmaster_nid = 0x03;
13899
13900         codec->patch_ops = alc_patch_ops;
13901         if (board_config == ALC861_AUTO)
13902                 spec->init_hook = alc861_auto_init;
13903 #ifdef CONFIG_SND_HDA_POWER_SAVE
13904         if (!spec->loopback.amplist)
13905                 spec->loopback.amplist = alc861_loopbacks;
13906 #endif
13907         codec->proc_widget_hook = print_realtek_coef;
13908
13909         return 0;
13910 }
13911
13912 /*
13913  * ALC861-VD support
13914  *
13915  * Based on ALC882
13916  *
13917  * In addition, an independent DAC
13918  */
13919 #define ALC861VD_DIGOUT_NID     0x06
13920
13921 static hda_nid_t alc861vd_dac_nids[4] = {
13922         /* front, surr, clfe, side surr */
13923         0x02, 0x03, 0x04, 0x05
13924 };
13925
13926 /* dac_nids for ALC660vd are in a different order - according to
13927  * Realtek's driver.
13928  * This should probably tesult in a different mixer for 6stack models
13929  * of ALC660vd codecs, but for now there is only 3stack mixer
13930  * - and it is the same as in 861vd.
13931  * adc_nids in ALC660vd are (is) the same as in 861vd
13932  */
13933 static hda_nid_t alc660vd_dac_nids[3] = {
13934         /* front, rear, clfe, rear_surr */
13935         0x02, 0x04, 0x03
13936 };
13937
13938 static hda_nid_t alc861vd_adc_nids[1] = {
13939         /* ADC0 */
13940         0x09,
13941 };
13942
13943 static hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
13944
13945 /* input MUX */
13946 /* FIXME: should be a matrix-type input source selection */
13947 static struct hda_input_mux alc861vd_capture_source = {
13948         .num_items = 4,
13949         .items = {
13950                 { "Mic", 0x0 },
13951                 { "Front Mic", 0x1 },
13952                 { "Line", 0x2 },
13953                 { "CD", 0x4 },
13954         },
13955 };
13956
13957 static struct hda_input_mux alc861vd_dallas_capture_source = {
13958         .num_items = 2,
13959         .items = {
13960                 { "Ext Mic", 0x0 },
13961                 { "Int Mic", 0x1 },
13962         },
13963 };
13964
13965 static struct hda_input_mux alc861vd_hp_capture_source = {
13966         .num_items = 2,
13967         .items = {
13968                 { "Front Mic", 0x0 },
13969                 { "ATAPI Mic", 0x1 },
13970         },
13971 };
13972
13973 /*
13974  * 2ch mode
13975  */
13976 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
13977         { 2, NULL }
13978 };
13979
13980 /*
13981  * 6ch mode
13982  */
13983 static struct hda_verb alc861vd_6stack_ch6_init[] = {
13984         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13985         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13986         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13987         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13988         { } /* end */
13989 };
13990
13991 /*
13992  * 8ch mode
13993  */
13994 static struct hda_verb alc861vd_6stack_ch8_init[] = {
13995         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13996         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13997         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13998         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13999         { } /* end */
14000 };
14001
14002 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
14003         { 6, alc861vd_6stack_ch6_init },
14004         { 8, alc861vd_6stack_ch8_init },
14005 };
14006
14007 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
14008         {
14009                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
14010                 .name = "Channel Mode",
14011                 .info = alc_ch_mode_info,
14012                 .get = alc_ch_mode_get,
14013                 .put = alc_ch_mode_put,
14014         },
14015         { } /* end */
14016 };
14017
14018 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
14019  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
14020  */
14021 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
14022         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14023         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14024
14025         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14026         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
14027
14028         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
14029                                 HDA_OUTPUT),
14030         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
14031                                 HDA_OUTPUT),
14032         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
14033         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
14034
14035         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
14036         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
14037
14038         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14039
14040         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14041         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14042         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14043
14044         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14045         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14046         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14047
14048         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14049         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14050
14051         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14052         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14053
14054         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
14055         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
14056
14057         { } /* end */
14058 };
14059
14060 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
14061         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14062         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14063
14064         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14065
14066         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14067         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14068         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14069
14070         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14071         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14072         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14073
14074         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14075         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14076
14077         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14078         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14079
14080         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
14081         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
14082
14083         { } /* end */
14084 };
14085
14086 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
14087         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14088         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
14089         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14090
14091         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14092
14093         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14094         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14095         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14096
14097         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14098         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14099         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14100
14101         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14102         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14103
14104         { } /* end */
14105 };
14106
14107 /* Pin assignment: Speaker=0x14, HP = 0x15,
14108  *                 Ext Mic=0x18, Int Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
14109  */
14110 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
14111         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14112         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
14113         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14114         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14115         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
14116         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14117         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14118         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
14119         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14120         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14121         HDA_CODEC_VOLUME("PC Beep Volume", 0x0b, 0x05, HDA_INPUT),
14122         HDA_CODEC_MUTE("PC Beep Switch", 0x0b, 0x05, HDA_INPUT),
14123         { } /* end */
14124 };
14125
14126 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
14127  *                 Front Mic=0x18, ATAPI Mic = 0x19,
14128  */
14129 static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
14130         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14131         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14132         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14133         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14134         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14135         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14136         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14137         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14138
14139         { } /* end */
14140 };
14141
14142 /*
14143  * generic initialization of ADC, input mixers and output mixers
14144  */
14145 static struct hda_verb alc861vd_volume_init_verbs[] = {
14146         /*
14147          * Unmute ADC0 and set the default input to mic-in
14148          */
14149         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14150         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14151
14152         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
14153          * the analog-loopback mixer widget
14154          */
14155         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
14156         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14157         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14158         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14159         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14160         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14161
14162         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
14163         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14164         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14165         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14166         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
14167
14168         /*
14169          * Set up output mixers (0x02 - 0x05)
14170          */
14171         /* set vol=0 to output mixers */
14172         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14173         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14174         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14175         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14176
14177         /* set up input amps for analog loopback */
14178         /* Amp Indices: DAC = 0, mixer = 1 */
14179         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14180         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14181         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14182         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14183         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14184         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14185         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14186         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14187
14188         { }
14189 };
14190
14191 /*
14192  * 3-stack pin configuration:
14193  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
14194  */
14195 static struct hda_verb alc861vd_3stack_init_verbs[] = {
14196         /*
14197          * Set pin mode and muting
14198          */
14199         /* set front pin widgets 0x14 for output */
14200         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14201         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14202         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
14203
14204         /* Mic (rear) pin: input vref at 80% */
14205         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14206         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14207         /* Front Mic pin: input vref at 80% */
14208         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14209         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14210         /* Line In pin: input */
14211         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14212         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14213         /* Line-2 In: Headphone output (output 0 - 0x0c) */
14214         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14215         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14216         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
14217         /* CD pin widget for input */
14218         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14219
14220         { }
14221 };
14222
14223 /*
14224  * 6-stack pin configuration:
14225  */
14226 static struct hda_verb alc861vd_6stack_init_verbs[] = {
14227         /*
14228          * Set pin mode and muting
14229          */
14230         /* set front pin widgets 0x14 for output */
14231         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14232         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14233         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
14234
14235         /* Rear Pin: output 1 (0x0d) */
14236         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14237         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14238         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
14239         /* CLFE Pin: output 2 (0x0e) */
14240         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14241         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14242         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
14243         /* Side Pin: output 3 (0x0f) */
14244         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14245         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14246         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
14247
14248         /* Mic (rear) pin: input vref at 80% */
14249         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14250         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14251         /* Front Mic pin: input vref at 80% */
14252         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14253         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14254         /* Line In pin: input */
14255         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14256         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14257         /* Line-2 In: Headphone output (output 0 - 0x0c) */
14258         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14259         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14260         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
14261         /* CD pin widget for input */
14262         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14263
14264         { }
14265 };
14266
14267 static struct hda_verb alc861vd_eapd_verbs[] = {
14268         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
14269         { }
14270 };
14271
14272 static struct hda_verb alc660vd_eapd_verbs[] = {
14273         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
14274         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
14275         { }
14276 };
14277
14278 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
14279         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14280         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14281         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
14282         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14283         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14284         {}
14285 };
14286
14287 /* toggle speaker-output according to the hp-jack state */
14288 static void alc861vd_lenovo_hp_automute(struct hda_codec *codec)
14289 {
14290         unsigned int present;
14291         unsigned char bits;
14292
14293         present = snd_hda_codec_read(codec, 0x1b, 0,
14294                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14295         bits = present ? HDA_AMP_MUTE : 0;
14296         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14297                                  HDA_AMP_MUTE, bits);
14298 }
14299
14300 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
14301 {
14302         unsigned int present;
14303         unsigned char bits;
14304
14305         present = snd_hda_codec_read(codec, 0x18, 0,
14306                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14307         bits = present ? HDA_AMP_MUTE : 0;
14308         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
14309                                  HDA_AMP_MUTE, bits);
14310 }
14311
14312 static void alc861vd_lenovo_automute(struct hda_codec *codec)
14313 {
14314         alc861vd_lenovo_hp_automute(codec);
14315         alc861vd_lenovo_mic_automute(codec);
14316 }
14317
14318 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
14319                                         unsigned int res)
14320 {
14321         switch (res >> 26) {
14322         case ALC880_HP_EVENT:
14323                 alc861vd_lenovo_hp_automute(codec);
14324                 break;
14325         case ALC880_MIC_EVENT:
14326                 alc861vd_lenovo_mic_automute(codec);
14327                 break;
14328         }
14329 }
14330
14331 static struct hda_verb alc861vd_dallas_verbs[] = {
14332         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14333         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14334         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14335         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14336
14337         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14338         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14339         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14340         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14341         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14342         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14343         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14344         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14345
14346         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14347         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14348         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14349         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14350         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14351         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14352         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14353         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14354
14355         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
14356         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14357         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
14358         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14359         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14360         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14361         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14362         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14363
14364         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14365         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14366         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14367         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14368
14369         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14370         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14371         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14372
14373         { } /* end */
14374 };
14375
14376 /* toggle speaker-output according to the hp-jack state */
14377 static void alc861vd_dallas_automute(struct hda_codec *codec)
14378 {
14379         unsigned int present;
14380
14381         present = snd_hda_codec_read(codec, 0x15, 0,
14382                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14383         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14384                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
14385 }
14386
14387 static void alc861vd_dallas_unsol_event(struct hda_codec *codec, unsigned int res)
14388 {
14389         if ((res >> 26) == ALC880_HP_EVENT)
14390                 alc861vd_dallas_automute(codec);
14391 }
14392
14393 #ifdef CONFIG_SND_HDA_POWER_SAVE
14394 #define alc861vd_loopbacks      alc880_loopbacks
14395 #endif
14396
14397 /* pcm configuration: identiacal with ALC880 */
14398 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
14399 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
14400 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
14401 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
14402
14403 /*
14404  * configuration and preset
14405  */
14406 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
14407         [ALC660VD_3ST]          = "3stack-660",
14408         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
14409         [ALC660VD_ASUS_V1S]     = "asus-v1s",
14410         [ALC861VD_3ST]          = "3stack",
14411         [ALC861VD_3ST_DIG]      = "3stack-digout",
14412         [ALC861VD_6ST_DIG]      = "6stack-digout",
14413         [ALC861VD_LENOVO]       = "lenovo",
14414         [ALC861VD_DALLAS]       = "dallas",
14415         [ALC861VD_HP]           = "hp",
14416         [ALC861VD_AUTO]         = "auto",
14417 };
14418
14419 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
14420         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
14421         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
14422         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
14423         SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),
14424         SND_PCI_QUIRK(0x1043, 0x1633, "Asus V1Sn", ALC660VD_ASUS_V1S),
14425         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
14426         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
14427         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
14428         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
14429         SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS),
14430         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
14431         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
14432         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
14433         SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo", ALC861VD_LENOVO),
14434         SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo 3000 C200", ALC861VD_LENOVO),
14435         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 N200", ALC861VD_LENOVO),
14436         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
14437         {}
14438 };
14439
14440 static struct alc_config_preset alc861vd_presets[] = {
14441         [ALC660VD_3ST] = {
14442                 .mixers = { alc861vd_3st_mixer },
14443                 .init_verbs = { alc861vd_volume_init_verbs,
14444                                  alc861vd_3stack_init_verbs },
14445                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14446                 .dac_nids = alc660vd_dac_nids,
14447                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14448                 .channel_mode = alc861vd_3stack_2ch_modes,
14449                 .input_mux = &alc861vd_capture_source,
14450         },
14451         [ALC660VD_3ST_DIG] = {
14452                 .mixers = { alc861vd_3st_mixer },
14453                 .init_verbs = { alc861vd_volume_init_verbs,
14454                                  alc861vd_3stack_init_verbs },
14455                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14456                 .dac_nids = alc660vd_dac_nids,
14457                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14458                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14459                 .channel_mode = alc861vd_3stack_2ch_modes,
14460                 .input_mux = &alc861vd_capture_source,
14461         },
14462         [ALC861VD_3ST] = {
14463                 .mixers = { alc861vd_3st_mixer },
14464                 .init_verbs = { alc861vd_volume_init_verbs,
14465                                  alc861vd_3stack_init_verbs },
14466                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14467                 .dac_nids = alc861vd_dac_nids,
14468                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14469                 .channel_mode = alc861vd_3stack_2ch_modes,
14470                 .input_mux = &alc861vd_capture_source,
14471         },
14472         [ALC861VD_3ST_DIG] = {
14473                 .mixers = { alc861vd_3st_mixer },
14474                 .init_verbs = { alc861vd_volume_init_verbs,
14475                                  alc861vd_3stack_init_verbs },
14476                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14477                 .dac_nids = alc861vd_dac_nids,
14478                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14479                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14480                 .channel_mode = alc861vd_3stack_2ch_modes,
14481                 .input_mux = &alc861vd_capture_source,
14482         },
14483         [ALC861VD_6ST_DIG] = {
14484                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
14485                 .init_verbs = { alc861vd_volume_init_verbs,
14486                                 alc861vd_6stack_init_verbs },
14487                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14488                 .dac_nids = alc861vd_dac_nids,
14489                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14490                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
14491                 .channel_mode = alc861vd_6stack_modes,
14492                 .input_mux = &alc861vd_capture_source,
14493         },
14494         [ALC861VD_LENOVO] = {
14495                 .mixers = { alc861vd_lenovo_mixer },
14496                 .init_verbs = { alc861vd_volume_init_verbs,
14497                                 alc861vd_3stack_init_verbs,
14498                                 alc861vd_eapd_verbs,
14499                                 alc861vd_lenovo_unsol_verbs },
14500                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14501                 .dac_nids = alc660vd_dac_nids,
14502                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14503                 .channel_mode = alc861vd_3stack_2ch_modes,
14504                 .input_mux = &alc861vd_capture_source,
14505                 .unsol_event = alc861vd_lenovo_unsol_event,
14506                 .init_hook = alc861vd_lenovo_automute,
14507         },
14508         [ALC861VD_DALLAS] = {
14509                 .mixers = { alc861vd_dallas_mixer },
14510                 .init_verbs = { alc861vd_dallas_verbs },
14511                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14512                 .dac_nids = alc861vd_dac_nids,
14513                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14514                 .channel_mode = alc861vd_3stack_2ch_modes,
14515                 .input_mux = &alc861vd_dallas_capture_source,
14516                 .unsol_event = alc861vd_dallas_unsol_event,
14517                 .init_hook = alc861vd_dallas_automute,
14518         },
14519         [ALC861VD_HP] = {
14520                 .mixers = { alc861vd_hp_mixer },
14521                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
14522                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14523                 .dac_nids = alc861vd_dac_nids,
14524                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14525                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14526                 .channel_mode = alc861vd_3stack_2ch_modes,
14527                 .input_mux = &alc861vd_hp_capture_source,
14528                 .unsol_event = alc861vd_dallas_unsol_event,
14529                 .init_hook = alc861vd_dallas_automute,
14530         },
14531         [ALC660VD_ASUS_V1S] = {
14532                 .mixers = { alc861vd_lenovo_mixer },
14533                 .init_verbs = { alc861vd_volume_init_verbs,
14534                                 alc861vd_3stack_init_verbs,
14535                                 alc861vd_eapd_verbs,
14536                                 alc861vd_lenovo_unsol_verbs },
14537                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14538                 .dac_nids = alc660vd_dac_nids,
14539                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14540                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14541                 .channel_mode = alc861vd_3stack_2ch_modes,
14542                 .input_mux = &alc861vd_capture_source,
14543                 .unsol_event = alc861vd_lenovo_unsol_event,
14544                 .init_hook = alc861vd_lenovo_automute,
14545         },
14546 };
14547
14548 /*
14549  * BIOS auto configuration
14550  */
14551 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
14552                                 hda_nid_t nid, int pin_type, int dac_idx)
14553 {
14554         alc_set_pin_output(codec, nid, pin_type);
14555 }
14556
14557 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
14558 {
14559         struct alc_spec *spec = codec->spec;
14560         int i;
14561
14562         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
14563         for (i = 0; i <= HDA_SIDE; i++) {
14564                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
14565                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
14566                 if (nid)
14567                         alc861vd_auto_set_output_and_unmute(codec, nid,
14568                                                             pin_type, i);
14569         }
14570 }
14571
14572
14573 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
14574 {
14575         struct alc_spec *spec = codec->spec;
14576         hda_nid_t pin;
14577
14578         pin = spec->autocfg.hp_pins[0];
14579         if (pin) /* connect to front and  use dac 0 */
14580                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
14581         pin = spec->autocfg.speaker_pins[0];
14582         if (pin)
14583                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
14584 }
14585
14586 #define alc861vd_is_input_pin(nid)      alc880_is_input_pin(nid)
14587 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
14588
14589 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
14590 {
14591         struct alc_spec *spec = codec->spec;
14592         int i;
14593
14594         for (i = 0; i < AUTO_PIN_LAST; i++) {
14595                 hda_nid_t nid = spec->autocfg.input_pins[i];
14596                 if (alc861vd_is_input_pin(nid)) {
14597                         snd_hda_codec_write(codec, nid, 0,
14598                                         AC_VERB_SET_PIN_WIDGET_CONTROL,
14599                                         i <= AUTO_PIN_FRONT_MIC ?
14600                                                         PIN_VREF80 : PIN_IN);
14601                         if (nid != ALC861VD_PIN_CD_NID)
14602                                 snd_hda_codec_write(codec, nid, 0,
14603                                                 AC_VERB_SET_AMP_GAIN_MUTE,
14604                                                 AMP_OUT_MUTE);
14605                 }
14606         }
14607 }
14608
14609 #define alc861vd_auto_init_input_src    alc882_auto_init_input_src
14610
14611 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
14612 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
14613
14614 /* add playback controls from the parsed DAC table */
14615 /* Based on ALC880 version. But ALC861VD has separate,
14616  * different NIDs for mute/unmute switch and volume control */
14617 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
14618                                              const struct auto_pin_cfg *cfg)
14619 {
14620         char name[32];
14621         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
14622         hda_nid_t nid_v, nid_s;
14623         int i, err;
14624
14625         for (i = 0; i < cfg->line_outs; i++) {
14626                 if (!spec->multiout.dac_nids[i])
14627                         continue;
14628                 nid_v = alc861vd_idx_to_mixer_vol(
14629                                 alc880_dac_to_idx(
14630                                         spec->multiout.dac_nids[i]));
14631                 nid_s = alc861vd_idx_to_mixer_switch(
14632                                 alc880_dac_to_idx(
14633                                         spec->multiout.dac_nids[i]));
14634
14635                 if (i == 2) {
14636                         /* Center/LFE */
14637                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14638                                           "Center Playback Volume",
14639                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
14640                                                               HDA_OUTPUT));
14641                         if (err < 0)
14642                                 return err;
14643                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14644                                           "LFE Playback Volume",
14645                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
14646                                                               HDA_OUTPUT));
14647                         if (err < 0)
14648                                 return err;
14649                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14650                                           "Center Playback Switch",
14651                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
14652                                                               HDA_INPUT));
14653                         if (err < 0)
14654                                 return err;
14655                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14656                                           "LFE Playback Switch",
14657                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
14658                                                               HDA_INPUT));
14659                         if (err < 0)
14660                                 return err;
14661                 } else {
14662                         sprintf(name, "%s Playback Volume", chname[i]);
14663                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14664                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
14665                                                               HDA_OUTPUT));
14666                         if (err < 0)
14667                                 return err;
14668                         sprintf(name, "%s Playback Switch", chname[i]);
14669                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14670                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
14671                                                               HDA_INPUT));
14672                         if (err < 0)
14673                                 return err;
14674                 }
14675         }
14676         return 0;
14677 }
14678
14679 /* add playback controls for speaker and HP outputs */
14680 /* Based on ALC880 version. But ALC861VD has separate,
14681  * different NIDs for mute/unmute switch and volume control */
14682 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
14683                                         hda_nid_t pin, const char *pfx)
14684 {
14685         hda_nid_t nid_v, nid_s;
14686         int err;
14687         char name[32];
14688
14689         if (!pin)
14690                 return 0;
14691
14692         if (alc880_is_fixed_pin(pin)) {
14693                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
14694                 /* specify the DAC as the extra output */
14695                 if (!spec->multiout.hp_nid)
14696                         spec->multiout.hp_nid = nid_v;
14697                 else
14698                         spec->multiout.extra_out_nid[0] = nid_v;
14699                 /* control HP volume/switch on the output mixer amp */
14700                 nid_v = alc861vd_idx_to_mixer_vol(
14701                                 alc880_fixed_pin_idx(pin));
14702                 nid_s = alc861vd_idx_to_mixer_switch(
14703                                 alc880_fixed_pin_idx(pin));
14704
14705                 sprintf(name, "%s Playback Volume", pfx);
14706                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14707                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
14708                 if (err < 0)
14709                         return err;
14710                 sprintf(name, "%s Playback Switch", pfx);
14711                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14712                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
14713                 if (err < 0)
14714                         return err;
14715         } else if (alc880_is_multi_pin(pin)) {
14716                 /* set manual connection */
14717                 /* we have only a switch on HP-out PIN */
14718                 sprintf(name, "%s Playback Switch", pfx);
14719                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
14720                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
14721                 if (err < 0)
14722                         return err;
14723         }
14724         return 0;
14725 }
14726
14727 /* parse the BIOS configuration and set up the alc_spec
14728  * return 1 if successful, 0 if the proper config is not found,
14729  * or a negative error code
14730  * Based on ALC880 version - had to change it to override
14731  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
14732 static int alc861vd_parse_auto_config(struct hda_codec *codec)
14733 {
14734         struct alc_spec *spec = codec->spec;
14735         int err;
14736         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
14737
14738         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
14739                                            alc861vd_ignore);
14740         if (err < 0)
14741                 return err;
14742         if (!spec->autocfg.line_outs)
14743                 return 0; /* can't find valid BIOS pin config */
14744
14745         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
14746         if (err < 0)
14747                 return err;
14748         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
14749         if (err < 0)
14750                 return err;
14751         err = alc861vd_auto_create_extra_out(spec,
14752                                              spec->autocfg.speaker_pins[0],
14753                                              "Speaker");
14754         if (err < 0)
14755                 return err;
14756         err = alc861vd_auto_create_extra_out(spec,
14757                                              spec->autocfg.hp_pins[0],
14758                                              "Headphone");
14759         if (err < 0)
14760                 return err;
14761         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
14762         if (err < 0)
14763                 return err;
14764
14765         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
14766
14767         if (spec->autocfg.dig_out_pin)
14768                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
14769
14770         if (spec->kctls.list)
14771                 add_mixer(spec, spec->kctls.list);
14772
14773         add_verb(spec, alc861vd_volume_init_verbs);
14774
14775         spec->num_mux_defs = 1;
14776         spec->input_mux = &spec->private_imux[0];
14777
14778         err = alc_auto_add_mic_boost(codec);
14779         if (err < 0)
14780                 return err;
14781
14782         store_pin_configs(codec);
14783         return 1;
14784 }
14785
14786 /* additional initialization for auto-configuration model */
14787 static void alc861vd_auto_init(struct hda_codec *codec)
14788 {
14789         struct alc_spec *spec = codec->spec;
14790         alc861vd_auto_init_multi_out(codec);
14791         alc861vd_auto_init_hp_out(codec);
14792         alc861vd_auto_init_analog_input(codec);
14793         alc861vd_auto_init_input_src(codec);
14794         if (spec->unsol_event)
14795                 alc_inithook(codec);
14796 }
14797
14798 static int patch_alc861vd(struct hda_codec *codec)
14799 {
14800         struct alc_spec *spec;
14801         int err, board_config;
14802
14803         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
14804         if (spec == NULL)
14805                 return -ENOMEM;
14806
14807         codec->spec = spec;
14808
14809         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
14810                                                   alc861vd_models,
14811                                                   alc861vd_cfg_tbl);
14812
14813         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
14814                 printk(KERN_INFO "hda_codec: Unknown model for ALC660VD/"
14815                         "ALC861VD, trying auto-probe from BIOS...\n");
14816                 board_config = ALC861VD_AUTO;
14817         }
14818
14819         if (board_config == ALC861VD_AUTO) {
14820                 /* automatic parse from the BIOS config */
14821                 err = alc861vd_parse_auto_config(codec);
14822                 if (err < 0) {
14823                         alc_free(codec);
14824                         return err;
14825                 } else if (!err) {
14826                         printk(KERN_INFO
14827                                "hda_codec: Cannot set up configuration "
14828                                "from BIOS.  Using base mode...\n");
14829                         board_config = ALC861VD_3ST;
14830                 }
14831         }
14832
14833         if (board_config != ALC861VD_AUTO)
14834                 setup_preset(spec, &alc861vd_presets[board_config]);
14835
14836         if (codec->vendor_id == 0x10ec0660) {
14837                 spec->stream_name_analog = "ALC660-VD Analog";
14838                 spec->stream_name_digital = "ALC660-VD Digital";
14839                 /* always turn on EAPD */
14840                 add_verb(spec, alc660vd_eapd_verbs);
14841         } else {
14842                 spec->stream_name_analog = "ALC861VD Analog";
14843                 spec->stream_name_digital = "ALC861VD Digital";
14844         }
14845
14846         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
14847         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
14848
14849         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
14850         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
14851
14852         spec->adc_nids = alc861vd_adc_nids;
14853         spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
14854         spec->capsrc_nids = alc861vd_capsrc_nids;
14855         spec->capture_style = CAPT_MIX;
14856
14857         set_capture_mixer(spec);
14858
14859         spec->vmaster_nid = 0x02;
14860
14861         codec->patch_ops = alc_patch_ops;
14862
14863         if (board_config == ALC861VD_AUTO)
14864                 spec->init_hook = alc861vd_auto_init;
14865 #ifdef CONFIG_SND_HDA_POWER_SAVE
14866         if (!spec->loopback.amplist)
14867                 spec->loopback.amplist = alc861vd_loopbacks;
14868 #endif
14869         codec->proc_widget_hook = print_realtek_coef;
14870
14871         return 0;
14872 }
14873
14874 /*
14875  * ALC662 support
14876  *
14877  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
14878  * configuration.  Each pin widget can choose any input DACs and a mixer.
14879  * Each ADC is connected from a mixer of all inputs.  This makes possible
14880  * 6-channel independent captures.
14881  *
14882  * In addition, an independent DAC for the multi-playback (not used in this
14883  * driver yet).
14884  */
14885 #define ALC662_DIGOUT_NID       0x06
14886 #define ALC662_DIGIN_NID        0x0a
14887
14888 static hda_nid_t alc662_dac_nids[4] = {
14889         /* front, rear, clfe, rear_surr */
14890         0x02, 0x03, 0x04
14891 };
14892
14893 static hda_nid_t alc662_adc_nids[1] = {
14894         /* ADC1-2 */
14895         0x09,
14896 };
14897
14898 static hda_nid_t alc662_capsrc_nids[1] = { 0x22 };
14899
14900 /* input MUX */
14901 /* FIXME: should be a matrix-type input source selection */
14902 static struct hda_input_mux alc662_capture_source = {
14903         .num_items = 4,
14904         .items = {
14905                 { "Mic", 0x0 },
14906                 { "Front Mic", 0x1 },
14907                 { "Line", 0x2 },
14908                 { "CD", 0x4 },
14909         },
14910 };
14911
14912 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
14913         .num_items = 2,
14914         .items = {
14915                 { "Mic", 0x1 },
14916                 { "Line", 0x2 },
14917         },
14918 };
14919
14920 static struct hda_input_mux alc662_eeepc_capture_source = {
14921         .num_items = 2,
14922         .items = {
14923                 { "i-Mic", 0x1 },
14924                 { "e-Mic", 0x0 },
14925         },
14926 };
14927
14928 static struct hda_input_mux alc663_capture_source = {
14929         .num_items = 3,
14930         .items = {
14931                 { "Mic", 0x0 },
14932                 { "Front Mic", 0x1 },
14933                 { "Line", 0x2 },
14934         },
14935 };
14936
14937 static struct hda_input_mux alc663_m51va_capture_source = {
14938         .num_items = 2,
14939         .items = {
14940                 { "Ext-Mic", 0x0 },
14941                 { "D-Mic", 0x9 },
14942         },
14943 };
14944
14945 /*
14946  * 2ch mode
14947  */
14948 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
14949         { 2, NULL }
14950 };
14951
14952 /*
14953  * 2ch mode
14954  */
14955 static struct hda_verb alc662_3ST_ch2_init[] = {
14956         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
14957         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
14958         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
14959         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
14960         { } /* end */
14961 };
14962
14963 /*
14964  * 6ch mode
14965  */
14966 static struct hda_verb alc662_3ST_ch6_init[] = {
14967         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14968         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
14969         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
14970         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14971         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
14972         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
14973         { } /* end */
14974 };
14975
14976 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
14977         { 2, alc662_3ST_ch2_init },
14978         { 6, alc662_3ST_ch6_init },
14979 };
14980
14981 /*
14982  * 2ch mode
14983  */
14984 static struct hda_verb alc662_sixstack_ch6_init[] = {
14985         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
14986         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
14987         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14988         { } /* end */
14989 };
14990
14991 /*
14992  * 6ch mode
14993  */
14994 static struct hda_verb alc662_sixstack_ch8_init[] = {
14995         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14996         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14997         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14998         { } /* end */
14999 };
15000
15001 static struct hda_channel_mode alc662_5stack_modes[2] = {
15002         { 2, alc662_sixstack_ch6_init },
15003         { 6, alc662_sixstack_ch8_init },
15004 };
15005
15006 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
15007  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
15008  */
15009
15010 static struct snd_kcontrol_new alc662_base_mixer[] = {
15011         /* output mixer control */
15012         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
15013         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15014         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
15015         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
15016         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15017         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15018         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
15019         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
15020         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15021
15022         /*Input mixer control */
15023         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
15024         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
15025         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
15026         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
15027         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
15028         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
15029         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
15030         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
15031         { } /* end */
15032 };
15033
15034 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
15035         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15036         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15037         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15038         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
15039         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
15040         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15041         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15042         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15043         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15044         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15045         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15046         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
15047         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
15048         { } /* end */
15049 };
15050
15051 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
15052         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15053         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15054         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15055         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
15056         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15057         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15058         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
15059         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
15060         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15061         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
15062         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
15063         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15064         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15065         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15066         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15067         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15068         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15069         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
15070         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
15071         { } /* end */
15072 };
15073
15074 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
15075         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15076         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
15077         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15078         HDA_BIND_MUTE("Speaker Playback Switch", 0x03, 2, HDA_INPUT),
15079         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15080         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15081         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15082         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15083         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15084         { } /* end */
15085 };
15086
15087 static struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
15088         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15089
15090         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15091         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15092
15093         HDA_CODEC_VOLUME("e-Mic Boost", 0x18, 0, HDA_INPUT),
15094         HDA_CODEC_VOLUME("e-Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15095         HDA_CODEC_MUTE("e-Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15096
15097         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
15098         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15099         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15100         { } /* end */
15101 };
15102
15103 static struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
15104         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15105         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15106         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15107         HDA_BIND_MUTE("Surround Playback Switch", 0x03, 2, HDA_INPUT),
15108         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15109         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15110         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
15111         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
15112         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15113         HDA_BIND_MUTE("MuteCtrl Playback Switch", 0x0c, 2, HDA_INPUT),
15114         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15115         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15116         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15117         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15118         { } /* end */
15119 };
15120
15121 static struct hda_bind_ctls alc663_asus_bind_master_vol = {
15122         .ops = &snd_hda_bind_vol,
15123         .values = {
15124                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
15125                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
15126                 0
15127         },
15128 };
15129
15130 static struct hda_bind_ctls alc663_asus_one_bind_switch = {
15131         .ops = &snd_hda_bind_sw,
15132         .values = {
15133                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15134                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15135                 0
15136         },
15137 };
15138
15139 static struct snd_kcontrol_new alc663_m51va_mixer[] = {
15140         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15141         HDA_BIND_SW("Master Playback Switch", &alc663_asus_one_bind_switch),
15142         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15143         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15144         { } /* end */
15145 };
15146
15147 static struct hda_bind_ctls alc663_asus_tree_bind_switch = {
15148         .ops = &snd_hda_bind_sw,
15149         .values = {
15150                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15151                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15152                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15153                 0
15154         },
15155 };
15156
15157 static struct snd_kcontrol_new alc663_two_hp_m1_mixer[] = {
15158         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15159         HDA_BIND_SW("Master Playback Switch", &alc663_asus_tree_bind_switch),
15160         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15161         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15162         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15163         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15164
15165         { } /* end */
15166 };
15167
15168 static struct hda_bind_ctls alc663_asus_four_bind_switch = {
15169         .ops = &snd_hda_bind_sw,
15170         .values = {
15171                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15172                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15173                 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
15174                 0
15175         },
15176 };
15177
15178 static struct snd_kcontrol_new alc663_two_hp_m2_mixer[] = {
15179         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15180         HDA_BIND_SW("Master Playback Switch", &alc663_asus_four_bind_switch),
15181         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15182         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15183         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15184         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15185         { } /* end */
15186 };
15187
15188 static struct snd_kcontrol_new alc662_1bjd_mixer[] = {
15189         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15190         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15191         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15192         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15193         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15194         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15195         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15196         { } /* end */
15197 };
15198
15199 static struct hda_bind_ctls alc663_asus_two_bind_master_vol = {
15200         .ops = &snd_hda_bind_vol,
15201         .values = {
15202                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
15203                 HDA_COMPOSE_AMP_VAL(0x04, 3, 0, HDA_OUTPUT),
15204                 0
15205         },
15206 };
15207
15208 static struct hda_bind_ctls alc663_asus_two_bind_switch = {
15209         .ops = &snd_hda_bind_sw,
15210         .values = {
15211                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15212                 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT),
15213                 0
15214         },
15215 };
15216
15217 static struct snd_kcontrol_new alc663_asus_21jd_clfe_mixer[] = {
15218         HDA_BIND_VOL("Master Playback Volume",
15219                                 &alc663_asus_two_bind_master_vol),
15220         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
15221         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15222         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
15223         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15224         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15225         { } /* end */
15226 };
15227
15228 static struct snd_kcontrol_new alc663_asus_15jd_clfe_mixer[] = {
15229         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15230         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
15231         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15232         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
15233         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15234         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15235         { } /* end */
15236 };
15237
15238 static struct snd_kcontrol_new alc663_g71v_mixer[] = {
15239         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15240         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15241         HDA_CODEC_VOLUME("Front Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15242         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
15243         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
15244
15245         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15246         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15247         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15248         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15249         { } /* end */
15250 };
15251
15252 static struct snd_kcontrol_new alc663_g50v_mixer[] = {
15253         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15254         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15255         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
15256
15257         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15258         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15259         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15260         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15261         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15262         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15263         { } /* end */
15264 };
15265
15266 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
15267         {
15268                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
15269                 .name = "Channel Mode",
15270                 .info = alc_ch_mode_info,
15271                 .get = alc_ch_mode_get,
15272                 .put = alc_ch_mode_put,
15273         },
15274         { } /* end */
15275 };
15276
15277 static struct hda_verb alc662_init_verbs[] = {
15278         /* ADC: mute amp left and right */
15279         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15280         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
15281         /* Front mixer: unmute input/output amp left and right (volume = 0) */
15282
15283         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15284         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15285         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
15286         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
15287         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
15288
15289         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15290         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15291         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15292         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15293         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15294         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15295
15296         /* Front Pin: output 0 (0x0c) */
15297         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15298         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15299
15300         /* Rear Pin: output 1 (0x0d) */
15301         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15302         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15303
15304         /* CLFE Pin: output 2 (0x0e) */
15305         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15306         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15307
15308         /* Mic (rear) pin: input vref at 80% */
15309         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
15310         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15311         /* Front Mic pin: input vref at 80% */
15312         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
15313         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15314         /* Line In pin: input */
15315         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15316         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15317         /* Line-2 In: Headphone output (output 0 - 0x0c) */
15318         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15319         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15320         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
15321         /* CD pin widget for input */
15322         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15323
15324         /* FIXME: use matrix-type input source selection */
15325         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
15326         /* Input mixer */
15327         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15328         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15329         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15330         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
15331
15332         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15333         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15334         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15335         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
15336
15337         /* always trun on EAPD */
15338         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
15339         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
15340
15341         { }
15342 };
15343
15344 static struct hda_verb alc662_sue_init_verbs[] = {
15345         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
15346         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
15347         {}
15348 };
15349
15350 static struct hda_verb alc662_eeepc_sue_init_verbs[] = {
15351         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15352         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15353         {}
15354 };
15355
15356 /* Set Unsolicited Event*/
15357 static struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
15358         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15359         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15360         {}
15361 };
15362
15363 /*
15364  * generic initialization of ADC, input mixers and output mixers
15365  */
15366 static struct hda_verb alc662_auto_init_verbs[] = {
15367         /*
15368          * Unmute ADC and set the default input to mic-in
15369          */
15370         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
15371         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15372
15373         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
15374          * mixer widget
15375          * Note: PASD motherboards uses the Line In 2 as the input for front
15376          * panel mic (mic 2)
15377          */
15378         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
15379         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15380         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15381         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
15382         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
15383         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
15384
15385         /*
15386          * Set up output mixers (0x0c - 0x0f)
15387          */
15388         /* set vol=0 to output mixers */
15389         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15390         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15391         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15392
15393         /* set up input amps for analog loopback */
15394         /* Amp Indices: DAC = 0, mixer = 1 */
15395         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15396         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15397         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15398         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15399         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15400         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15401
15402
15403         /* FIXME: use matrix-type input source selection */
15404         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
15405         /* Input mixer */
15406         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15407         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15408         { }
15409 };
15410
15411 /* additional verbs for ALC663 */
15412 static struct hda_verb alc663_auto_init_verbs[] = {
15413         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15414         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15415         { }
15416 };
15417
15418 static struct hda_verb alc663_m51va_init_verbs[] = {
15419         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15420         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15421         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15422         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15423         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15424         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15425         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
15426         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15427         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15428         {}
15429 };
15430
15431 static struct hda_verb alc663_21jd_amic_init_verbs[] = {
15432         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15433         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15434         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15435         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15436         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15437         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15438         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15439         {}
15440 };
15441
15442 static struct hda_verb alc662_1bjd_amic_init_verbs[] = {
15443         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15444         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15445         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15446         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15447         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15448         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15449         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15450         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15451         {}
15452 };
15453
15454 static struct hda_verb alc663_15jd_amic_init_verbs[] = {
15455         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15456         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15457         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15458         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15459         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15460         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15461         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15462         {}
15463 };
15464
15465 static struct hda_verb alc663_two_hp_amic_m1_init_verbs[] = {
15466         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15467         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15468         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15469         {0x21, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
15470         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15471         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15472         {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
15473         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15474         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15475         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15476         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15477         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15478         {}
15479 };
15480
15481 static struct hda_verb alc663_two_hp_amic_m2_init_verbs[] = {
15482         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15483         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15484         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15485         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15486         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15487         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15488         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15489         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15490         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15491         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15492         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15493         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15494         {}
15495 };
15496
15497 static struct hda_verb alc663_g71v_init_verbs[] = {
15498         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15499         /* {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
15500         /* {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, */ /* Headphone */
15501
15502         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15503         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15504         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15505
15506         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
15507         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_MIC_EVENT},
15508         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
15509         {}
15510 };
15511
15512 static struct hda_verb alc663_g50v_init_verbs[] = {
15513         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15514         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15515         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15516
15517         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15518         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15519         {}
15520 };
15521
15522 static struct hda_verb alc662_ecs_init_verbs[] = {
15523         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
15524         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15525         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15526         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15527         {}
15528 };
15529
15530 static struct snd_kcontrol_new alc662_auto_capture_mixer[] = {
15531         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
15532         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
15533         { } /* end */
15534 };
15535
15536 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
15537 {
15538         unsigned int present;
15539         unsigned char bits;
15540
15541         present = snd_hda_codec_read(codec, 0x14, 0,
15542                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15543         bits = present ? HDA_AMP_MUTE : 0;
15544         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15545                                  HDA_AMP_MUTE, bits);
15546 }
15547
15548 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
15549 {
15550         unsigned int present;
15551         unsigned char bits;
15552
15553         present = snd_hda_codec_read(codec, 0x1b, 0,
15554                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15555         bits = present ? HDA_AMP_MUTE : 0;
15556         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15557                                  HDA_AMP_MUTE, bits);
15558         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15559                                  HDA_AMP_MUTE, bits);
15560 }
15561
15562 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
15563                                            unsigned int res)
15564 {
15565         if ((res >> 26) == ALC880_HP_EVENT)
15566                 alc662_lenovo_101e_all_automute(codec);
15567         if ((res >> 26) == ALC880_FRONT_EVENT)
15568                 alc662_lenovo_101e_ispeaker_automute(codec);
15569 }
15570
15571 static void alc662_eeepc_mic_automute(struct hda_codec *codec)
15572 {
15573         unsigned int present;
15574
15575         present = snd_hda_codec_read(codec, 0x18, 0,
15576                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15577         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15578                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15579         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15580                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15581         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15582                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
15583         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15584                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
15585 }
15586
15587 /* unsolicited event for HP jack sensing */
15588 static void alc662_eeepc_unsol_event(struct hda_codec *codec,
15589                                      unsigned int res)
15590 {
15591         if ((res >> 26) == ALC880_HP_EVENT)
15592                 alc262_hippo1_automute( codec );
15593
15594         if ((res >> 26) == ALC880_MIC_EVENT)
15595                 alc662_eeepc_mic_automute(codec);
15596 }
15597
15598 static void alc662_eeepc_inithook(struct hda_codec *codec)
15599 {
15600         alc262_hippo1_automute( codec );
15601         alc662_eeepc_mic_automute(codec);
15602 }
15603
15604 static void alc662_eeepc_ep20_automute(struct hda_codec *codec)
15605 {
15606         unsigned int mute;
15607         unsigned int present;
15608
15609         snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
15610         present = snd_hda_codec_read(codec, 0x14, 0,
15611                                      AC_VERB_GET_PIN_SENSE, 0);
15612         present = (present & 0x80000000) != 0;
15613         if (present) {
15614                 /* mute internal speaker */
15615                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
15616                                         HDA_AMP_MUTE, HDA_AMP_MUTE);
15617         } else {
15618                 /* unmute internal speaker if necessary */
15619                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
15620                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
15621                                         HDA_AMP_MUTE, mute);
15622         }
15623 }
15624
15625 /* unsolicited event for HP jack sensing */
15626 static void alc662_eeepc_ep20_unsol_event(struct hda_codec *codec,
15627                                           unsigned int res)
15628 {
15629         if ((res >> 26) == ALC880_HP_EVENT)
15630                 alc662_eeepc_ep20_automute(codec);
15631 }
15632
15633 static void alc662_eeepc_ep20_inithook(struct hda_codec *codec)
15634 {
15635         alc662_eeepc_ep20_automute(codec);
15636 }
15637
15638 static void alc663_m51va_speaker_automute(struct hda_codec *codec)
15639 {
15640         unsigned int present;
15641         unsigned char bits;
15642
15643         present = snd_hda_codec_read(codec, 0x21, 0,
15644                         AC_VERB_GET_PIN_SENSE, 0)
15645                         & AC_PINSENSE_PRESENCE;
15646         bits = present ? HDA_AMP_MUTE : 0;
15647         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15648                                 AMP_IN_MUTE(0), bits);
15649         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15650                                 AMP_IN_MUTE(0), bits);
15651 }
15652
15653 static void alc663_21jd_two_speaker_automute(struct hda_codec *codec)
15654 {
15655         unsigned int present;
15656         unsigned char bits;
15657
15658         present = snd_hda_codec_read(codec, 0x21, 0,
15659                         AC_VERB_GET_PIN_SENSE, 0)
15660                         & AC_PINSENSE_PRESENCE;
15661         bits = present ? HDA_AMP_MUTE : 0;
15662         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15663                                 AMP_IN_MUTE(0), bits);
15664         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15665                                 AMP_IN_MUTE(0), bits);
15666         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
15667                                 AMP_IN_MUTE(0), bits);
15668         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
15669                                 AMP_IN_MUTE(0), bits);
15670 }
15671
15672 static void alc663_15jd_two_speaker_automute(struct hda_codec *codec)
15673 {
15674         unsigned int present;
15675         unsigned char bits;
15676
15677         present = snd_hda_codec_read(codec, 0x15, 0,
15678                         AC_VERB_GET_PIN_SENSE, 0)
15679                         & AC_PINSENSE_PRESENCE;
15680         bits = present ? HDA_AMP_MUTE : 0;
15681         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15682                                 AMP_IN_MUTE(0), bits);
15683         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15684                                 AMP_IN_MUTE(0), bits);
15685         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
15686                                 AMP_IN_MUTE(0), bits);
15687         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
15688                                 AMP_IN_MUTE(0), bits);
15689 }
15690
15691 static void alc662_f5z_speaker_automute(struct hda_codec *codec)
15692 {
15693         unsigned int present;
15694         unsigned char bits;
15695
15696         present = snd_hda_codec_read(codec, 0x1b, 0,
15697                         AC_VERB_GET_PIN_SENSE, 0)
15698                         & AC_PINSENSE_PRESENCE;
15699         bits = present ? 0 : PIN_OUT;
15700         snd_hda_codec_write(codec, 0x14, 0,
15701                          AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
15702 }
15703
15704 static void alc663_two_hp_m1_speaker_automute(struct hda_codec *codec)
15705 {
15706         unsigned int present1, present2;
15707
15708         present1 = snd_hda_codec_read(codec, 0x21, 0,
15709                         AC_VERB_GET_PIN_SENSE, 0)
15710                         & AC_PINSENSE_PRESENCE;
15711         present2 = snd_hda_codec_read(codec, 0x15, 0,
15712                         AC_VERB_GET_PIN_SENSE, 0)
15713                         & AC_PINSENSE_PRESENCE;
15714
15715         if (present1 || present2) {
15716                 snd_hda_codec_write_cache(codec, 0x14, 0,
15717                         AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
15718         } else {
15719                 snd_hda_codec_write_cache(codec, 0x14, 0,
15720                         AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
15721         }
15722 }
15723
15724 static void alc663_two_hp_m2_speaker_automute(struct hda_codec *codec)
15725 {
15726         unsigned int present1, present2;
15727
15728         present1 = snd_hda_codec_read(codec, 0x1b, 0,
15729                                 AC_VERB_GET_PIN_SENSE, 0)
15730                                 & AC_PINSENSE_PRESENCE;
15731         present2 = snd_hda_codec_read(codec, 0x15, 0,
15732                                 AC_VERB_GET_PIN_SENSE, 0)
15733                                 & AC_PINSENSE_PRESENCE;
15734
15735         if (present1 || present2) {
15736                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15737                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
15738                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15739                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
15740         } else {
15741                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15742                                 AMP_IN_MUTE(0), 0);
15743                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15744                                 AMP_IN_MUTE(0), 0);
15745         }
15746 }
15747
15748 static void alc663_m51va_mic_automute(struct hda_codec *codec)
15749 {
15750         unsigned int present;
15751
15752         present = snd_hda_codec_read(codec, 0x18, 0,
15753                         AC_VERB_GET_PIN_SENSE, 0)
15754                         & AC_PINSENSE_PRESENCE;
15755         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15756                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15757         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15758                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15759         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15760                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
15761         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15762                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
15763 }
15764
15765 static void alc663_m51va_unsol_event(struct hda_codec *codec,
15766                                            unsigned int res)
15767 {
15768         switch (res >> 26) {
15769         case ALC880_HP_EVENT:
15770                 alc663_m51va_speaker_automute(codec);
15771                 break;
15772         case ALC880_MIC_EVENT:
15773                 alc663_m51va_mic_automute(codec);
15774                 break;
15775         }
15776 }
15777
15778 static void alc663_m51va_inithook(struct hda_codec *codec)
15779 {
15780         alc663_m51va_speaker_automute(codec);
15781         alc663_m51va_mic_automute(codec);
15782 }
15783
15784 /* ***************** Mode1 ******************************/
15785 static void alc663_mode1_unsol_event(struct hda_codec *codec,
15786                                            unsigned int res)
15787 {
15788         switch (res >> 26) {
15789         case ALC880_HP_EVENT:
15790                 alc663_m51va_speaker_automute(codec);
15791                 break;
15792         case ALC880_MIC_EVENT:
15793                 alc662_eeepc_mic_automute(codec);
15794                 break;
15795         }
15796 }
15797
15798 static void alc663_mode1_inithook(struct hda_codec *codec)
15799 {
15800         alc663_m51va_speaker_automute(codec);
15801         alc662_eeepc_mic_automute(codec);
15802 }
15803 /* ***************** Mode2 ******************************/
15804 static void alc662_mode2_unsol_event(struct hda_codec *codec,
15805                                            unsigned int res)
15806 {
15807         switch (res >> 26) {
15808         case ALC880_HP_EVENT:
15809                 alc662_f5z_speaker_automute(codec);
15810                 break;
15811         case ALC880_MIC_EVENT:
15812                 alc662_eeepc_mic_automute(codec);
15813                 break;
15814         }
15815 }
15816
15817 static void alc662_mode2_inithook(struct hda_codec *codec)
15818 {
15819         alc662_f5z_speaker_automute(codec);
15820         alc662_eeepc_mic_automute(codec);
15821 }
15822 /* ***************** Mode3 ******************************/
15823 static void alc663_mode3_unsol_event(struct hda_codec *codec,
15824                                            unsigned int res)
15825 {
15826         switch (res >> 26) {
15827         case ALC880_HP_EVENT:
15828                 alc663_two_hp_m1_speaker_automute(codec);
15829                 break;
15830         case ALC880_MIC_EVENT:
15831                 alc662_eeepc_mic_automute(codec);
15832                 break;
15833         }
15834 }
15835
15836 static void alc663_mode3_inithook(struct hda_codec *codec)
15837 {
15838         alc663_two_hp_m1_speaker_automute(codec);
15839         alc662_eeepc_mic_automute(codec);
15840 }
15841 /* ***************** Mode4 ******************************/
15842 static void alc663_mode4_unsol_event(struct hda_codec *codec,
15843                                            unsigned int res)
15844 {
15845         switch (res >> 26) {
15846         case ALC880_HP_EVENT:
15847                 alc663_21jd_two_speaker_automute(codec);
15848                 break;
15849         case ALC880_MIC_EVENT:
15850                 alc662_eeepc_mic_automute(codec);
15851                 break;
15852         }
15853 }
15854
15855 static void alc663_mode4_inithook(struct hda_codec *codec)
15856 {
15857         alc663_21jd_two_speaker_automute(codec);
15858         alc662_eeepc_mic_automute(codec);
15859 }
15860 /* ***************** Mode5 ******************************/
15861 static void alc663_mode5_unsol_event(struct hda_codec *codec,
15862                                            unsigned int res)
15863 {
15864         switch (res >> 26) {
15865         case ALC880_HP_EVENT:
15866                 alc663_15jd_two_speaker_automute(codec);
15867                 break;
15868         case ALC880_MIC_EVENT:
15869                 alc662_eeepc_mic_automute(codec);
15870                 break;
15871         }
15872 }
15873
15874 static void alc663_mode5_inithook(struct hda_codec *codec)
15875 {
15876         alc663_15jd_two_speaker_automute(codec);
15877         alc662_eeepc_mic_automute(codec);
15878 }
15879 /* ***************** Mode6 ******************************/
15880 static void alc663_mode6_unsol_event(struct hda_codec *codec,
15881                                            unsigned int res)
15882 {
15883         switch (res >> 26) {
15884         case ALC880_HP_EVENT:
15885                 alc663_two_hp_m2_speaker_automute(codec);
15886                 break;
15887         case ALC880_MIC_EVENT:
15888                 alc662_eeepc_mic_automute(codec);
15889                 break;
15890         }
15891 }
15892
15893 static void alc663_mode6_inithook(struct hda_codec *codec)
15894 {
15895         alc663_two_hp_m2_speaker_automute(codec);
15896         alc662_eeepc_mic_automute(codec);
15897 }
15898
15899 static void alc663_g71v_hp_automute(struct hda_codec *codec)
15900 {
15901         unsigned int present;
15902         unsigned char bits;
15903
15904         present = snd_hda_codec_read(codec, 0x21, 0,
15905                                      AC_VERB_GET_PIN_SENSE, 0)
15906                 & AC_PINSENSE_PRESENCE;
15907         bits = present ? HDA_AMP_MUTE : 0;
15908         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15909                                  HDA_AMP_MUTE, bits);
15910         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15911                                  HDA_AMP_MUTE, bits);
15912 }
15913
15914 static void alc663_g71v_front_automute(struct hda_codec *codec)
15915 {
15916         unsigned int present;
15917         unsigned char bits;
15918
15919         present = snd_hda_codec_read(codec, 0x15, 0,
15920                                      AC_VERB_GET_PIN_SENSE, 0)
15921                 & AC_PINSENSE_PRESENCE;
15922         bits = present ? HDA_AMP_MUTE : 0;
15923         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15924                                  HDA_AMP_MUTE, bits);
15925 }
15926
15927 static void alc663_g71v_unsol_event(struct hda_codec *codec,
15928                                            unsigned int res)
15929 {
15930         switch (res >> 26) {
15931         case ALC880_HP_EVENT:
15932                 alc663_g71v_hp_automute(codec);
15933                 break;
15934         case ALC880_FRONT_EVENT:
15935                 alc663_g71v_front_automute(codec);
15936                 break;
15937         case ALC880_MIC_EVENT:
15938                 alc662_eeepc_mic_automute(codec);
15939                 break;
15940         }
15941 }
15942
15943 static void alc663_g71v_inithook(struct hda_codec *codec)
15944 {
15945         alc663_g71v_front_automute(codec);
15946         alc663_g71v_hp_automute(codec);
15947         alc662_eeepc_mic_automute(codec);
15948 }
15949
15950 static void alc663_g50v_unsol_event(struct hda_codec *codec,
15951                                            unsigned int res)
15952 {
15953         switch (res >> 26) {
15954         case ALC880_HP_EVENT:
15955                 alc663_m51va_speaker_automute(codec);
15956                 break;
15957         case ALC880_MIC_EVENT:
15958                 alc662_eeepc_mic_automute(codec);
15959                 break;
15960         }
15961 }
15962
15963 static void alc663_g50v_inithook(struct hda_codec *codec)
15964 {
15965         alc663_m51va_speaker_automute(codec);
15966         alc662_eeepc_mic_automute(codec);
15967 }
15968
15969 /* bind hp and internal speaker mute (with plug check) */
15970 static int alc662_ecs_master_sw_put(struct snd_kcontrol *kcontrol,
15971                                      struct snd_ctl_elem_value *ucontrol)
15972 {
15973         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
15974         long *valp = ucontrol->value.integer.value;
15975         int change;
15976
15977         change = snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0,
15978                                           HDA_AMP_MUTE,
15979                                           valp[0] ? 0 : HDA_AMP_MUTE);
15980         change |= snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0,
15981                                            HDA_AMP_MUTE,
15982                                            valp[1] ? 0 : HDA_AMP_MUTE);
15983         if (change)
15984                 alc262_hippo1_automute(codec);
15985         return change;
15986 }
15987
15988 static struct snd_kcontrol_new alc662_ecs_mixer[] = {
15989         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15990         {
15991                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
15992                 .name = "Master Playback Switch",
15993                 .info = snd_hda_mixer_amp_switch_info,
15994                 .get = snd_hda_mixer_amp_switch_get,
15995                 .put = alc662_ecs_master_sw_put,
15996                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
15997         },
15998
15999         HDA_CODEC_VOLUME("e-Mic/LineIn Boost", 0x18, 0, HDA_INPUT),
16000         HDA_CODEC_VOLUME("e-Mic/LineIn Playback Volume", 0x0b, 0x0, HDA_INPUT),
16001         HDA_CODEC_MUTE("e-Mic/LineIn Playback Switch", 0x0b, 0x0, HDA_INPUT),
16002
16003         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
16004         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16005         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16006         { } /* end */
16007 };
16008
16009 #ifdef CONFIG_SND_HDA_POWER_SAVE
16010 #define alc662_loopbacks        alc880_loopbacks
16011 #endif
16012
16013
16014 /* pcm configuration: identiacal with ALC880 */
16015 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
16016 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
16017 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
16018 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
16019
16020 /*
16021  * configuration and preset
16022  */
16023 static const char *alc662_models[ALC662_MODEL_LAST] = {
16024         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
16025         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
16026         [ALC662_3ST_6ch]        = "3stack-6ch",
16027         [ALC662_5ST_DIG]        = "6stack-dig",
16028         [ALC662_LENOVO_101E]    = "lenovo-101e",
16029         [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
16030         [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
16031         [ALC662_ECS] = "ecs",
16032         [ALC663_ASUS_M51VA] = "m51va",
16033         [ALC663_ASUS_G71V] = "g71v",
16034         [ALC663_ASUS_H13] = "h13",
16035         [ALC663_ASUS_G50V] = "g50v",
16036         [ALC663_ASUS_MODE1] = "asus-mode1",
16037         [ALC662_ASUS_MODE2] = "asus-mode2",
16038         [ALC663_ASUS_MODE3] = "asus-mode3",
16039         [ALC663_ASUS_MODE4] = "asus-mode4",
16040         [ALC663_ASUS_MODE5] = "asus-mode5",
16041         [ALC663_ASUS_MODE6] = "asus-mode6",
16042         [ALC662_AUTO]           = "auto",
16043 };
16044
16045 static struct snd_pci_quirk alc662_cfg_tbl[] = {
16046         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA),
16047         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS G50V", ALC663_ASUS_G50V),
16048         SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
16049         SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
16050         SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
16051         SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC663_ASUS_MODE1),
16052         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M50Vr", ALC663_ASUS_MODE1),
16053         SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC663_ASUS_MODE1),
16054         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC663_ASUS_MODE1),
16055         SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC663_ASUS_MODE1),
16056         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS NB", ALC663_ASUS_MODE1),
16057         SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC663_ASUS_MODE1),
16058         SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC663_ASUS_MODE1),
16059         SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC663_ASUS_MODE1),
16060         SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC663_ASUS_MODE1),
16061         SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_ASUS_MODE2),
16062         SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_ASUS_MODE2),
16063         SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_ASUS_MODE2),
16064         SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_ASUS_MODE2),
16065         SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_ASUS_MODE2),
16066         SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_ASUS_MODE2),
16067         SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_ASUS_MODE2),
16068         SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_ASUS_MODE2),
16069         SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_ASUS_MODE2),
16070         SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_ASUS_MODE2),
16071         SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_ASUS_MODE2),
16072         SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_ASUS_MODE2),
16073         SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC663_ASUS_MODE3),
16074         SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC663_ASUS_MODE3),
16075         SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC663_ASUS_MODE3),
16076         SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC663_ASUS_MODE3),
16077         SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC663_ASUS_MODE3),
16078         SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC663_ASUS_MODE4),
16079         SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC663_ASUS_MODE5),
16080         SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC663_ASUS_MODE6),
16081         SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC663_ASUS_MODE6),
16082         SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC663_ASUS_MODE6),
16083         SND_PCI_QUIRK(0x105b, 0x0d47, "Foxconn 45CMX/45GMX/45CMX-K",
16084                       ALC662_3ST_6ch_DIG),
16085         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
16086         SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_ECS),
16087         SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_ECS),
16088         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte 945GCM-S2L",
16089                       ALC662_3ST_6ch_DIG),
16090         SND_PCI_QUIRK(0x1565, 0x820f, "Biostar TA780G M2+", ALC662_3ST_6ch_DIG),
16091         SND_PCI_QUIRK(0x1849, 0x3662, "ASROCK K10N78FullHD-hSLI R3.0",
16092                                         ALC662_3ST_6ch_DIG),
16093         SND_PCI_QUIRK(0x1854, 0x2000, "ASUS H13-2000", ALC663_ASUS_H13),
16094         SND_PCI_QUIRK(0x1854, 0x2001, "ASUS H13-2001", ALC663_ASUS_H13),
16095         SND_PCI_QUIRK(0x1854, 0x2002, "ASUS H13-2002", ALC663_ASUS_H13),
16096         {}
16097 };
16098
16099 static struct alc_config_preset alc662_presets[] = {
16100         [ALC662_3ST_2ch_DIG] = {
16101                 .mixers = { alc662_3ST_2ch_mixer },
16102                 .init_verbs = { alc662_init_verbs },
16103                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16104                 .dac_nids = alc662_dac_nids,
16105                 .dig_out_nid = ALC662_DIGOUT_NID,
16106                 .dig_in_nid = ALC662_DIGIN_NID,
16107                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16108                 .channel_mode = alc662_3ST_2ch_modes,
16109                 .input_mux = &alc662_capture_source,
16110         },
16111         [ALC662_3ST_6ch_DIG] = {
16112                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16113                 .init_verbs = { alc662_init_verbs },
16114                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16115                 .dac_nids = alc662_dac_nids,
16116                 .dig_out_nid = ALC662_DIGOUT_NID,
16117                 .dig_in_nid = ALC662_DIGIN_NID,
16118                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16119                 .channel_mode = alc662_3ST_6ch_modes,
16120                 .need_dac_fix = 1,
16121                 .input_mux = &alc662_capture_source,
16122         },
16123         [ALC662_3ST_6ch] = {
16124                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16125                 .init_verbs = { alc662_init_verbs },
16126                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16127                 .dac_nids = alc662_dac_nids,
16128                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16129                 .channel_mode = alc662_3ST_6ch_modes,
16130                 .need_dac_fix = 1,
16131                 .input_mux = &alc662_capture_source,
16132         },
16133         [ALC662_5ST_DIG] = {
16134                 .mixers = { alc662_base_mixer, alc662_chmode_mixer },
16135                 .init_verbs = { alc662_init_verbs },
16136                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16137                 .dac_nids = alc662_dac_nids,
16138                 .dig_out_nid = ALC662_DIGOUT_NID,
16139                 .dig_in_nid = ALC662_DIGIN_NID,
16140                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
16141                 .channel_mode = alc662_5stack_modes,
16142                 .input_mux = &alc662_capture_source,
16143         },
16144         [ALC662_LENOVO_101E] = {
16145                 .mixers = { alc662_lenovo_101e_mixer },
16146                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
16147                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16148                 .dac_nids = alc662_dac_nids,
16149                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16150                 .channel_mode = alc662_3ST_2ch_modes,
16151                 .input_mux = &alc662_lenovo_101e_capture_source,
16152                 .unsol_event = alc662_lenovo_101e_unsol_event,
16153                 .init_hook = alc662_lenovo_101e_all_automute,
16154         },
16155         [ALC662_ASUS_EEEPC_P701] = {
16156                 .mixers = { alc662_eeepc_p701_mixer },
16157                 .init_verbs = { alc662_init_verbs,
16158                                 alc662_eeepc_sue_init_verbs },
16159                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16160                 .dac_nids = alc662_dac_nids,
16161                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16162                 .channel_mode = alc662_3ST_2ch_modes,
16163                 .input_mux = &alc662_eeepc_capture_source,
16164                 .unsol_event = alc662_eeepc_unsol_event,
16165                 .init_hook = alc662_eeepc_inithook,
16166         },
16167         [ALC662_ASUS_EEEPC_EP20] = {
16168                 .mixers = { alc662_eeepc_ep20_mixer,
16169                             alc662_chmode_mixer },
16170                 .init_verbs = { alc662_init_verbs,
16171                                 alc662_eeepc_ep20_sue_init_verbs },
16172                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16173                 .dac_nids = alc662_dac_nids,
16174                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16175                 .channel_mode = alc662_3ST_6ch_modes,
16176                 .input_mux = &alc662_lenovo_101e_capture_source,
16177                 .unsol_event = alc662_eeepc_ep20_unsol_event,
16178                 .init_hook = alc662_eeepc_ep20_inithook,
16179         },
16180         [ALC662_ECS] = {
16181                 .mixers = { alc662_ecs_mixer },
16182                 .init_verbs = { alc662_init_verbs,
16183                                 alc662_ecs_init_verbs },
16184                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16185                 .dac_nids = alc662_dac_nids,
16186                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16187                 .channel_mode = alc662_3ST_2ch_modes,
16188                 .input_mux = &alc662_eeepc_capture_source,
16189                 .unsol_event = alc662_eeepc_unsol_event,
16190                 .init_hook = alc662_eeepc_inithook,
16191         },
16192         [ALC663_ASUS_M51VA] = {
16193                 .mixers = { alc663_m51va_mixer },
16194                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
16195                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16196                 .dac_nids = alc662_dac_nids,
16197                 .dig_out_nid = ALC662_DIGOUT_NID,
16198                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16199                 .channel_mode = alc662_3ST_2ch_modes,
16200                 .input_mux = &alc663_m51va_capture_source,
16201                 .unsol_event = alc663_m51va_unsol_event,
16202                 .init_hook = alc663_m51va_inithook,
16203         },
16204         [ALC663_ASUS_G71V] = {
16205                 .mixers = { alc663_g71v_mixer },
16206                 .init_verbs = { alc662_init_verbs, alc663_g71v_init_verbs },
16207                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16208                 .dac_nids = alc662_dac_nids,
16209                 .dig_out_nid = ALC662_DIGOUT_NID,
16210                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16211                 .channel_mode = alc662_3ST_2ch_modes,
16212                 .input_mux = &alc662_eeepc_capture_source,
16213                 .unsol_event = alc663_g71v_unsol_event,
16214                 .init_hook = alc663_g71v_inithook,
16215         },
16216         [ALC663_ASUS_H13] = {
16217                 .mixers = { alc663_m51va_mixer },
16218                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
16219                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16220                 .dac_nids = alc662_dac_nids,
16221                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16222                 .channel_mode = alc662_3ST_2ch_modes,
16223                 .input_mux = &alc663_m51va_capture_source,
16224                 .unsol_event = alc663_m51va_unsol_event,
16225                 .init_hook = alc663_m51va_inithook,
16226         },
16227         [ALC663_ASUS_G50V] = {
16228                 .mixers = { alc663_g50v_mixer },
16229                 .init_verbs = { alc662_init_verbs, alc663_g50v_init_verbs },
16230                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16231                 .dac_nids = alc662_dac_nids,
16232                 .dig_out_nid = ALC662_DIGOUT_NID,
16233                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16234                 .channel_mode = alc662_3ST_6ch_modes,
16235                 .input_mux = &alc663_capture_source,
16236                 .unsol_event = alc663_g50v_unsol_event,
16237                 .init_hook = alc663_g50v_inithook,
16238         },
16239         [ALC663_ASUS_MODE1] = {
16240                 .mixers = { alc663_m51va_mixer },
16241                 .cap_mixer = alc662_auto_capture_mixer,
16242                 .init_verbs = { alc662_init_verbs,
16243                                 alc663_21jd_amic_init_verbs },
16244                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16245                 .hp_nid = 0x03,
16246                 .dac_nids = alc662_dac_nids,
16247                 .dig_out_nid = ALC662_DIGOUT_NID,
16248                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16249                 .channel_mode = alc662_3ST_2ch_modes,
16250                 .input_mux = &alc662_eeepc_capture_source,
16251                 .unsol_event = alc663_mode1_unsol_event,
16252                 .init_hook = alc663_mode1_inithook,
16253         },
16254         [ALC662_ASUS_MODE2] = {
16255                 .mixers = { alc662_1bjd_mixer },
16256                 .cap_mixer = alc662_auto_capture_mixer,
16257                 .init_verbs = { alc662_init_verbs,
16258                                 alc662_1bjd_amic_init_verbs },
16259                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16260                 .dac_nids = alc662_dac_nids,
16261                 .dig_out_nid = ALC662_DIGOUT_NID,
16262                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16263                 .channel_mode = alc662_3ST_2ch_modes,
16264                 .input_mux = &alc662_eeepc_capture_source,
16265                 .unsol_event = alc662_mode2_unsol_event,
16266                 .init_hook = alc662_mode2_inithook,
16267         },
16268         [ALC663_ASUS_MODE3] = {
16269                 .mixers = { alc663_two_hp_m1_mixer },
16270                 .cap_mixer = alc662_auto_capture_mixer,
16271                 .init_verbs = { alc662_init_verbs,
16272                                 alc663_two_hp_amic_m1_init_verbs },
16273                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16274                 .hp_nid = 0x03,
16275                 .dac_nids = alc662_dac_nids,
16276                 .dig_out_nid = ALC662_DIGOUT_NID,
16277                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16278                 .channel_mode = alc662_3ST_2ch_modes,
16279                 .input_mux = &alc662_eeepc_capture_source,
16280                 .unsol_event = alc663_mode3_unsol_event,
16281                 .init_hook = alc663_mode3_inithook,
16282         },
16283         [ALC663_ASUS_MODE4] = {
16284                 .mixers = { alc663_asus_21jd_clfe_mixer },
16285                 .cap_mixer = alc662_auto_capture_mixer,
16286                 .init_verbs = { alc662_init_verbs,
16287                                 alc663_21jd_amic_init_verbs},
16288                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16289                 .hp_nid = 0x03,
16290                 .dac_nids = alc662_dac_nids,
16291                 .dig_out_nid = ALC662_DIGOUT_NID,
16292                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16293                 .channel_mode = alc662_3ST_2ch_modes,
16294                 .input_mux = &alc662_eeepc_capture_source,
16295                 .unsol_event = alc663_mode4_unsol_event,
16296                 .init_hook = alc663_mode4_inithook,
16297         },
16298         [ALC663_ASUS_MODE5] = {
16299                 .mixers = { alc663_asus_15jd_clfe_mixer },
16300                 .cap_mixer = alc662_auto_capture_mixer,
16301                 .init_verbs = { alc662_init_verbs,
16302                                 alc663_15jd_amic_init_verbs },
16303                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16304                 .hp_nid = 0x03,
16305                 .dac_nids = alc662_dac_nids,
16306                 .dig_out_nid = ALC662_DIGOUT_NID,
16307                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16308                 .channel_mode = alc662_3ST_2ch_modes,
16309                 .input_mux = &alc662_eeepc_capture_source,
16310                 .unsol_event = alc663_mode5_unsol_event,
16311                 .init_hook = alc663_mode5_inithook,
16312         },
16313         [ALC663_ASUS_MODE6] = {
16314                 .mixers = { alc663_two_hp_m2_mixer },
16315                 .cap_mixer = alc662_auto_capture_mixer,
16316                 .init_verbs = { alc662_init_verbs,
16317                                 alc663_two_hp_amic_m2_init_verbs },
16318                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16319                 .hp_nid = 0x03,
16320                 .dac_nids = alc662_dac_nids,
16321                 .dig_out_nid = ALC662_DIGOUT_NID,
16322                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16323                 .channel_mode = alc662_3ST_2ch_modes,
16324                 .input_mux = &alc662_eeepc_capture_source,
16325                 .unsol_event = alc663_mode6_unsol_event,
16326                 .init_hook = alc663_mode6_inithook,
16327         },
16328 };
16329
16330
16331 /*
16332  * BIOS auto configuration
16333  */
16334
16335 /* add playback controls from the parsed DAC table */
16336 static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec,
16337                                              const struct auto_pin_cfg *cfg)
16338 {
16339         char name[32];
16340         static const char *chname[4] = {
16341                 "Front", "Surround", NULL /*CLFE*/, "Side"
16342         };
16343         hda_nid_t nid;
16344         int i, err;
16345
16346         for (i = 0; i < cfg->line_outs; i++) {
16347                 if (!spec->multiout.dac_nids[i])
16348                         continue;
16349                 nid = alc880_idx_to_dac(i);
16350                 if (i == 2) {
16351                         /* Center/LFE */
16352                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
16353                                           "Center Playback Volume",
16354                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
16355                                                               HDA_OUTPUT));
16356                         if (err < 0)
16357                                 return err;
16358                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
16359                                           "LFE Playback Volume",
16360                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
16361                                                               HDA_OUTPUT));
16362                         if (err < 0)
16363                                 return err;
16364                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
16365                                           "Center Playback Switch",
16366                                           HDA_COMPOSE_AMP_VAL(0x0e, 1, 0,
16367                                                               HDA_INPUT));
16368                         if (err < 0)
16369                                 return err;
16370                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
16371                                           "LFE Playback Switch",
16372                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
16373                                                               HDA_INPUT));
16374                         if (err < 0)
16375                                 return err;
16376                 } else {
16377                         sprintf(name, "%s Playback Volume", chname[i]);
16378                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
16379                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
16380                                                               HDA_OUTPUT));
16381                         if (err < 0)
16382                                 return err;
16383                         sprintf(name, "%s Playback Switch", chname[i]);
16384                         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16385                                 HDA_COMPOSE_AMP_VAL(alc880_idx_to_mixer(i),
16386                                                     3, 0, HDA_INPUT));
16387                         if (err < 0)
16388                                 return err;
16389                 }
16390         }
16391         return 0;
16392 }
16393
16394 /* add playback controls for speaker and HP outputs */
16395 static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
16396                                         const char *pfx)
16397 {
16398         hda_nid_t nid;
16399         int err;
16400         char name[32];
16401
16402         if (!pin)
16403                 return 0;
16404
16405         if (pin == 0x17) {
16406                 /* ALC663 has a mono output pin on 0x17 */
16407                 sprintf(name, "%s Playback Switch", pfx);
16408                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16409                                   HDA_COMPOSE_AMP_VAL(pin, 2, 0, HDA_OUTPUT));
16410                 return err;
16411         }
16412
16413         if (alc880_is_fixed_pin(pin)) {
16414                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
16415                 /* printk("DAC nid=%x\n",nid); */
16416                 /* specify the DAC as the extra output */
16417                 if (!spec->multiout.hp_nid)
16418                         spec->multiout.hp_nid = nid;
16419                 else
16420                         spec->multiout.extra_out_nid[0] = nid;
16421                 /* control HP volume/switch on the output mixer amp */
16422                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
16423                 sprintf(name, "%s Playback Volume", pfx);
16424                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
16425                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
16426                 if (err < 0)
16427                         return err;
16428                 sprintf(name, "%s Playback Switch", pfx);
16429                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
16430                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
16431                 if (err < 0)
16432                         return err;
16433         } else if (alc880_is_multi_pin(pin)) {
16434                 /* set manual connection */
16435                 /* we have only a switch on HP-out PIN */
16436                 sprintf(name, "%s Playback Switch", pfx);
16437                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16438                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
16439                 if (err < 0)
16440                         return err;
16441         }
16442         return 0;
16443 }
16444
16445 /* create playback/capture controls for input pins */
16446 static int alc662_auto_create_analog_input_ctls(struct alc_spec *spec,
16447                                                 const struct auto_pin_cfg *cfg)
16448 {
16449         struct hda_input_mux *imux = &spec->private_imux[0];
16450         int i, err, idx;
16451
16452         for (i = 0; i < AUTO_PIN_LAST; i++) {
16453                 if (alc880_is_input_pin(cfg->input_pins[i])) {
16454                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
16455                         err = new_analog_input(spec, cfg->input_pins[i],
16456                                                auto_pin_cfg_labels[i],
16457                                                idx, 0x0b);
16458                         if (err < 0)
16459                                 return err;
16460                         imux->items[imux->num_items].label =
16461                                 auto_pin_cfg_labels[i];
16462                         imux->items[imux->num_items].index =
16463                                 alc880_input_pin_idx(cfg->input_pins[i]);
16464                         imux->num_items++;
16465                 }
16466         }
16467         return 0;
16468 }
16469
16470 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
16471                                               hda_nid_t nid, int pin_type,
16472                                               int dac_idx)
16473 {
16474         alc_set_pin_output(codec, nid, pin_type);
16475         /* need the manual connection? */
16476         if (alc880_is_multi_pin(nid)) {
16477                 struct alc_spec *spec = codec->spec;
16478                 int idx = alc880_multi_pin_idx(nid);
16479                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
16480                                     AC_VERB_SET_CONNECT_SEL,
16481                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
16482         }
16483 }
16484
16485 static void alc662_auto_init_multi_out(struct hda_codec *codec)
16486 {
16487         struct alc_spec *spec = codec->spec;
16488         int i;
16489
16490         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
16491         for (i = 0; i <= HDA_SIDE; i++) {
16492                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
16493                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
16494                 if (nid)
16495                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
16496                                                           i);
16497         }
16498 }
16499
16500 static void alc662_auto_init_hp_out(struct hda_codec *codec)
16501 {
16502         struct alc_spec *spec = codec->spec;
16503         hda_nid_t pin;
16504
16505         pin = spec->autocfg.hp_pins[0];
16506         if (pin) /* connect to front */
16507                 /* use dac 0 */
16508                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
16509         pin = spec->autocfg.speaker_pins[0];
16510         if (pin)
16511                 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
16512 }
16513
16514 #define alc662_is_input_pin(nid)        alc880_is_input_pin(nid)
16515 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
16516
16517 static void alc662_auto_init_analog_input(struct hda_codec *codec)
16518 {
16519         struct alc_spec *spec = codec->spec;
16520         int i;
16521
16522         for (i = 0; i < AUTO_PIN_LAST; i++) {
16523                 hda_nid_t nid = spec->autocfg.input_pins[i];
16524                 if (alc662_is_input_pin(nid)) {
16525                         snd_hda_codec_write(codec, nid, 0,
16526                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
16527                                             (i <= AUTO_PIN_FRONT_MIC ?
16528                                              PIN_VREF80 : PIN_IN));
16529                         if (nid != ALC662_PIN_CD_NID)
16530                                 snd_hda_codec_write(codec, nid, 0,
16531                                                     AC_VERB_SET_AMP_GAIN_MUTE,
16532                                                     AMP_OUT_MUTE);
16533                 }
16534         }
16535 }
16536
16537 #define alc662_auto_init_input_src      alc882_auto_init_input_src
16538
16539 static int alc662_parse_auto_config(struct hda_codec *codec)
16540 {
16541         struct alc_spec *spec = codec->spec;
16542         int err;
16543         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
16544
16545         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
16546                                            alc662_ignore);
16547         if (err < 0)
16548                 return err;
16549         if (!spec->autocfg.line_outs)
16550                 return 0; /* can't find valid BIOS pin config */
16551
16552         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
16553         if (err < 0)
16554                 return err;
16555         err = alc662_auto_create_multi_out_ctls(spec, &spec->autocfg);
16556         if (err < 0)
16557                 return err;
16558         err = alc662_auto_create_extra_out(spec,
16559                                            spec->autocfg.speaker_pins[0],
16560                                            "Speaker");
16561         if (err < 0)
16562                 return err;
16563         err = alc662_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
16564                                            "Headphone");
16565         if (err < 0)
16566                 return err;
16567         err = alc662_auto_create_analog_input_ctls(spec, &spec->autocfg);
16568         if (err < 0)
16569                 return err;
16570
16571         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
16572
16573         if (spec->autocfg.dig_out_pin)
16574                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
16575
16576         if (spec->kctls.list)
16577                 add_mixer(spec, spec->kctls.list);
16578
16579         spec->num_mux_defs = 1;
16580         spec->input_mux = &spec->private_imux[0];
16581
16582         add_verb(spec, alc662_auto_init_verbs);
16583         if (codec->vendor_id == 0x10ec0663)
16584                 add_verb(spec, alc663_auto_init_verbs);
16585
16586         err = alc_auto_add_mic_boost(codec);
16587         if (err < 0)
16588                 return err;
16589
16590         store_pin_configs(codec);
16591         return 1;
16592 }
16593
16594 /* additional initialization for auto-configuration model */
16595 static void alc662_auto_init(struct hda_codec *codec)
16596 {
16597         struct alc_spec *spec = codec->spec;
16598         alc662_auto_init_multi_out(codec);
16599         alc662_auto_init_hp_out(codec);
16600         alc662_auto_init_analog_input(codec);
16601         alc662_auto_init_input_src(codec);
16602         if (spec->unsol_event)
16603                 alc_inithook(codec);
16604 }
16605
16606 static int patch_alc662(struct hda_codec *codec)
16607 {
16608         struct alc_spec *spec;
16609         int err, board_config;
16610
16611         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
16612         if (!spec)
16613                 return -ENOMEM;
16614
16615         codec->spec = spec;
16616
16617         alc_fix_pll_init(codec, 0x20, 0x04, 15);
16618
16619         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
16620                                                   alc662_models,
16621                                                   alc662_cfg_tbl);
16622         if (board_config < 0) {
16623                 printk(KERN_INFO "hda_codec: Unknown model for ALC662, "
16624                        "trying auto-probe from BIOS...\n");
16625                 board_config = ALC662_AUTO;
16626         }
16627
16628         if (board_config == ALC662_AUTO) {
16629                 /* automatic parse from the BIOS config */
16630                 err = alc662_parse_auto_config(codec);
16631                 if (err < 0) {
16632                         alc_free(codec);
16633                         return err;
16634                 } else if (!err) {
16635                         printk(KERN_INFO
16636                                "hda_codec: Cannot set up configuration "
16637                                "from BIOS.  Using base mode...\n");
16638                         board_config = ALC662_3ST_2ch_DIG;
16639                 }
16640         }
16641
16642         if (board_config != ALC662_AUTO)
16643                 setup_preset(spec, &alc662_presets[board_config]);
16644
16645         if (codec->vendor_id == 0x10ec0663) {
16646                 spec->stream_name_analog = "ALC663 Analog";
16647                 spec->stream_name_digital = "ALC663 Digital";
16648         } else if (codec->vendor_id == 0x10ec0272) {
16649                 spec->stream_name_analog = "ALC272 Analog";
16650                 spec->stream_name_digital = "ALC272 Digital";
16651         } else {
16652                 spec->stream_name_analog = "ALC662 Analog";
16653                 spec->stream_name_digital = "ALC662 Digital";
16654         }
16655
16656         spec->stream_analog_playback = &alc662_pcm_analog_playback;
16657         spec->stream_analog_capture = &alc662_pcm_analog_capture;
16658
16659         spec->stream_digital_playback = &alc662_pcm_digital_playback;
16660         spec->stream_digital_capture = &alc662_pcm_digital_capture;
16661
16662         spec->adc_nids = alc662_adc_nids;
16663         spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
16664         spec->capsrc_nids = alc662_capsrc_nids;
16665         spec->capture_style = CAPT_MIX;
16666
16667         if (!spec->cap_mixer)
16668                 set_capture_mixer(spec);
16669
16670         spec->vmaster_nid = 0x02;
16671
16672         codec->patch_ops = alc_patch_ops;
16673         if (board_config == ALC662_AUTO)
16674                 spec->init_hook = alc662_auto_init;
16675 #ifdef CONFIG_SND_HDA_POWER_SAVE
16676         if (!spec->loopback.amplist)
16677                 spec->loopback.amplist = alc662_loopbacks;
16678 #endif
16679         codec->proc_widget_hook = print_realtek_coef;
16680
16681         return 0;
16682 }
16683
16684 /*
16685  * patch entries
16686  */
16687 static struct hda_codec_preset snd_hda_preset_realtek[] = {
16688         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
16689         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
16690         { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
16691         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
16692         { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
16693         { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
16694         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
16695           .patch = patch_alc861 },
16696         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
16697         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
16698         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
16699         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
16700           .patch = patch_alc883 },
16701         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
16702           .patch = patch_alc662 },
16703         { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
16704         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
16705         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
16706         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
16707         { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
16708           .patch = patch_alc882 }, /* should be patch_alc883() in future */
16709         { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
16710           .patch = patch_alc882 }, /* should be patch_alc883() in future */
16711         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
16712         { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc883 },
16713         { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
16714           .patch = patch_alc883 },
16715         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
16716         { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 },
16717         {} /* terminator */
16718 };
16719
16720 MODULE_ALIAS("snd-hda-codec-id:10ec*");
16721
16722 MODULE_LICENSE("GPL");
16723 MODULE_DESCRIPTION("Realtek HD-audio codec");
16724
16725 static struct hda_codec_preset_list realtek_list = {
16726         .preset = snd_hda_preset_realtek,
16727         .owner = THIS_MODULE,
16728 };
16729
16730 static int __init patch_realtek_init(void)
16731 {
16732         return snd_hda_add_codec_preset(&realtek_list);
16733 }
16734
16735 static void __exit patch_realtek_exit(void)
16736 {
16737         snd_hda_delete_codec_preset(&realtek_list);
16738 }
16739
16740 module_init(patch_realtek_init)
16741 module_exit(patch_realtek_exit)